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.
1try {2 CustomerInfo customerInfo = await Purchases.purchasePackage(package);3 var isPro = customerInfo.entitlements.all["my_entitlement_identifier"].isActive;4 if (isPro) {5 // Unlock that great "pro" content6 }7} on PlatformException catch (e) {8 var errorCode = PurchasesErrorHelper.getErrorCode(e);9 if (errorCode != PurchasesErrorCode.purchaseCancelledError) {10 showError(e); 11 }12}
This is the code from the sample.
1 void perfomMagic() async {2 setState(() {3 _isLoading = true;4 });56 CustomerInfo customerInfo = await Purchases.getCustomerInfo();78 if (customerInfo.entitlements.all[entitlementID] != null &&9 customerInfo.entitlements.all[entitlementID]?.isActive == true) {1011 setState(() {12 _isLoading = false;13 });14 } else {15 late Offerings offerings;16 try {17 offerings = await Purchases.getOfferings();18 } on PlatformException catch (e) {19 await showDialog(20 context: context,21 builder: (BuildContext context) => ShowDialogToDismiss(22 title: "Error", content: e.message!, buttonText: 'OK'));23 }2425 setState(() {26 _isLoading = false;27 });2829 if (offerings.current == null) {30 // offerings are empty, show a message to your user31 } else {32 // current offering is available, show paywall33 await showModalBottomSheet(34 useRootNavigator: true,35 isDismissible: true,36 isScrollControlled: true,37 backgroundColor: Colors.black87,38 shape: const RoundedRectangleBorder(39 borderRadius: BorderRadius.vertical(top: Radius.circular(25.0)),40 ),41 context: context,42 builder: (BuildContext context) {43 return StatefulBuilder(44 builder: (BuildContext context, StateSetter setModalState) {45 return Paywall(46 offering: offerings.current!,47 );48 });49 },50 );51 }52 }53 }