flutter-stripe / flutter_stripe

Flutter SDK for Stripe.
https://pub.dev/packages/flutter_stripe
927 stars 510 forks source link

[Exception] when closing customer sheet (Customer Sheet Result deserialization) #1854

Closed angelorodem closed 1 month ago

angelorodem commented 1 month ago

Describe the bug When getting error from stripe, StripeError.fromJson( returns an error type 'String' is not a subtype of type 'Map<String, dynamic>' in type cast

the code i use is this

Future<void> confirmCustomerSheet() async {
    try {
      // 3. display the customer sheet.
      final result = await Stripe.instance.presentCustomerSheet();
[...]

in this code

_$CustomerSheetResultImpl _$$CustomerSheetResultImplFromJson(
        Map<String, dynamic> json) =>
    _$CustomerSheetResultImpl(
      paymentOption: json['paymentOption'] == null
          ? null
          : PaymentSheetPaymentOption.fromJson(
              json['paymentOption'] as Map<String, dynamic>),
      paymentMethod: json['paymentMethod'] == null
          ? null
          : PaymentMethod.fromJson(
              json['paymentMethod'] as Map<String, dynamic>),
      error: json['error'] == null
          ? null
          : StripeError<dynamic>.fromJson( // ------- here
              json['error'] as Map<String, dynamic>),
    );

strangely on the debugger the field seems to be a map image but the code still except with this message:

[log] type 'String' is not a subtype of type 'Map<String, dynamic>' in type cast
[log] _TypeError (type 'String' is not a subtype of type 'Map<String, dynamic>' in type cast)
[log] #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:135:13)
      #5      new _$CustomerSheetResultImpl.fromJson (package:stripe_platform_interface/src/models/customer_sheet.freezed.dart:1060:7)
      #6      _$CustomerSheetResultFromJson (package:stripe_platform_interface/src/models/customer_sheet.freezed.dart:891:31)
      #7      new CustomerSheetResult.fromJson (package:stripe_platform_interface/src/models/customer_sheet.dart:105: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:charge_app/pages/payment_page.dart:132:22)
      <asynchronous suspension>
      #11     _LoadingButtonState._loadFuture (package:charge_app/loading_button.dart:50:7)
      <asynchronous suspension>

To Reproduce Steps to reproduce the behavior:

  1. Create customer sheet
  2. Create payment method
  3. close
  4. open customer sheet
  5. click on the X button.
  6. the error field fails to be converted to map

Expected behavior should not except

this seems to be because error field needs to be decoded before?

remonh87 commented 1 month ago

Simulator Screenshot - iPhone 15 - 2024-07-17 at 20 26 21

I cannot reproduce it on the example app what is the version that you are using?