Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Prev Previous commit
Next Next commit
Moved the quantity param the AppStorePurchaseParam
  • Loading branch information
vlad0209 committed May 16, 2022
commit 03b6758bef827fd9903fa27b088b05c4b76cfc96
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class InAppPurchaseStoreKitPlatform extends InAppPurchasePlatform {
Future<bool> isAvailable() => SKPaymentQueueWrapper.canMakePayments();

@override
Future<bool> buyNonConsumable({required PurchaseParam purchaseParam, int quantity = 1}) async {
Future<bool> buyNonConsumable({required PurchaseParam purchaseParam}) async {
await _skPaymentQueueWrapper.addPayment(SKPaymentWrapper(
productIdentifier: purchaseParam.productDetails.id,
quantity: quantity,
quantity: purchaseParam is AppStorePurchaseParam ? purchaseParam.quantity : 1,
applicationUsername: purchaseParam.applicationUserName,
simulatesAskToBuyInSandbox: purchaseParam is AppStorePurchaseParam &&
purchaseParam.simulatesAskToBuyInSandbox,
Expand All @@ -82,9 +82,9 @@ class InAppPurchaseStoreKitPlatform extends InAppPurchasePlatform {

@override
Future<bool> buyConsumable(
{required PurchaseParam purchaseParam, bool autoConsume = true, int quantity = 1}) {
{required PurchaseParam purchaseParam, bool autoConsume = true}) {
assert(autoConsume == true, 'On iOS, we should always auto consume');
return buyNonConsumable(purchaseParam: purchaseParam, quantity: quantity);
return buyNonConsumable(purchaseParam: purchaseParam);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AppStorePurchaseParam extends PurchaseParam {
AppStorePurchaseParam({
required ProductDetails productDetails,
String? applicationUserName,
this.quantity = 1,
this.simulatesAskToBuyInSandbox = false,
}) : super(
productDetails: productDetails,
Expand All @@ -28,4 +29,7 @@ class AppStorePurchaseParam extends PurchaseParam {
///
/// See also [SKPaymentWrapper.simulatesAskToBuyInSandbox].
final bool simulatesAskToBuyInSandbox;

/// Quantity of the product user requested to buy
int quantity;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be final (unless there's a compelling reason it shouldn't be that I'm missing context for).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I've made the quantity param final in my last commit.

}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class FakeStoreKitPlatform {
return Future<void>.sync(() {});
case '-[InAppPurchasePlugin addPayment:result:]':
final String id = call.arguments['productIdentifier'] as String;
int quantity = call.arguments['quantity'] as int;
final int quantity = call.arguments['quantity'] as int;
final SKPaymentTransactionWrapper transaction =
createPendingTransaction(id, quantity: quantity);
transactions.add(transaction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,10 @@ void main() {
final AppStorePurchaseParam purchaseParam = AppStorePurchaseParam(
productDetails:
AppStoreProductDetails.fromSKProduct(dummyProductWrapper),
Copy link
Contributor

Choose a reason for hiding this comment

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

nits:
The formatting here is a little weird. I think it is because of the line max limit from the auto formatter?
Maybe we can assign a local variable to the product details and pass it to the function call:

final AppStoreProductDetails productDetails = AppStoreProductDetails.fromSKProduct(dummyProductWrapper);
final AppStorePurchaseParam purchaseParam = AppStorePurchaseParam(
        productDetails: productDetails,
        quantity: 5,
        applicationUserName: 'appName');
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added the changes you suggested.

quantity: 5,
applicationUserName: 'appName');
await iapStoreKitPlatform.buyNonConsumable(
purchaseParam: purchaseParam,
quantity: 5
purchaseParam: purchaseParam
);
await completer.future;
expect(fakeStoreKitPlatform.finishedTransactions.first.payment.quantity, 5);
Expand All @@ -477,10 +477,10 @@ void main() {
final AppStorePurchaseParam purchaseParam = AppStorePurchaseParam(
productDetails:
AppStoreProductDetails.fromSKProduct(dummyProductWrapper),
quantity: 5,
applicationUserName: 'appName');
await iapStoreKitPlatform.buyConsumable(
purchaseParam: purchaseParam,
quantity: 5
purchaseParam: purchaseParam
);
await completer.future;
expect(fakeStoreKitPlatform.finishedTransactions.first.payment.quantity, 5);
Expand Down