From c6f41004b55d7d9d475da9d3f504ffb75f9a6a63 Mon Sep 17 00:00:00 2001 From: Giacomo Policicchio Date: Wed, 17 Jul 2024 20:54:03 +0200 Subject: [PATCH] Fix/deferred payment methods (#1839) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixes #1834 * Fixes #1837 * Rollback Stripe Sdk Changes, Alternative solution for flutter-stripe#1834 * Rollback Change on Stripe Ios Sdk --------- Co-authored-by: Giacomo Policicchio Co-authored-by: RĂ©mon --- .../payment_sheet_deffered_screen.dart | 1 + .../facebook/react/bridge/ReadableMap.java | 2 + .../lib/src/models/payment_sheet.dart | 2 +- .../lib/src/models/payment_sheet.freezed.dart | 40 +++++++++---------- .../lib/src/models/payment_sheet.g.dart | 28 ++++++++----- 5 files changed, 43 insertions(+), 30 deletions(-) diff --git a/example/lib/screens/payment_sheet/payment_sheet_deffered_screen.dart b/example/lib/screens/payment_sheet/payment_sheet_deffered_screen.dart index dfe823965..7425c8ab3 100644 --- a/example/lib/screens/payment_sheet/payment_sheet_deffered_screen.dart +++ b/example/lib/screens/payment_sheet/payment_sheet_deffered_screen.dart @@ -91,6 +91,7 @@ class _PaymentSheetScreenState extends State { await Stripe.instance.initPaymentSheet( paymentSheetParameters: SetupPaymentSheetParameters( // Main params + returnURL: 'flutterstripe://stripe-redirect"', merchantDisplayName: 'Flutter Stripe Store Demo', intentConfiguration: IntentConfiguration( mode: IntentMode( diff --git a/packages/stripe_android/android/src/main/kotlin/com/facebook/react/bridge/ReadableMap.java b/packages/stripe_android/android/src/main/kotlin/com/facebook/react/bridge/ReadableMap.java index 9e76d1a9d..789089824 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/facebook/react/bridge/ReadableMap.java +++ b/packages/stripe_android/android/src/main/kotlin/com/facebook/react/bridge/ReadableMap.java @@ -85,6 +85,8 @@ public ReadableType getType(String key) { return ReadableType.Boolean; } else if (value instanceof Iterable) { return ReadableType.Array; + } else if (value instanceof JSONArray) { + return ReadableType.Array; } else if (value instanceof Number) { return ReadableType.Number; } else if (value instanceof Map || (value instanceof JSONObject)) { diff --git a/packages/stripe_platform_interface/lib/src/models/payment_sheet.dart b/packages/stripe_platform_interface/lib/src/models/payment_sheet.dart index 673240df1..76fdcaff1 100644 --- a/packages/stripe_platform_interface/lib/src/models/payment_sheet.dart +++ b/packages/stripe_platform_interface/lib/src/models/payment_sheet.dart @@ -138,7 +138,7 @@ class IntentConfiguration with _$IntentConfiguration { @freezed class IntentMode with _$IntentMode { - @JsonSerializable(explicitToJson: true) + @JsonSerializable(explicitToJson: true,includeIfNull: false) const factory IntentMode({ required String currencyCode, required int amount, diff --git a/packages/stripe_platform_interface/lib/src/models/payment_sheet.freezed.dart b/packages/stripe_platform_interface/lib/src/models/payment_sheet.freezed.dart index d7e739006..1c2870aaf 100644 --- a/packages/stripe_platform_interface/lib/src/models/payment_sheet.freezed.dart +++ b/packages/stripe_platform_interface/lib/src/models/payment_sheet.freezed.dart @@ -12,7 +12,7 @@ part of 'payment_sheet.dart'; T _$identity(T value) => value; final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); SetupPaymentSheetParameters _$SetupPaymentSheetParametersFromJson( Map json) { @@ -711,7 +711,7 @@ class _$SetupParametersImpl implements _SetupParameters { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$SetupParametersImpl && @@ -1130,7 +1130,7 @@ class _$IntentConfigurationImpl implements _IntentConfiguration { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$IntentConfigurationImpl && @@ -1320,7 +1320,7 @@ class __$$IntentModeImplCopyWithImpl<$Res> /// @nodoc -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class _$IntentModeImpl implements _IntentMode { const _$IntentModeImpl( {required this.currencyCode, @@ -1350,7 +1350,7 @@ class _$IntentModeImpl implements _IntentMode { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$IntentModeImpl && @@ -1636,7 +1636,7 @@ class _$PaymentSheetApplePayImpl implements _PaymentSheetApplePay { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetApplePayImpl && @@ -1928,7 +1928,7 @@ class _$PaymentSheetGooglePayImpl implements _PaymentSheetGooglePay { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetGooglePayImpl && @@ -2201,7 +2201,7 @@ class _$PaymentSheetAppearanceImpl implements _PaymentSheetAppearance { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetAppearanceImpl && @@ -2631,7 +2631,7 @@ class _$PaymentSheetAppearanceColorsImpl } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetAppearanceColorsImpl && @@ -2941,7 +2941,7 @@ class _$PaymentSheetShapeImpl implements _PaymentSheetShape { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetShapeImpl && @@ -3169,7 +3169,7 @@ class _$PaymentSheetShadowParamsImpl implements _PaymentSheetShadowParams { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetShadowParamsImpl && @@ -3348,7 +3348,7 @@ class _$PaymentSheetShadowOffsetImpl implements _PaymentSheetShadowOffset { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetShadowOffsetImpl && @@ -3563,7 +3563,7 @@ class _$PaymentSheetPrimaryButtonAppearanceImpl } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetPrimaryButtonAppearanceImpl && @@ -3784,7 +3784,7 @@ class _$PaymentSheetPrimaryButtonShapeImpl } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetPrimaryButtonShapeImpl && @@ -4010,7 +4010,7 @@ class _$PaymentSheetPrimaryButtonThemeImpl } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetPrimaryButtonThemeImpl && @@ -4229,7 +4229,7 @@ class _$PaymentSheetPrimaryButtonThemeColorsImpl } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetPrimaryButtonThemeColorsImpl && @@ -4430,7 +4430,7 @@ class _$PresentParametersImpl implements _PresentParameters { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PresentParametersImpl && @@ -4600,7 +4600,7 @@ class _$PaymentSheetPresentOptionsImpl implements _PaymentSheetPresentOptions { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetPresentOptionsImpl && @@ -4769,7 +4769,7 @@ class _$PaymentSheetPaymentOptionImpl implements _PaymentSheetPaymentOption { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetPaymentOptionImpl && @@ -5031,7 +5031,7 @@ class _$BillingDetailsCollectionConfigurationImpl } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$BillingDetailsCollectionConfigurationImpl && diff --git a/packages/stripe_platform_interface/lib/src/models/payment_sheet.g.dart b/packages/stripe_platform_interface/lib/src/models/payment_sheet.g.dart index 3065a04c9..887c27c43 100644 --- a/packages/stripe_platform_interface/lib/src/models/payment_sheet.g.dart +++ b/packages/stripe_platform_interface/lib/src/models/payment_sheet.g.dart @@ -123,20 +123,30 @@ Map _$$IntentConfigurationImplToJson( _$IntentModeImpl _$$IntentModeImplFromJson(Map json) => _$IntentModeImpl( currencyCode: json['currencyCode'] as String, - amount: json['amount'] as int, + amount: (json['amount'] as num).toInt(), setupFutureUsage: $enumDecodeNullable( _$IntentFutureUsageEnumMap, json['setupFutureUsage']), captureMethod: $enumDecodeNullable(_$CaptureMethodEnumMap, json['captureMethod']), ); -Map _$$IntentModeImplToJson(_$IntentModeImpl instance) => - { - 'currencyCode': instance.currencyCode, - 'amount': instance.amount, - 'setupFutureUsage': _$IntentFutureUsageEnumMap[instance.setupFutureUsage], - 'captureMethod': _$CaptureMethodEnumMap[instance.captureMethod], - }; +Map _$$IntentModeImplToJson(_$IntentModeImpl instance) { + final val = { + 'currencyCode': instance.currencyCode, + 'amount': instance.amount, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('setupFutureUsage', + _$IntentFutureUsageEnumMap[instance.setupFutureUsage]); + writeNotNull('captureMethod', _$CaptureMethodEnumMap[instance.captureMethod]); + return val; +} const _$IntentFutureUsageEnumMap = { IntentFutureUsage.OffSession: 'OffSession', @@ -422,7 +432,7 @@ Map _$$PresentParametersImplToJson( _$PaymentSheetPresentOptionsImpl _$$PaymentSheetPresentOptionsImplFromJson( Map json) => _$PaymentSheetPresentOptionsImpl( - timeout: json['timeout'] as int?, + timeout: (json['timeout'] as num?)?.toInt(), ); Map _$$PaymentSheetPresentOptionsImplToJson(