Skip to main content
Question

Deferred Proration Mode Blocks Execution

  • 21 July 2024
  • 2 replies
  • 27 views

 

Hi,

Im using purchases_flutter: ^6.30.1 in my flutter app to handle downgrade and upgrade for subscriptions.

im getting issue in android while downgrading  

await Purchases.purchasePackage call does not resolve when GoogleProrationMode.deferred is used.
Expected behavior: The await Purchases.purchasePackage call should resolve, allowing subsequent code to execute 

Actual behavior: The await Purchases.purchasePackage call does not resolve

 

any help regard this ?

This post has been closed for comments

2 replies

Userlevel 2
Badge +5

Hi @Saeed Basweidan,

 

Does it work with any other mode? And would you be able to pass the snippet of code where you do the purchase call?

Best,

Badge +4

hi @joan-cardona 

all other modes work fine only deferred mode call does not resolve

check the code

also i testing with sand box

 

 

 

import 'package:flutter/material.dart';
import 'package:purchases_flutter/purchases_flutter.dart';

Future<void> purchaseSubscription(BuildContext context, Package package, String activeSubscriptionId) async {
try {
WidgetUtils.showLoading(context);

// Sync attributes and offerings if needed
Purchases.syncAttributesAndOfferingsIfNeeded();

CustomerInfo customerInfo;

if (activeSubscriptionId.isNotEmpty) {
print("---------------------+++++++++++++ deferred---------------------+++++++++++++ ");

customerInfo = await Purchases.purchasePackage(
package,
googleProductChangeInfo: GoogleProductChangeInfo(
activeSubscriptionId,
prorationMode: GoogleProrationMode.deferred,
),
);

print("---------------------+++++++++++++ after deferred---------------------+++++++++++++ ");
} else {
customerInfo = await Purchases.purchasePackage(package);
}

print('---------------------+++++++++++++ payment is done now ---------------------+++++++++++++ ');

if (customerInfo.activeSubscriptions.isNotEmpty) {
logPurchase(package.storeProduct.currencyCode, package.storeProduct.price);

print('purchase-updated: `${package}`');
await Future.delayed(Duration(seconds: 2));
WidgetUtils.hideLoading(context);

Navigator.of(context).pushNamed("/home");
}
} on PlatformException catch (e) {
WidgetUtils.hideLoading(context);
final errorCode = PurchasesErrorHelper.getErrorCode(e);

String errorMessage = "An error occurred: ${e.message}";

if (errorCode == PurchasesErrorCode.purchaseNotAllowedError) {
errorMessage = 'User not allowed to purchase';
} else if (errorCode == PurchasesErrorCode.paymentPendingError) {
errorMessage = 'Payment is pending';
} else if (errorCode == PurchasesErrorCode.productAlreadyPurchasedError) {
errorMessage = 'User already subscribed';
}

if (errorCode != PurchasesErrorCode.purchaseCancelledError) {
WidgetUtils.showMessage(context, "Purchase Error", errorMessage);
}
}
}