Skip to content

Commit

Permalink
Properly implement cancellation protocol when users dismiss pay sheet
Browse files Browse the repository at this point in the history
*

*
  • Loading branch information
cornwe19 committed Feb 13, 2024
1 parent ab6cab3 commit 35c6d71
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions packages/stripe_web/lib/src/web_stripe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
}
});

Expand Down Expand Up @@ -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<bool> get isPaymentAvailable => this.canMakePayment().then((value) =>
value?.applePay == true ||
Expand Down

0 comments on commit 35c6d71

Please sign in to comment.