Skip to content

[in_app_purchase_storekit] Add support for quantity in consumable product purchases (#171570) #9698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nikunjrCybage
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
2 participants