Reputation: 267
I have implemented IAP in my flutter app successfully! My problem is how do I know if the user cancels the subscription or not?
I have tried: await FlutterInappPurchase.checkSubscribed();
But it's always returning "false"
Upvotes: 3
Views: 3036
Reputation: 21
You can use await InAppPurchase.instance.restorePurchases();
to restore current purchases. Once the user cancels or pauses his subscriptions, the product will no longer appear in the restored products list.
This is exactly what I have done.
final purchasedUpdated = InAppPurchase.instance.purchaseStream;
StreamSubscription<List<PurchaseDetails>> _subscription = purchasedUpdated.listen(_onPurchasedUpdated);
await InAppPurchase.instance.restorePurchases();
And later,
void _onPurchasedUpdated(List<PurchaseDetails> purchaseDetailsList) {
purchaseDetailsList.forEach((purchaseDetails){
if (purchaseDetails.status == PurchaseStatus.restored) {
print(purchaseDetails.productID);
}
});
}
The subscription stream will listen to updates on subscriptions in the app.
Upvotes: 1
Reputation: 2134
You need to use Real time developer notifications. It uses Google PubSub that sends the information to your endpoint as and when the subscriptions update or get cancelled. It is easily configurable in the Play Store Console.
https://developer.android.com/google/play/billing/billing_subscriptions#Handle-states
Upvotes: 1