Hi, we have published a flutter app on the App Store offering additional content via one-time in-app purchases. Everything is working as expected when distributing the app via TestFlight but we're reportedly having issues with users not being able to restore purchases on some devices with the app loaded from the Apple App Store.
We noticed the issue when some user were unable to unlock the in-app purchases via promotion codes we supplied for marketing reasons. Most of them were able to unlock the purchases using the promotion codes without a problem. Some had to try several times using a new code each time but for some users (on some of their devices) it's not working at all and we can't seem to find the reason for it.
Here is one users case in detail:
the user tried to unlock our "complete bundle" using a promo code
first code did not seem to work, so I provided a new code
it seems that both codes were redeemed correctly because both of the show up in the users purchase history in his App Store profile
Now, the user is unable to unlock the content inside our app on his iPhone, he is however able to unlock it on its iPad without a problem. Both devices run the same iOS version, same Apple ID and the exact same app version. Even stranger: when using the TestFlight version of the app, again everything is working correctly even on the users iPhone.
I took a look at the device logs and here's what I found:
This is a snapshot of the users iPad. As you can see
products are found and listed correctly
storekitd seems to find and return products in receipt with the correct identifier
we get the correct information and are able to restore the correct purchase
14:48:17.032895+0200 Runner flutter: Found id: de.BUNDLEID.01, title: TITLE 1, price: €29.99
14:48:17.032922+0200 Runner flutter: Found id: de.BUNDLEID.bundle, title: TITLE Gesamtpaket, price: €59.99
14:48:17.032975+0200 Runner flutter: Found id: de.BUNDLEID.02, title: TITLE 2, price: €29.99
14:48:17.033001+0200 Runner flutter: Found id: de.BUNDLEID.extension, title: TITLE Plus, price: €9.99
14:48:20.656702+0200 storekitd [70D5C079]: Found 2 products in receipt with ID de.BUNDLEID.bundle
14:48:20.667793+0200 Runner flutter: Called purchaseListener (purchaseDetailsList: 1)
14:48:20.667838+0200 Runner flutter: Purchase restored
14:48:20.667869+0200 Runner flutter: Unlock permission TITLE_1
14:48:20.667892+0200 Runner flutter: Update TITLE_1 with true
14:48:20.672199+0200 Runner flutter: Unlock permission TITLE_2
14:48:20.672243+0200 Runner flutter: Update TITLE_2 with true
14:48:20.677849+0200 Runner flutter: Unlock permission TITLE_3
14:48:20.677897+0200 Runner flutter: Update TITLE_3 with true
14:48:20.679079+0200 Runner flutter: Calling completePurchase...
Same exact behavior can be observed on the users iPhone when running the TestFlight version of the app.
However, running the app from the Apple App Store on the users iPhone (same Apple ID, same OS and app version), the log looks like this:
14:23:26.150484+0200 Runner flutter: Found id: de.BUNDLEID.bundle, title: TITLE Gesamtpaket, price: €59.99
14:23:26.150513+0200 Runner flutter: Found id: de.BUNDLEID.02, title: TITLE 2, price: €29.99
14:23:26.150619+0200 Runner flutter: Found id: de.BUDNLEID.extension, title: TITLE Plus, price: €9.99
14:23:26.150657+0200 Runner flutter: Found id: de.BUNDLEID.01, title: TITLE 1, price: €29.99
14:23:27.125353+0200 dasd com.apple.icloud.searchpartyd.ProductInfoManager:C25423:[ (name: Thundering Herd Policy, policyWeight:
14:23:27.376336+0200 storekitd [Client] (Runner) Initialized with server Production bundle ID de.ds-infocenter.guk and request bundl
14:23:27.390026+0200 storekitd AMSURRequestEncoder: (7BA6012D] Encoding request for URL: https://mzstorekit.itunes.apple.com/inApps/
14:23:27.984831+0200 storekitd [7BA6012D]: Found 2 products in receipt with ID de.BUNDLEID.bundle
14:23:27.990235+0200 Runner flutter: Called purchaseListener (purchaseDetailsList: 0)
14:23:27.990271+0200 Runner flutter: Purchase details list is empty!
StoreKit seems to return the same exact products but for some reason the purchaseDetails list seems to be empty this time.
Here is the code responsible for restoring the purchases. Nothing fancy going on here if you ask me.
@override
void initState() {
super.initState();
db = context.read<Database>();
inAppPurchase = InAppPurchase.instance;
inAppPurchase.purchaseStream.listen(
purchaseListener,
onError: (error) {
print('Purchase stream error: $error');
showErrorDialog();
},
cancelOnError: true,
);
queryProductInformation().then((value) {
if (value == null) {
print('value in queryProductInformation is null!');
updateProcessing(false);
return;
}
setState(() {
for (var details in value.productDetails) {
products[details.id] = details;
}
});
updateProcessing(false);
});
}
Future<void> restorePurchases() async {
updateProcessing(true);
await inAppPurchase.restorePurchases();
}
void purchaseListener(List<PurchaseDetails> purchaseDetailsList) async {
print(
'Called purchaseListener (purchaseDetailsList: ${purchaseDetailsList.length})');
if (purchaseDetailsList.isEmpty) {
print('Purchase details list is empty!');
updateProcessing(false);
return;
}
for (var purchaseDetails in purchaseDetailsList) {
switch (purchaseDetails.status) {
case PurchaseStatus.purchased:
print('Purchase successful: ${purchaseDetails.productID}');
completePurchase(purchaseDetails.productID);
break;
case PurchaseStatus.canceled:
print('Purchase was canceled');
updateProcessing(false);
break;
case PurchaseStatus.restored:
print('Purchase restored');
completePurchase(purchaseDetails.productID);
break;
case PurchaseStatus.pending:
print('Purchase pending');
break;
case PurchaseStatus.error:
print('Purchase error');
showErrorDialog();
break;
}
print('Calling completePurchase...');
await inAppPurchase.completePurchase(purchaseDetails);
}
}
Could this be an issue on Apples API or flutters in_app_purchase package?