Issue
I am using in-app purchase official plugin. but when I am trying to purchase a subscription on iOS I'm seeing the following error:
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 manually using `completePurchase` to avoid edge cases., {applicationUsername: null, requestData: null, quantity: 1, productIdentifier: in_app_test, simulatesAskToBuyInSandbox: false}, null)
I'm using version in_app_purchase: ^0.5.2
of the in_app_purchase package
The code where I'm calling this just looks like this:
TextButton(
child: Text(productDetails.price),
style: flatButtonStyle,
onPressed: () async {
PurchaseParam purchaseParam = PurchaseParam(
productDetails: productDetails,
applicationUserName: null,
sandboxTesting: false);
if (productDetails.id == _kConsumableId) {
_connection.buyConsumable(
purchaseParam: purchaseParam,
autoConsume: kAutoConsume || Platform.isIOS);
} else {
_connection.buyNonConsumable(
purchaseParam: purchaseParam);
}},
)
Solution
please follow up on #60763
You can finishTransaction those transactions using SKPaymentQueueWrapper().finishTransaction(skPaymentTransactionWrapper)
To avoid this error put the code below before buyNonConsumable
and work:
var transactions = await SKPaymentQueueWrapper().transactions();
transactions.forEach((skPaymentTransactionWrapper) {
SKPaymentQueueWrapper().finishTransaction(skPaymentTransactionWrapper);
});
Full example
TextButton(
child: Text(productDetails.price),
style: flatButtonStyle,
onPressed: () async {
PurchaseParam purchaseParam = PurchaseParam(
productDetails: productDetails,
applicationUserName: null,
sandboxTesting: false);
if (productDetails.id == _kConsumableId) {
_connection.buyConsumable(
purchaseParam: purchaseParam,
autoConsume: kAutoConsume || Platform.isIOS);
} else {
_connection.buyNonConsumable(
purchaseParam: purchaseParam);
var transactions = await SKPaymentQueueWrapper().transactions();
transactions.forEach((skPaymentTransactionWrapper) {
SKPaymentQueueWrapper().finishTransaction(skPaymentTransactionWrapper);
});
}
},
)
Answer source from siloebb's answer
Answered By - Paresh Mangukiya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.