getErrorCode static method
Use this to convert a PlatformException to a PurchasesErrorCode. It will return PurchasesErrorCode.unknownError if the error code is not in the range of PurchasesErrorCode.
try {
PurchaserInfo purchaserInfo = await Purchases.purchasePackage(package);
} on PlatformException catch (e) {
var errorCode = PurchasesErrorHelper.getErrorCode(e);
switch(errorCode) {
case PurchasesErrorCode.purchaseCancelledError:
print("User cancelled");
break;
case PurchasesErrorCode.purchaseNotAllowedError:
print("User not allowed to purchase");
break;
default:
// Do other stuff
break;
}
}
Implementation
static PurchasesErrorCode getErrorCode(PlatformException e) {
final errorCode = int.parse(e.code);
if (errorCode >= PurchasesErrorCode.values.length) {
return PurchasesErrorCode.unknownError;
}
return PurchasesErrorCode.values[errorCode];
}