The payment flow is working completely fine, but when the slow test card is used the consumable product cannot be purchased again. the plugin used is in_app_purchase: ^3.0.4. To reproduce the issue:
- purchase the product with "slow test card, Approves after a few minutes" option.
- once initiated then close the application.
- open the application. The purchase stream will be triggered and
await InAppPurchase.instance.completePurchase(purchaseDetails);
will successfully run for that purchase. But after that, when I try to purchase the product, the google play in-app-purchases handler throws an error: You already own this item. The whole process works successfully when app is not closed in the process.
and also i'm not able to convert that product back to consumable.
code snippet
purchaseParam=PurchaseParam(productDetails:selectedProduct);
InAppPurchase.instance.buyConsumable(purchaseParam: purchaseParam);
_subscription = purchaseUpdated.listen((purchaseDetailsList) {
log("initiating purchase stream");
p_purchaseList = purchaseDetailsList;
listenToPurchaseUpdated(purchaseDetailsList);
}, onDone: () {
log("done..");
_subscription.cancel();
}, onError: (error) {
log("error in payment is = $error");
},
);
void listenToPurchaseUpdated(List<PurchaseDetails> purchaseDetailsList) async {
log("listening to purchases 1 ");
purchaseDetailsList.forEach((PurchaseDetails purchaseDetails) async {
if (purchaseDetails.status == PurchaseStatus.pending) {
} else {
if (purchaseDetails.status == PurchaseStatus.error||purchaseDetails.status == PurchaseStatus.canceled) {
print("error :${purchaseDetails.error!}");
}
else if (purchaseDetails.status == PurchaseStatus.purchased || purchaseDetails.status == PurchaseStatus.restored) {
FirebaseDataStorage().uploadPurchaseInfo(purchaseDetails); // performing tasks once product is purchased
}
if (purchaseDetails.pendingCompletePurchase) {
log("listening to purchases 5 ");
await InAppPurchase.instance.completePurchase(purchaseDetails);
}
}
});
}
the stream is listened in initstate
flutter doctor -v
[✓] Flutter (Channel stable, 3.0.0, on macOS 12.2.1 21D62 darwin-x64, locale en-GB)
• Flutter version 3.0.0 at /Users/anubhav/Library/Developer/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ee4e09cce0 (10 days ago), 2022-05-09 16:45:18 -0700
• Engine revision d1b9a6938a
• Dart version 2.17.0
• DevTools version 2.12.2
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
• Android SDK at /Users/anubhav/Library/Android/sdk
• Platform android-32, build-tools 32.1.0-rc1
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.4)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
[✓] Connected device (4 available)
• 2201117TI (mobile) • 7a310cf0 • android-arm64 • Android 11 (API 30)
• iPhone SE (3rd generation) (mobile) • 27BC18C4-21F5-43EA-A7F1-9A0DC41FF182 • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-5 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS 12.2.1 21D62 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 101.0.4951.64
[✓] HTTP Host Availability
• All required HTTP hosts are available