Payment flow cancellation exceptions from flutter_stripe are not caught by try-catch blocks #2190
Unanswered
WaliHassanKhan
asked this question in
Q&A
Replies: 3 comments
-
|
I think there must be something wrong in your current application because we do exactly what you state and we get the StripeException nicely in our try catch block. See: I think somewhere you miss concurrency awaiting because we use standard dart exception throwing. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
-
|
this only happens during the debug mode. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
When using the flutter_stripe package, if the user cancels the payment flow, a StripeException is thrown with FailureCode.Canceled (clicking outside the payment box), but this exception does not get caught by surrounding try-catch blocks in Dart async methods. Instead it crashes the app.
cancelling await Stripe.instance.presentPaymentSheet() would crash the app
if you don't use await. It wont crash the app.
To Reproduce
try {
await Stripe.instance.confirmPayment(
paymentIntentClientSecret,
PaymentMethodParams.card(),
);
// Payment confirmed
} on StripeException catch (e) {
// This should catch the cancellation, but does not
print('Stripe Error: ${e.error.localizedMessage}');
} catch (e) {
// Other errors
print('Other Error: $e');
}
Result: The cancellation exception is not caught by any of the catch handlers above.
flutter_stripe: ^11.5.0
Expected behavior
The debugger would go to the await Stripe.instance.presentPaymentSheet();
line and show you the exception.
_$StripeExceptionImpl (StripeException(error: LocalizedErrorMessage(code: FailureCode.Canceled, localizedMessage: The payment flow has been canceled, message: The payment flow has been canceled, ...)))
However, it would not go to the catch block.
Smartphone / tablet
Additional context:
This breaks the standard Dart exception handling flow and makes handling Stripe errors much harder. Please advise if there's a workaround or if this needs to be fixed at the plugin level.
Beta Was this translation helpful? Give feedback.
All reactions