From 35c6d71a1c6a1a0eed731f651a022614ef969c41 Mon Sep 17 00:00:00 2001 From: Dennis Cornwell Date: Tue, 13 Feb 2024 10:39:22 -0500 Subject: [PATCH] Properly implement cancellation protocol when users dismiss pay sheet * * --- packages/stripe_web/lib/src/web_stripe.dart | 22 +++++++++------------ 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/packages/stripe_web/lib/src/web_stripe.dart b/packages/stripe_web/lib/src/web_stripe.dart index 5be1e9093..d025b0816 100644 --- a/packages/stripe_web/lib/src/web_stripe.dart +++ b/packages/stripe_web/lib/src/web_stripe.dart @@ -543,14 +543,20 @@ class WebStripe extends StripePlatform { response.complete('success'); }); paymentRequest.onCancel(() { - completer.completeError(CancellationError('Payment request cancelled')); + completer.completeError(StripeException( + error: LocalizedErrorMessage( + code: FailureCode.Canceled, + message: 'Payment request cancelled'))); }); paymentRequest.isPaymentAvailable.then((available) { if (available) { paymentRequest.show(); } else { - completer.completeError(CancellationError( - "No enabled wallets are available for payment method creation")); + completer.completeError(StripeException( + error: LocalizedErrorMessage( + code: FailureCode.Failed, + message: + "No enabled wallets are available for payment method creation"))); } }); @@ -617,16 +623,6 @@ class WebUnsupportedError extends Error implements UnsupportedError { : "WebUnsupportedError"; } -class CancellationError extends Error implements Exception { - final String? message; - - CancellationError([this.message]); - - @override - String toString() => - (message != null) ? "CancellationError: $message" : "CancellationError"; -} - extension CanMakePayment on stripe_js.PaymentRequest { Future get isPaymentAvailable => this.canMakePayment().then((value) => value?.applePay == true ||