Skip to main content
Solved

Purchasing subscription


Forum|alt.badge.img+1

I’m following the Magic Weather App, all working fine but I want to update customer’s record to indicate that they subscribed. According to the quick guide I need to have the following code but the sample code missing this bit of code. My question is how is working? Does Purchases.getCustomerInfo() does the actual purchase? Please advise.

try {
  CustomerInfo customerInfo = await Purchases.purchasePackage(package);
  var isPro = customerInfo.entitlements.all["my_entitlement_identifier"].isActive;
  if (isPro) {
    // Unlock that great "pro" content
  }
} on PlatformException catch (e) {
  var errorCode = PurchasesErrorHelper.getErrorCode(e);
  if (errorCode != PurchasesErrorCode.purchaseCancelledError) {
    showError(e);             
  }
}

This is the code from the sample.
 

  void perfomMagic() async {
    setState(() {
      _isLoading = true;
    });

    CustomerInfo customerInfo = await Purchases.getCustomerInfo();

    if (customerInfo.entitlements.all[entitlementID] != null &&
        customerInfo.entitlements.all[entitlementID]?.isActive == true) {

      setState(() {
        _isLoading = false;
      });
    } else {
      late Offerings offerings;
      try {
        offerings = await Purchases.getOfferings();
      } on PlatformException catch (e) {
        await showDialog(
            context: context,
            builder: (BuildContext context) => ShowDialogToDismiss(
                title: "Error", content: e.message!, buttonText: 'OK'));
      }

      setState(() {
        _isLoading = false;
      });

      if (offerings.current == null) {
        // offerings are empty, show a message to your user
      } else {
        // current offering is available, show paywall
        await showModalBottomSheet(
          useRootNavigator: true,
          isDismissible: true,
          isScrollControlled: true,
          backgroundColor: Colors.black87,
          shape: const RoundedRectangleBorder(
            borderRadius: BorderRadius.vertical(top: Radius.circular(25.0)),
          ),
          context: context,
          builder: (BuildContext context) {
            return StatefulBuilder(
                builder: (BuildContext context, StateSetter setModalState) {
              return Paywall(
                offering: offerings.current!,
              );
            });
          },
        );
      }
    }
  }

 

Best answer by kaitlin

Hi @Huzzi,

The customerInfo object contains the user’s purchase data and is updated periodically or when a purchase is made. Calling .getCustomerInfo doesn’t make the purchase itself, just returns that user information. It’s safe to call as often as you need. You can see more about it here in our docs: https://www.revenuecat.com/docs/customer-info#get-user-information

 

View original
Did this post help you find an answer to your question?

kaitlin
RevenueCat Staff
Forum|alt.badge.img+6
  • RevenueCat Staff
  • December 13, 2022

Hi @Huzzi,

The customerInfo object contains the user’s purchase data and is updated periodically or when a purchase is made. Calling .getCustomerInfo doesn’t make the purchase itself, just returns that user information. It’s safe to call as often as you need. You can see more about it here in our docs: https://www.revenuecat.com/docs/customer-info#get-user-information

 


Forum|alt.badge.img+1
  • New Member
  • December 13, 2022

Thanks, I’ve found that paywall file does the actual purchasing. Thank you


Reply


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