iosflutterin-app-purchasestorekit2

Purchase quantity is ignored in in_app_purchase_storekit


I'm using Flutter's in_app_purchase_storekit package (StoreKit 2) to allow purchasing multiple quantities of a consumable product on iOS.

According to Apple’s official documentation, StoreKit 2 supports setting a purchase quantity (up to 10). However, even when I pass a quantity > 1 to AppStorePurchaseParam, the Apple Pay sheet only shows the price for a single item, and the resulting purchase always returns "quantity": 1.

Here's my code:

Future<void> buyCoin(int amount) async {
  try {
    final product = _products.firstWhere((p) => p.id == 'test');
    final purchaseParam = AppStorePurchaseParam(
      productDetails: product,
      quantity: amount,
    );

    await _iap.buyConsumable(purchaseParam: purchaseParam);
  } catch (e) {
    debugPrint('Failed to initiate BLK purchase: $e');
  }
}

But the resulting StoreKit transaction always returns:

"quantity": 1

Even though I passed quantity: 5.

Has anyone successfully purchased more than 1 quantity of a product using in_app_purchase_storekit and StoreKit 2 on iOS? Or is this a limitation/bug in the Flutter plugin?


Solution

  • I’ve resolved this issue. The problem was due to the in_app_purchase_storekit package not handling the purchase quantity parameter correctly for StoreKit 2.

    I made the necessary changes to the package to support purchasing multiple quantities, submitted them to the Flutter team, and the changes have now been approved and are live on pub.dev.

    You can check the updated package here:
    https://pub.dev/packages/in_app_purchase_storekit

    With the latest version, passing a quantity greater than 1 to AppStorePurchaseParam will now correctly reflect in the Apple Pay sheet and in the returned StoreKit transaction.