-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Added ability to purchase multiple quantity of one product #5711
Changes from 2 commits
a53e1fd
03b6758
43cae14
d4b97de
8164f9c
d1d3816
2768b6a
4dba240
402ecee
e30795a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ class AppStorePurchaseParam extends PurchaseParam { | |
| AppStorePurchaseParam({ | ||
| required ProductDetails productDetails, | ||
| String? applicationUserName, | ||
| this.quantity = 1, | ||
| this.simulatesAskToBuyInSandbox = false, | ||
| }) : super( | ||
| productDetails: productDetails, | ||
|
|
@@ -28,4 +29,7 @@ class AppStorePurchaseParam extends PurchaseParam { | |
| /// | ||
| /// See also [SKPaymentWrapper.simulatesAskToBuyInSandbox]. | ||
| final bool simulatesAskToBuyInSandbox; | ||
|
|
||
| /// Quantity of the product user requested to buy | ||
stuartmorgan-g marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| int quantity; | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -427,6 +427,64 @@ void main() { | |
| final PurchaseStatus purchaseStatus = await completer.future; | ||
| expect(purchaseStatus, PurchaseStatus.canceled); | ||
| }); | ||
|
|
||
| test('buying non consumable, should be able to purchase multiple quantity of one product', () async { | ||
| final List<PurchaseDetails> details = <PurchaseDetails>[]; | ||
| final Completer<List<PurchaseDetails>> completer = | ||
| Completer<List<PurchaseDetails>>(); | ||
| final Stream<List<PurchaseDetails>> stream = | ||
| iapStoreKitPlatform.purchaseStream; | ||
| late StreamSubscription<List<PurchaseDetails>> subscription; | ||
| subscription = stream.listen((List<PurchaseDetails> purchaseDetailsList) { | ||
| details.addAll(purchaseDetailsList); | ||
| for (final PurchaseDetails purchaseDetails in purchaseDetailsList) { | ||
| if (purchaseDetails.pendingCompletePurchase) { | ||
| iapStoreKitPlatform.completePurchase(purchaseDetails); | ||
| completer.complete(details); | ||
| subscription.cancel(); | ||
| } | ||
| } | ||
| }); | ||
| final AppStorePurchaseParam purchaseParam = AppStorePurchaseParam( | ||
| productDetails: | ||
| AppStoreProductDetails.fromSKProduct(dummyProductWrapper), | ||
|
||
| quantity: 5, | ||
| applicationUserName: 'appName'); | ||
| await iapStoreKitPlatform.buyNonConsumable( | ||
| purchaseParam: purchaseParam | ||
| ); | ||
| await completer.future; | ||
| expect(fakeStoreKitPlatform.finishedTransactions.first.payment.quantity, 5); | ||
| }); | ||
|
|
||
| test('buying consumable, should be able to purchase multiple quantity of one product', () async { | ||
| final List<PurchaseDetails> details = <PurchaseDetails>[]; | ||
| final Completer<List<PurchaseDetails>> completer = | ||
| Completer<List<PurchaseDetails>>(); | ||
| final Stream<List<PurchaseDetails>> stream = | ||
| iapStoreKitPlatform.purchaseStream; | ||
| late StreamSubscription<List<PurchaseDetails>> subscription; | ||
| subscription = stream.listen((List<PurchaseDetails> purchaseDetailsList) { | ||
| details.addAll(purchaseDetailsList); | ||
| for (final PurchaseDetails purchaseDetails in purchaseDetailsList) { | ||
| if (purchaseDetails.pendingCompletePurchase) { | ||
| iapStoreKitPlatform.completePurchase(purchaseDetails); | ||
| completer.complete(details); | ||
| subscription.cancel(); | ||
| } | ||
| } | ||
| }); | ||
| final AppStorePurchaseParam purchaseParam = AppStorePurchaseParam( | ||
| productDetails: | ||
| AppStoreProductDetails.fromSKProduct(dummyProductWrapper), | ||
| quantity: 5, | ||
| applicationUserName: 'appName'); | ||
| await iapStoreKitPlatform.buyConsumable( | ||
| purchaseParam: purchaseParam | ||
| ); | ||
| await completer.future; | ||
| expect(fakeStoreKitPlatform.finishedTransactions.first.payment.quantity, 5); | ||
| }); | ||
| }); | ||
|
|
||
| group('complete purchase', () { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to change the function signature of the parent class too?
And it looks like quantity should be part of PurchaseParam as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comment. According to your suggestions I will move the quantity param to PurchaseParam and change the function signature of the parent class. Then I will create issue describing the feature.