Reputation: 4769
I am using in_app_purchase package.
I have created a free package with a price of 0.00 in the "in-app purchase" section. also, I have created a recurring package of 0.00 in the "subscription" section as the "in-app purchase" section does not allow me to create the recurring package.
but the issue is, how do I cancel the active package?
I tried changing the package from recurring to free package as a cancel. But when I try to buy the recurring package again, it shows you have already bought that package.
how to solve this issue?
P.S. I did find a few answers in the StackOverflow but none of them answers my question
/// Buy package using in-app purchase
Future<void> buy(Package pkg) async {
try {
if (!Platform.isIOS) return;
final bool available = await iapInstance.isAvailable();
if (!available) {
throw ('In app purchase not available');
}
final ProductDetails productDetails = state.iapProducts.firstWhere(
(e) => e.id == prefixedSlug(pkg.slug),
orElse: () =>
throw ('Selected package not available in IAP at the moment'));
await iapInstance.buyNonConsumable(
purchaseParam: PurchaseParam(
productDetails: productDetails,
applicationUserName: '${authCubit.state.authUserModel.user.id}',
),
);
} catch (e) {
print('=> buy() Error: $e');
emit(state.copyWith(isProcessing: false));
rethrow;
}
}
/// returns the slug with the app package identifier as the prefix
///
/// DEV: free => com.example.dev.free
///
/// PROD: free => com.example.free
String prefixedSlug(String slug) {
final String prefix = PackageInfoUtils.packageInfo.packageName;
return '$prefix.$slug';
}
Upvotes: 2
Views: 733