flutter_stripe
flutter_stripe copied to clipboard
Payment Error Handling on the Web
Describe the bug Observed during debugging on Chrome. My current code to make a payment is:
try {
final paymentMethod = PaymentMethodParams.card(
billingDetails: details,
);
final intent = await Stripe.instance.confirmPayment(secretKey, paymentMethod);
logger.d(intent);
if (intent.status == PaymentIntentsStatus.Succeeded) {
NavigatorUtils.returnRoute<WebPaymentPayload>(context, WebPaymentSuccessPayload(verified: true));
} else {
NavigatorUtils.returnRoute(context, WebPaymentErrorPayload(message: intent.description));
}
}
on StripeException catch (e) {
handleError(context, e.error.localizedMessage ?? '');
}
on StripeError catch (e) {
handleError(context, e.message);
}
on PlatformException catch (e) {
handleError(context, e.message ?? '');
}
on Exception catch (e) {
handleError(context, e.toString());
}
on Error catch (e) {
handleError(context, e.toString());
}
Despite all these efforts, when something goes wrong in the intent (card number is wrong, problems with internet, wrong secret key from backend, etc.), flutter_stripe_web on this line throws an error that I can't catch. Because of this, an [object Object] is printed in the console, the card field disappears and nothing else happens. I can't enter new information, can't re-send it, nothing. I have to navigate to a different view and then back to get the card field to show up again.
To Reproduce Steps to reproduce the behavior:
- Generate wrong secret key on the backend.
- Enter card info.
- Tapping the confirm button.
- Observe uncaught error.
Expected behavior I expect to be able to catch the error and properly handle it depending on the type, message, etc.
Smartphone / tablet
- Device: Chrome
- OS: Win 11 Pro
- Package version: flutter_stripe: ^2.1.1 flutter_stripe_web: ^0.1.1
- Flutter version: 2.8.1
Additional context [√] Flutter (Channel stable, 2.8.1, on Microsoft Windows [Version 10.0.22000.434]) • Flutter version 2.8.1 at C:\Soft\Android\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 77d935af4d (7 weeks ago), 2021-12-16 08:37:33 -0800 • Engine revision 890a5fca2e • Dart version 2.15.1 [√] Connected device (3 available) • Chrome (web) • chrome • web-javascript • Google Chrome 97.0.4692.99
Thanks for the clear description very helpful. You are right we should provide an error that can be caught.
bro fix this package it is far away from bull shit fix it
Hi @RawatAshish11 - I have just reported your comment. Please provide constructive feedback and refrain yourself from harassing anyone on this platform.
I'm having same issue, mobile version returns a StripeException, but web returns a LegacyJavaScriptObject that has no public properties.
We are having the same issue. Any timeline on the fix?
Having the same problem here, Is there any way to parse somehow the exception, I'd like to show a more descriptive error to my users.
We are having the same issue. Any timeline on the fix?
We are having the same issue. Any timeline on the fix?
@jonasbark remonh87 我们有同样的问题。有修复的时间表吗?
I would love to have a fix for this. This would help me to show the exact error of what happened
+1
Hello! I I am currently working on a fix for this. Will update when it is fixed
James. Thanks for working on this. Can you please provide us with an estimate? I was also talking to my team last week about fixing it on our end since it is a critical part of our project.
@jamesblasco hi i have question
I saw you already throw StripeError but why i can't catch it
always catch _$36_PaymentElementChangeEvent (js object)
or i missing something?
I saw you already throw
StripeErrorbut why i can't catch italways catch
_$36_PaymentElementChangeEvent(js object) or i missing something?
Same here with Stripe.instance.confirmSetupIntent() on web. Error's runtime type is _$36_PaymentElementChangeEvent.