Flutter in_app_purchase iOS Sandbox App Store: cancelled but not expired subscriptions

Viewed 33

When I used Sandbox to test Flutter in_app_purchase in iOS, if I cancel a subscription in the Sandbox app store, it shows the subscription is already cancelled (but as the old subscription's expiration date is a year from now, so I assume the old one is still not expired), and then when I call InAppPurchase.instance.restorePurchases(), on the stream listen handler parameter List purchaseDetailsList, the canceled subscription still show up (and indeed show up multiple times, if I purchased and cancelled many times before). Is this the intended behaviour? How can I find out if a past purchase was already canceled but not expired yet? I am using in_app_purchase: ^3.0.6

1 Answers

If you are testing it in sandbox then the duration is lowered to minutes for testing.

preview

Also to remove all purchases you can try this code

  Future<void> clearTransactionsIos() async {
    if (Platform.isIOS) {
      final transactions = await SKPaymentQueueWrapper().transactions();
      for (final transaction in transactions) {
        try {
          if (transaction.transactionState !=
              SKPaymentTransactionStateWrapper.purchasing) {
            await SKPaymentQueueWrapper().finishTransaction(transaction);
          }
        } catch (e) {
          print(e);
        }
      }
    }
  }

This should remove all pending transactions.

More about IAP testing https://help.apple.com/app-store-connect/#/dev7e89e149d

Related