Skip to content

Conversation

nikunjrCybage
Copy link
Contributor

@nikunjrCybage nikunjrCybage commented Jul 30, 2025

This PR adds support for specifying a quantity when purchasing consumable products using StoreKit 2 in the in_app_purchase_storekit package.

✅ What’s changing

  • Introduces logic to read the quantity field from PurchaseParam and insert it into the native StoreKit 2 .purchase(options:) call.
  • Ensures this logic is only applied to consumable products.
  • Adds null checks and default behavior to maintain compatibility with purchases that don’t specify quantity.

🧪 Testing

  • Added unit tests to verify quantity handling in Sk2PurchaseParam:
    • ✅ Verifies that a custom quantity is passed correctly to native purchase options.
    • ✅ Ensures that quantity defaults to 1 when not explicitly provided.
  • Tests cover buyConsumable flows using fakeStoreKit2Platform.
  • Verified on a real device using StoreKit 2 with different quantity values.
  • Ensures no change to StoreKit 1 flow or other product types.

📌 Fixes

Fix #171570

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

Copy link

google-cla bot commented Jul 30, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This PR adds support for specifying a quantity when purchasing consumable products with StoreKit 2. The implementation is straightforward, but it's missing crucial validation to ensure the quantity is only used for consumable products and that its value is positive, as required by Apple's StoreKit framework. I've suggested adding guards to handle these cases.

@nikunjrCybage nikunjrCybage force-pushed the enhancement/storekit-consumable-quantity branch from 922f30a to 338f91e Compare July 30, 2025 07:21
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! The patch itself LGTM, but you may have to:

  1. update the PR description a bit so when it gets merged it also closes the associated issue (basically you want to replace the markdown link with the issue url after the "fix" keyword)
  2. The version of the plugin needs to be bumped and you'll need to add a simple description of this change to the CHANGELOG file.

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Bradley-McCallion
Copy link

Looks good to me too! @LouiseHsu is there anything else needed to get this in?

@LongCatIsLooong
Copy link
Contributor

@nikunjrCybage
Copy link
Contributor Author

@LongCatIsLooong Thanks for pointing that out! I've fixed the formatting issue—CI should pass now. ✅

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still LGTM.

Copy link
Contributor

@LouiseHsu LouiseHsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM also!

@LouiseHsu LouiseHsu added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 11, 2025
@auto-submit auto-submit bot merged commit 08a9b2c into flutter:main Aug 11, 2025
80 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 12, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Aug 12, 2025
flutter/packages@a114ac2...08a9b2c

2025-08-11 [email protected] [in_app_purchase_storekit] Add support for
quantity in consumable product purchases (#171570)
(flutter/packages#9698)
2025-08-11 [email protected] [pigeon]
Improves documentation of `ProxyApi` and moves helper functions to a
separate file (flutter/packages#9756)
2025-08-11 [email protected] Roll Flutter from
1590543 to e2a347b (1 revision) (flutter/packages#9784)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
CaoGiaHieu-dev added a commit to CaoGiaHieu-dev/packages that referenced this pull request Aug 14, 2025
* main: (56 commits)
  [go_router_builder] Support extension types (flutter#9458)
  Roll Flutter from e2a347b14a18 to 34c2a3b158b2 (41 revisions) (flutter#9803)
  [go_router_builder] Migrate to Element2 API and update dependencies (flutter#9649)
  [in_app_purchase_storekit] Add support for quantity in consumable product purchases (#171570) (flutter#9698)
  [pigeon] Improves documentation of `ProxyApi` and moves helper functions to a separate file (flutter#9756)
  Roll Flutter from 1590543f6794 to e2a347b14a18 (1 revision) (flutter#9784)
  [camera_avfoundation] Implementation swift migration - part 11 (flutter#9690)
  [camera_avfoundation] Fix crash when streaming while recording (flutter#9691)
  Roll Flutter from 38217906e95c to 1590543f6794 (14 revisions) (flutter#9780)
  Roll Flutter from 92a6bfbfd6ef to 38217906e95c (17 revisions) (flutter#9778)
  [video_player] Improve KVO handling on iOS (flutter#9718)
  [dependabot]: Bump the test-dependencies group across 15 directories with 7 updates (flutter#9736)
  Roll Flutter from 9de63a03428f to 92a6bfbfd6ef (11 revisions) (flutter#9769)
  [google_maps_flutter_platform_interface] Add Advanced markers support (flutter#9737)
  [camera_android_camerax] Re-land "Force new Surface for each SurfaceRequest" (flutter#9760)
  [google_maps_flutter] Add ability to perform Google Maps SDK warmup (flutter#9674)
  Roll Flutter from 59fc766c6fdf to 9de63a03428f (6 revisions) (flutter#9764)
  [webview_flutter_wkwebview] Extended Web View API on iOS to add flexibility when working with local HTML content (flutter#8787)
  [local_auth] Differentiate iOS authentication errors (flutter#9705)
  manual roll to 59fc766c6fdfd03d0983fc95ce8b76793a300dd5 (flutter#9758)
  ...

# Conflicts:
#	packages/go_router_builder/lib/src/type_helpers.dart
#	packages/go_router_builder/pubspec.yaml
SydneyBao pushed a commit to SydneyBao/flutter that referenced this pull request Aug 14, 2025
…r#173625)

flutter/packages@a114ac2...08a9b2c

2025-08-11 [email protected] [in_app_purchase_storekit] Add support for
quantity in consumable product purchases (flutter#171570)
(flutter/packages#9698)
2025-08-11 [email protected] [pigeon]
Improves documentation of `ProxyApi` and moves helper functions to a
separate file (flutter/packages#9756)
2025-08-11 [email protected] Roll Flutter from
1590543 to e2a347b (1 revision) (flutter/packages#9784)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
ksokolovskyi pushed a commit to ksokolovskyi/flutter that referenced this pull request Aug 19, 2025
…r#173625)

flutter/packages@a114ac2...08a9b2c

2025-08-11 [email protected] [in_app_purchase_storekit] Add support for
quantity in consumable product purchases (flutter#171570)
(flutter/packages#9698)
2025-08-11 [email protected] [pigeon]
Improves documentation of `ProxyApi` and moves helper functions to a
separate file (flutter/packages#9756)
2025-08-11 [email protected] Roll Flutter from
1590543 to e2a347b (1 revision) (flutter/packages#9784)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
mboetger pushed a commit to mboetger/flutter that referenced this pull request Sep 18, 2025
…r#173625)

flutter/packages@a114ac2...08a9b2c

2025-08-11 [email protected] [in_app_purchase_storekit] Add support for
quantity in consumable product purchases (flutter#171570)
(flutter/packages#9698)
2025-08-11 [email protected] [pigeon]
Improves documentation of `ProxyApi` and moves helper functions to a
separate file (flutter/packages#9756)
2025-08-11 [email protected] Roll Flutter from
1590543 to e2a347b (1 revision) (flutter/packages#9784)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
korca0220 pushed a commit to korca0220/flutter that referenced this pull request Sep 22, 2025
…r#173625)

flutter/packages@a114ac2...08a9b2c

2025-08-11 [email protected] [in_app_purchase_storekit] Add support for
quantity in consumable product purchases (flutter#171570)
(flutter/packages#9698)
2025-08-11 [email protected] [pigeon]
Improves documentation of `ProxyApi` and moves helper functions to a
separate file (flutter/packages#9756)
2025-08-11 [email protected] Roll Flutter from
1590543 to e2a347b (1 revision) (flutter/packages#9784)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: in_app_purchase platform-ios platform-macos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[in_app_purchase] In StoreKit2, the quantity of SK2ProductPurchaseOptionsMessage does not work.

4 participants