Hi!
I get a platform exception when a user cancels the purchas of an in-app product. I cannot catch the exception. Physical device, product is correctly setup, afaik.
Error:
PlatformException (PlatformException(1, Purchase was cancelled., {code: 1, message: Purchase was cancelled., readableErrorCode: PurchaseCancelledError, readable_error_code: PurchaseCancelledError, underlyingErrorMessage: Error updating purchases. DebugMessage: . ErrorCode: USER_CANCELED., userCancelled: true}, null))
try {
final customerInfo = await Purchases.purchasePackage(currentPackage!);
// Check if the product was successfully purchased by verifying active subscriptions.
if (customerInfo.activeSubscriptions.contains(revenueCatProduct)) {
markAsPurchased();
}
} on PlatformException catch (e) {
bool isCancelled = false;
if (e.details is Map) {
final Map details = e.details as Map;
if (details['userCancelled'] == true ||
(details['readableErrorCode'] != null &&
details['readableErrorCode'].toString().toLowerCase() ==
'purchasecancellederror')) {
isCancelled = true;
}
}
if (e.message != null && e.message!.toLowerCase().contains('cancel')) {
isCancelled = true;
}
if (isCancelled) {
debugPrint("Purchase cancelled by user.");
} else {
errorMessage = "Purchase failed: ${e.message}";
}
} catch (e) {
errorMessage = "Purchase failed: $e";
} finally {
isPurchasing = false;
notifyListeners();
}