I use ExamplePaymentQueueDelegate
to restore purchases on iOS, and it works fine in my case, in promo codes as well.
Future<void> init() async {
await _fetchSubscriptions();
final purchaseUpdated = _inAppPurchase.purchaseStream;
_subscription = purchaseUpdated.listen(
_listenToPurchaseUpdated,
onDone: () {
_subscription.cancel();
},
onError: (Object error) {
log(error.toString());
},
);
if (Platform.isIOS) {
final iosPlatformAddition = _inAppPurchase
.getPlatformAddition<InAppPurchaseStoreKitPlatformAddition>();
await iosPlatformAddition.setDelegate(ExamplePaymentQueueDelegate());
} else {
await InAppPurchase.instance.restorePurchases();
}
}
class ExamplePaymentQueueDelegate implements SKPaymentQueueDelegateWrapper {
@override
bool shouldContinueTransaction(
SKPaymentTransactionWrapper transaction,
SKStorefrontWrapper storefront,
) {
return true;
}
@override
bool shouldShowPriceConsent() {
return false;
}
}
Also, please show price consent on hitting subscribe button to avoid future bugs
if (Platform.isIOS) {
await confirmPriceChange();
}
Future<void> confirmPriceChange() async {
// Price changes for Android are not handled by the application, but are
// instead handled by the Play Store. See
// https://developer.android.com/google/play/billing/price-changes for more
// information on price changes on Android.
if (Platform.isIOS) {
final iapStoreKitPlatformAddition = _inAppPurchase
.getPlatformAddition<InAppPurchaseStoreKitPlatformAddition>();
await iapStoreKitPlatformAddition.showPriceConsentIfNeeded();
}
}