-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Description
I'm using version 0.3.3+2 of the in_app_purchase package. It is working fine for Android, but when attempting to purchase a subscription on iOS I'm seeing the following error:
[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: PlatformException(storekit_duplicate_product_object, There is a pending transaction for the same product identifier. Please either wait for it to be finished or finish it manuelly usingcompletePurchase to avoid edge cases., {applicationUsername: null, requestData: null, quantity: 1, productIdentifier: premium, simulatesAskToBuyInSandbox: null}) #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7) #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18) <asynchronous suspension> #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12) #3 SKPaymentQueueWrapper.addPayment (package:in_app_purchase/src/store_kit_wrappers/sk_payment_queue_wrapper.dart:88:19) #4 AppStoreConnection.buyNonConsumable (package:in_app_purchase/src/in_app_purchase/app_store_connection.dart:48:34)
The code where I'm calling this just looks like this:
Future<ProductDetails> getPremiumSubscription() async {
const Set<String> _kIds = {'premium'};
final ProductDetailsResponse response =
await InAppPurchaseConnection.instance.queryProductDetails(_kIds);
List<ProductDetails> products = response.productDetails;
return products.isNotEmpty ? products.first : null;
}
Future<bool> upgradeToPremium() async {
ProductDetails premiumSubscription = await getPremiumSubscription();
if (premiumSubscription != null) {
return await purchaseSubscription(premiumSubscription);
} else {
return false;
}
}
Future<bool> purchaseSubscription(ProductDetails product) async {
final PurchaseParam purchaseParam = PurchaseParam(productDetails: product);
return await InAppPurchaseConnection.instance
.buyNonConsumable(purchaseParam: purchaseParam);
}