Skip to main content
Question

Deferred Proration Mode Blocks Execution


Forum|alt.badge.img+4

 

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

joan-cardona
RevenueCat Staff
Forum|alt.badge.img+6
  • RevenueCat Staff
  • 208 replies
  • July 24, 2024

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,


Forum|alt.badge.img+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);
    }
  }
}

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings