Solved

Purchasing subscription

  • 11 December 2022
  • 2 replies
  • 77 views

Badge +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!,
);
});
},
);
}
}
}

 

icon

Best answer by kaitlin 13 December 2022, 21:24

View original

2 replies

Userlevel 4
Badge +6

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

 

Badge +1

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

Reply