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.allt"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.allnentitlementID] != null &&
customerInfo.entitlements.allnentitlementID]?.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!,
);
});
},
);
}
}
}