flutterin-app-purchaseflutter-in-app-purchase

Flutter: get past purchases on iOS


Everything is working on Android with the new implementation of in_app_purchase (https://pub.dev/packages/in_app_purchase) but on iOS I don't get past purchases. Following the documentation I don't see anything special.

My code is:

final Stream<List<PurchaseDetails>> purchaseUpdated =
          inAppPurchase.purchaseStream;

      _subscription = purchaseUpdated.listen((purchaseDetailsList) {
        if (purchaseDetailsList.isEmpty) {
          Provider.of<AdState>(context, listen: false).toggleAds(context, true);
        } else {
          Provider.of<AdState>(context, listen: false)
              .toggleAds(context, false);
          this.purchases.addAll(purchaseDetailsList);
          listenToPurchaseUpdated(purchaseDetailsList);
        }
      }, onDone: () {
        _subscription.cancel();
      }, onError: (error) {
        // handle error here.
      });

      inAppPurchase.restorePurchases();

It just doesn't go in and if I try to buy same product I get this error:

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


Solution

  • I opened a ticket on the repo and it was fixed on version 1.0.9: https://github.com/flutter/flutter/issues/89950