Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type cast fails on Customer Sheet cancel #1721

Open
ovchars2 opened this issue Apr 16, 2024 · 5 comments
Open

Type cast fails on Customer Sheet cancel #1721

ovchars2 opened this issue Apr 16, 2024 · 5 comments
Labels
Android Issue related to Android native bindings

Comments

@ovchars2
Copy link

Describe the bug
When a Customer Sheet is closed, a type cast error is thrown instead of StripeException

To Reproduce

  1. Open CustomerSheetScreen
  2. Init Customer Sheet
  3. Present Customer Sheet
  4. Close Customer Sheet by tapping above the sheet or using close button in the top right corner

Expected behavior
StripeException with FailureCode.Canceled is thrown

Smartphone / tablet

  • Device: Pixel 3
  • OS: Android 12
  • Package version: main branch
  • Flutter version: 3.19.3

Additional context
Logs:

W/ActivityResultRegistry(27246): Dropping pending result for request CustomerSheet: ActivityResult{resultCode=RESULT_OK, data=Intent { (has extras) }}
D/StripeReactNative(27246): com.stripe.android.customersheet.InternalCustomerSheetResult$Canceled cannot be cast to com.stripe.android.view.AddPaymentMethodActivityStarter$Result
[log] type 'String' is not a subtype of type 'Map<String, dynamic>' in type cast
      type 'String' is not a subtype of type 'Map<String, dynamic>' in type cast
      #0      _$$StripeErrorGenericImplFromJson (package:stripe_platform_interface/src/models/errors.g.dart:13:40)
      #1      new _$StripeErrorGenericImpl.fromJson (package:stripe_platform_interface/src/models/errors.freezed.dart:123:7)
      #2      _$StripeErrorFromJson (package:stripe_platform_interface/src/models/errors.freezed.dart:18:10)
      #3      new StripeError.fromJson (package:stripe_platform_interface/src/models/errors.dart:26:7)
      #4      _$$CustomerSheetResultImplFromJson (package:stripe_platform_interface/src/models/customer_sheet.g.dart:131:13)
      #5      new _$CustomerSheetResultImpl.fromJson (package:stripe_platform_interface/src/models/customer_sheet.freezed.dart:1024:7)
      #6      _$CustomerSheetResultFromJson (package:stripe_platform_interface/src/models/customer_sheet.freezed.dart:855:31)
      #7      new CustomerSheetResult.fromJson (package:stripe_platform_interface/src/models/customer_sheet.dart:100:7)
      #8      MethodChannelStripe._parseCustomerSheetResult (package:stripe_platform_interface/src/method_channel_stripe.dart:358:36)
      #9      MethodChannelStripe.presentCustomerSheet (package:stripe_platform_interface/src/method_channel_stripe.dart:278:12)
      <asynchronous suspension>
      #10     _CustomerSheetScreenState.confirmCustomerSheet (package:stripe_example/screens/customer_sheet/customer_sheet_screen.dart:119:22)
      <asynchronous suspension>
      #11     _LoadingButtonState._loadFuture (package:stripe_example/widgets/loading_button.dart:50:7)
      <asynchronous suspension>
@ovchars2 ovchars2 added the needs triage Needs triage label Apr 16, 2024
@jamesblasco jamesblasco added Android Issue related to Android native bindings and removed needs triage Needs triage labels Apr 21, 2024
@Flucadetena
Copy link

This also happens on IOS.

Flucadetena added a commit to Flucadetena/flutter_stripe that referenced this issue May 9, 2024
@Flucadetena
Copy link

Flucadetena commented May 9, 2024

I created a pull request to fix this issue. Hopefully it will get merged soon ;)
In the meantime you can use my fork like this. Hope it helps ;)

In your pubspec.yaml

  flutter_stripe:
    git:
      url: https://github.com/Flucadetena/flutter_stripe.git
      path: packages/stripe

dependency_overrides:
  stripe_platform_interface:
    git:
      url: https://github.com/Flucadetena/flutter_stripe.git
      path: packages/stripe_platform_interface

@phawadshah
Copy link

I have somehow the same problem. Collecting payment through cardForm.

  1. Create Intent
  2. CreatePaymentMethod
  3. ConfirmPayment. --> using client_secret and methed_id

If the card is 3d secured the user is redirected to hooks.stripe.com to authenticate the card, but on closing that page it throws StripeException with FailureCode.failed rather than FailureCode.cancelled. since the user explicitly closed the payment process. I am expecting to get FailureCode.cancelled.

@Flucadetena @jamesblasco @ovchars2 @cornwe19 .

Can someone please help me out this?

@Flucadetena
Copy link

Hi @phawadshah I'm sorry but I'm still using my fork to avoid this issue, I can not tell you more than to use it or check out what I did and see if it helps :)

@phawadshah
Copy link

@Flucadetena I did use your fork but it did not work. I think you misread my issue.

  1. Closing paymentSheet
    It throws the expected exception of cancelled.

  2. My issue is when Confirming a payment via card, and Payment intent status is "requires_action" and you close/cancel the process. You can look this in the photo attached.

I am expecting failureCode.cancelled and it throws failed, since it was cancelled by the user.

Simulator Screenshot - iPhone 16 Pro Max - 2024-12-05 at 09 54 23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Issue related to Android native bindings
Projects
None yet
Development

No branches or pull requests

4 participants