flutter_stripe icon indicating copy to clipboard operation
flutter_stripe copied to clipboard

Payment Error Handling on the Web

Open mcmikecreations opened this issue 3 years ago • 13 comments

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:

  1. Generate wrong secret key on the backend.
  2. Enter card info.
  3. Tapping the confirm button.
  4. 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

mcmikecreations avatar Feb 04 '22 15:02 mcmikecreations

Thanks for the clear description very helpful. You are right we should provide an error that can be caught.

remonh87 avatar Feb 05 '22 13:02 remonh87

bro fix this package it is far away from bull shit fix it

RawatAshish11 avatar Feb 09 '22 11:02 RawatAshish11

Hi @RawatAshish11 - I have just reported your comment. Please provide constructive feedback and refrain yourself from harassing anyone on this platform.

jonasbark avatar Feb 09 '22 11:02 jonasbark

I'm having same issue, mobile version returns a StripeException, but web returns a LegacyJavaScriptObject that has no public properties.

VictorSDK avatar Mar 31 '22 20:03 VictorSDK

We are having the same issue. Any timeline on the fix?

devyev avatar Mar 31 '22 20:03 devyev

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.

CRDEV00 avatar Mar 31 '22 21:03 CRDEV00

We are having the same issue. Any timeline on the fix?

wintrue avatar Jul 08 '22 11:07 wintrue

We are having the same issue. Any timeline on the fix?

wintrue avatar Jul 08 '22 11:07 wintrue

@jonasbark remonh87 我们有同样的问题。有修复的时间表吗?

wintrue avatar Jul 12 '22 07:07 wintrue

I would love to have a fix for this. This would help me to show the exact error of what happened

sramac2 avatar Jul 16 '22 16:07 sramac2

+1

debjeetdebnath avatar Oct 14 '22 15:10 debjeetdebnath

Hello! I I am currently working on a fix for this. Will update when it is fixed

jamesblasco avatar Oct 14 '22 15:10 jamesblasco

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.

chatoromo avatar Oct 18 '22 03:10 chatoromo

@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?

image

mminhlequang avatar Jul 03 '23 09:07 mminhlequang

I saw you already throw StripeError but why i can't catch it

always catch _$36_PaymentElementChangeEvent (js object) or i missing something?

Same here with Stripe.instance.confirmSetupIntent() on web. Error's runtime type is _$36_PaymentElementChangeEvent.

dioseltorre avatar Sep 13 '23 03:09 dioseltorre