Flutter in_app_purchase queryPastPurchases() returns empty list on iOS

Unfortunately, this is currently a known bug of the plugin and as of today there is no other solution than using the unofficial plugin that works better....

You can find the current status of the bug here and the unofficial plugin here


Turns out there was nothing wrong with the code.

In order to make it work I had to create a sandbox user. Then I had to log out from my current logged in AppID on the phone. Then I had to "Edit Scheme" in Xcode from Release to Debug. Then I ran "flutter run" in terminal. Then I purchased my NonConsumable subscription, and in the dialog I had to enter the sandbox user email and pwd.

Updated: Also I had to create a completely new subscription in app store connect, because the original subscription got trapped in a state were it was not bought nor purchasable. This was due to the fact that the completePurchase was done at the wrong place in my code. It should not be done in _getPastPurchases(), but rather in the actual purchase logic.

So put completePurchase here:

_subscription = _iap.purchaseUpdatedStream.listen((data) => setState(() {
    _purchases.addAll(data);
    for(PurchaseDetails purchase in _purchases){
        if(purchase.productID == 'subName'){
            //SOLUTION
            if (Platform.isIOS) {
                InAppPurchaseConnection.instance.completePurchase(purchase);
            }
        }
    }   
}));

PS: I don't remember if I had the completePurchse in the for loop or outside...

Tags:

Flutter