Skip to main content
Question

Dart SDK, can you please clarify the purchasePackage() sample code?

  • December 13, 2024
  • 1 reply
  • 6 views

Forum|alt.badge.img

Hello, could someone kindly explain why we should check entitlements.all isActive after a purchase before unlocking the feature (see code below) ? My points are:

  1. If purchasePackage() didn’t fail, it means that the purchase was processed successfully and this should be enough to unlock the features associated to the purchase.
  2. Checking isActive of Entitlements doesn’t make sense in the case where Entitlement has several consumable products (ie. boost_1, boost_2, boost_3) which can be purchased multiple times (so for example , user might have 3 active boost_1, 1 active boost_2, 5 active boost_3, etc). In that case, using customerInfo.entitlements.all["my_entitlement_identifier"].isActive might lead even to wrong outcome. Am I missing something?

 

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

This post has been closed for comments

1 reply

kaitlin
RevenueCat Staff
Forum|alt.badge.img+6
  • RevenueCat Staff
  • 365 replies
  • December 17, 2024

Hey ​@ioseph,

Any code snippets that you see in our documentation are just recommendations and may not make sense for every app installation, as you mentioned in the example of the consumables products. You can set up your flow of checking entitlements, or not, as you wish, and just use the snippets as a guide.


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