Skip to main content
Question

PlatformException on cancelled purchase (Android, physical device)


Forum|alt.badge.img

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();

    }

2 replies

Forum|alt.badge.img
  • Author
  • New Member
  • 2 replies
  • March 20, 2025

I have the same error, when using an entitlement, instead of referencing the product: cancelling the transaction crashes revenue cat. It seems to be similar to this error here: 

 

 


jeffrey_bunn
RevenueCat Staff
Forum|alt.badge.img+6
  • RevenueCat Staff
  • 266 replies
  • March 26, 2025

Hi ​@BluePasta - I just replied to your comment here, and have copied my response below:

Hi ​@BluePasta - the PR mentioned above is now merged and currently being released in version 8.7.0. This release should be available in the next few hours. Please upgrade your SDK and the PlatformException should no longer appear. Thanks!


Reply


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