From c657c2e628efae66c1a2c2c46f69623f7b69103d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mon?= Date: Wed, 24 Jul 2024 20:56:31 +0100 Subject: [PATCH] Bugfixes july (#1858) * BREAKING: min sdk is dart 3.0 * BREAKING: fix #1853 deferred payment for setupintent --------- Co-authored-by: Remon --- .../payment_sheet_deffered_screen.dart | 155 +++++- example/pubspec.yaml | 2 +- .../lib/src/widgets/card_form_field.dart | 2 +- packages/stripe/pubspec.yaml | 2 +- packages/stripe_android/pubspec.yaml | 2 +- packages/stripe_ios/pubspec.yaml | 2 +- packages/stripe_js/pubspec.yaml | 2 +- .../lib/src/card_edit_controller.dart | 2 +- .../lib/src/models/errors.dart | 4 +- .../src/models/payment_methods.freezed.dart | 6 +- .../lib/src/models/payment_sheet.dart | 16 +- .../lib/src/models/payment_sheet.freezed.dart | 447 +++++++++++++++--- .../lib/src/models/payment_sheet.g.dart | 28 +- .../stripe_platform_interface/pubspec.yaml | 2 +- packages/stripe_web/pubspec.yaml | 2 +- pubspec.yaml | 2 +- 16 files changed, 569 insertions(+), 107 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 7425c8ab3..96e93121b 100644 --- a/example/lib/screens/payment_sheet/payment_sheet_deffered_screen.dart +++ b/example/lib/screens/payment_sheet/payment_sheet_deffered_screen.dart @@ -15,6 +15,7 @@ class PaymentSheetDefferedScreen extends StatefulWidget { class _PaymentSheetScreenState extends State { int step = 0; + _PaymentMode? mode = null; @override Widget build(BuildContext context) { @@ -27,10 +28,42 @@ class _PaymentSheetScreenState extends State { currentStep: step, steps: [ Step( - title: Text('Init payment'), + title: Text('Select mode'), + content: Column( + children: [ + LoadingButton( + onPressed: () async { + setState(() { + mode = _PaymentMode.paymentIntent; + step = 1; + }); + }, + text: 'PaymentIntent', + ), + SizedBox(width: 32), + LoadingButton( + onPressed: () async { + setState(() { + mode = _PaymentMode.setupIntent; + step = 1; + }); + }, + text: 'Setup intent', + ), + ], + ), + ), + Step( + title: Text('Init paymentsheet'), content: LoadingButton( - onPressed: initPaymentSheet, - text: 'Init payment sheet', + onPressed: () async { + if (mode == _PaymentMode.paymentIntent) { + await initPaymentSheetPaymentMode(); + } else { + await initPaymentSheetSetupMode(); + } + }, + text: 'Init payment sheet for ${mode?.name}', ), ), Step( @@ -46,7 +79,8 @@ class _PaymentSheetScreenState extends State { ); } - Future _createIntentAndConfirmToUser(String paymentMethodId) async { + Future _createPaymentIntentAndConfirmToUser( + String paymentMethodId) async { final url = Uri.parse('$kApiUrl/payment-intent-for-payment-sheet'); final response = await http.post( url, @@ -62,12 +96,32 @@ class _PaymentSheetScreenState extends State { throw Exception(body['error']); } + await Stripe.instance.intentCreationCallback( + IntentCreationCallbackParams(clientSecret: body['clientSecret'])); + } + + Future _createSetupIntentAndConfirmToUser( + String paymentMethodId) async { + final url = Uri.parse('$kApiUrl/create-setup-intent'); + final response = await http.post( + url, + headers: { + 'Content-Type': 'application/json', + }, + body: json.encode({ + 'paymentMethodId': paymentMethodId, + }), + ); + final body = json.decode(response.body); + if (body['error'] != null) { + throw Exception(body['error']); + } await Stripe.instance.intentCreationCallback( IntentCreationCallbackParams(clientSecret: body['clientSecret'])); } - Future initPaymentSheet() async { + Future initPaymentSheetPaymentMode() async { try { // // 1. create payment intent on the server // final data = await _createTestPaymentSheet(); @@ -91,15 +145,96 @@ class _PaymentSheetScreenState extends State { await Stripe.instance.initPaymentSheet( paymentSheetParameters: SetupPaymentSheetParameters( // Main params - returnURL: 'flutterstripe://stripe-redirect"', + returnURL: 'flutterstripe://redirect', merchantDisplayName: 'Flutter Stripe Store Demo', intentConfiguration: IntentConfiguration( - mode: IntentMode( + mode: IntentMode.paymentMode( currencyCode: 'USD', amount: 1500, ), confirmHandler: (method, saveFuture) { - _createIntentAndConfirmToUser(method.id); + _createPaymentIntentAndConfirmToUser(method.id); + }), + + // Extra params + primaryButtonLabel: 'Pay now', + applePay: PaymentSheetApplePay( + merchantCountryCode: 'DE', + ), + googlePay: PaymentSheetGooglePay( + merchantCountryCode: 'DE', + testEnv: true, + ), + + style: ThemeMode.dark, + appearance: PaymentSheetAppearance( + colors: PaymentSheetAppearanceColors( + background: Colors.lightBlue, + primary: Colors.blue, + componentBorder: Colors.red, + ), + shapes: PaymentSheetShape( + borderWidth: 4, + shadow: PaymentSheetShadowParams(color: Colors.red), + ), + primaryButton: PaymentSheetPrimaryButtonAppearance( + shapes: PaymentSheetPrimaryButtonShape(blurRadius: 8), + colors: PaymentSheetPrimaryButtonTheme( + light: PaymentSheetPrimaryButtonThemeColors( + background: Color.fromARGB(255, 231, 235, 30), + text: Color.fromARGB(255, 235, 92, 30), + border: Color.fromARGB(255, 235, 92, 30), + ), + ), + ), + ), + billingDetails: billingDetails, + ), + ); + setState(() { + step = 2; + }); + } catch (e) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Error: $e')), + ); + rethrow; + } + } + + Future initPaymentSheetSetupMode() async { + try { + // // 1. create payment intent on the server + // final data = await _createTestPaymentSheet(); + + // create some billingdetails + final billingDetails = BillingDetails( + name: 'Flutter Stripe', + email: 'email@stripe.com', + phone: '+48888000888', + address: Address( + city: 'Houston', + country: 'US', + line1: '1459 Circle Drive', + line2: '', + state: 'Texas', + postalCode: '77063', + ), + ); // mocked data for tests + + // 2. initialize the payment sheet + await Stripe.instance.initPaymentSheet( + paymentSheetParameters: SetupPaymentSheetParameters( + // Main params + returnURL: 'flutterstripe://flutterstripe://redirect', + merchantDisplayName: 'Flutter Stripe Store Demo', + intentConfiguration: IntentConfiguration( + mode: IntentMode.setupMode( + currencyCode: 'USD', + setupFutureUsage: IntentFutureUsage.OffSession, + ), + confirmHandler: (method, saveFuture) { + _createSetupIntentAndConfirmToUser(method.id); }), // Extra params @@ -138,7 +273,7 @@ class _PaymentSheetScreenState extends State { ), ); setState(() { - step = 1; + step = 2; }); } catch (e) { ScaffoldMessenger.of(context).showSnackBar( @@ -179,3 +314,5 @@ class _PaymentSheetScreenState extends State { } } } + +enum _PaymentMode { paymentIntent, setupIntent } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index bd4a49cf7..c3fd3d081 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -4,7 +4,7 @@ version: 1.0.0 publish_to: 'none' environment: - sdk: ">=2.17.0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" flutter: ">=3.0.0" dependencies: diff --git a/packages/stripe/lib/src/widgets/card_form_field.dart b/packages/stripe/lib/src/widgets/card_form_field.dart index 0f60ba0fc..268485037 100644 --- a/packages/stripe/lib/src/widgets/card_form_field.dart +++ b/packages/stripe/lib/src/widgets/card_form_field.dart @@ -98,7 +98,7 @@ class CardFormField extends StatefulWidget { _CardFormFieldState createState() => _CardFormFieldState(); } -abstract class CardFormFieldContext { +mixin CardFormFieldContext { void focus(); void blur(); diff --git a/packages/stripe/pubspec.yaml b/packages/stripe/pubspec.yaml index 30e1bd3e2..c014bb7d5 100644 --- a/packages/stripe/pubspec.yaml +++ b/packages/stripe/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://github.com/flutter-stripe/flutter_stripe repository: https://github.com/flutter-stripe/flutter_stripe environment: - sdk: ">=2.17.0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" flutter: ">=3.0.0" flutter: diff --git a/packages/stripe_android/pubspec.yaml b/packages/stripe_android/pubspec.yaml index 28d370ca3..ec4dc5503 100644 --- a/packages/stripe_android/pubspec.yaml +++ b/packages/stripe_android/pubspec.yaml @@ -5,7 +5,7 @@ repository: https://github.com/flutter-stripe/flutter_stripe homepage: https://pub.dev/packages/flutter_stripe environment: - sdk: ">=2.12.0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" flutter: ">=3.0.0" dependencies: diff --git a/packages/stripe_ios/pubspec.yaml b/packages/stripe_ios/pubspec.yaml index b64bdc5a0..5fe96258b 100644 --- a/packages/stripe_ios/pubspec.yaml +++ b/packages/stripe_ios/pubspec.yaml @@ -5,7 +5,7 @@ repository: https://github.com/flutter-stripe/flutter_stripe homepage: https://pub.dev/packages/flutter_stripe environment: - sdk: ">=2.12.0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" flutter: ">=3.0.0" dependencies: diff --git a/packages/stripe_js/pubspec.yaml b/packages/stripe_js/pubspec.yaml index 3d9cd3462..d84fc3ff3 100644 --- a/packages/stripe_js/pubspec.yaml +++ b/packages/stripe_js/pubspec.yaml @@ -4,7 +4,7 @@ version: 3.4.0 homepage: https://github.com/flutter-stripe/flutter_stripe environment: - sdk: ">=2.17.0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: freezed_annotation: ^2.2.0 diff --git a/packages/stripe_platform_interface/lib/src/card_edit_controller.dart b/packages/stripe_platform_interface/lib/src/card_edit_controller.dart index 8423084d2..4cbaf90b2 100644 --- a/packages/stripe_platform_interface/lib/src/card_edit_controller.dart +++ b/packages/stripe_platform_interface/lib/src/card_edit_controller.dart @@ -11,7 +11,7 @@ const String kDebugPCIMessage = typedef CardChangedCallback = void Function(CardFieldInputDetails? details); typedef CardFocusCallback = void Function(CardFieldName? focusedField); -abstract class CardFieldContext { +mixin CardFieldContext { void focus(); void blur(); void clear(); diff --git a/packages/stripe_platform_interface/lib/src/models/errors.dart b/packages/stripe_platform_interface/lib/src/models/errors.dart index ad894e0c5..a75217a06 100644 --- a/packages/stripe_platform_interface/lib/src/models/errors.dart +++ b/packages/stripe_platform_interface/lib/src/models/errors.dart @@ -15,7 +15,7 @@ enum CustomerSheetError { unknown, failed, canceled } @freezed /// Wrapper class that represents an error with the Stripe platform. -class StripeError with _$StripeError, Exception { +class StripeError with _$StripeError implements Exception { @JsonSerializable(explicitToJson: true) const factory StripeError({ @Default('Unknown error') String message, @@ -34,7 +34,7 @@ Map _dataToJson(T input) => {'code': input}; @freezed /// Exception retrieved from the Stripe platform. -class StripeException with _$StripeException, Exception { +class StripeException with _$StripeException implements Exception { const factory StripeException({ /// error details required LocalizedErrorMessage error, diff --git a/packages/stripe_platform_interface/lib/src/models/payment_methods.freezed.dart b/packages/stripe_platform_interface/lib/src/models/payment_methods.freezed.dart index 31bd65c9d..6ae7a85a1 100644 --- a/packages/stripe_platform_interface/lib/src/models/payment_methods.freezed.dart +++ b/packages/stripe_platform_interface/lib/src/models/payment_methods.freezed.dart @@ -64,7 +64,7 @@ mixin _$PaymentMethod { @JsonKey(name: 'Upi') Upi get upi => throw _privateConstructorUsedError; - /// Containing additional data in case paymentmethod type is UPI. + /// Containing additional data in case paymentmethod type is Us bank account. @JsonKey(name: 'USBankAccount') UsBankAccount get usBankAccount => throw _privateConstructorUsedError; @@ -492,7 +492,7 @@ class _$PaymentMethodImpl implements _PaymentMethod { @JsonKey(name: 'Upi') final Upi upi; - /// Containing additional data in case paymentmethod type is UPI. + /// Containing additional data in case paymentmethod type is Us bank account. @override @JsonKey(name: 'USBankAccount') final UsBankAccount usBankAccount; @@ -647,7 +647,7 @@ abstract class _PaymentMethod implements PaymentMethod { Upi get upi; @override - /// Containing additional data in case paymentmethod type is UPI. + /// Containing additional data in case paymentmethod type is Us bank account. @JsonKey(name: 'USBankAccount') UsBankAccount get usBankAccount; @override 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 76fdcaff1..e997ac223 100644 --- a/packages/stripe_platform_interface/lib/src/models/payment_sheet.dart +++ b/packages/stripe_platform_interface/lib/src/models/payment_sheet.dart @@ -137,9 +137,9 @@ class IntentConfiguration with _$IntentConfiguration { } @freezed -class IntentMode with _$IntentMode { - @JsonSerializable(explicitToJson: true,includeIfNull: false) - const factory IntentMode({ +sealed class IntentMode with _$IntentMode { + @JsonSerializable(explicitToJson: true, includeIfNull: false) + const factory IntentMode.paymentMode({ required String currencyCode, required int amount, @@ -148,7 +148,15 @@ class IntentMode with _$IntentMode { /// Capture method for the future payment intent CaptureMethod? captureMethod, - }) = _IntentMode; + }) = _PaymentMode; + + @JsonSerializable(explicitToJson: true) + const factory IntentMode.setupMode({ + String? currencyCode, + + /// Data related to the future payment intent + required IntentFutureUsage setupFutureUsage, + }) = _SetupMode; factory IntentMode.fromJson(Map json) => _$IntentModeFromJson(json); 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 1c2870aaf..2d1186966 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#adding-getters-and-methods-to-our-models'); + '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'); SetupPaymentSheetParameters _$SetupPaymentSheetParametersFromJson( Map json) { @@ -711,7 +711,7 @@ class _$SetupParametersImpl implements _SetupParameters { } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$SetupParametersImpl && @@ -1130,7 +1130,7 @@ class _$IntentConfigurationImpl implements _IntentConfiguration { } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$IntentConfigurationImpl && @@ -1194,20 +1194,72 @@ abstract class _IntentConfiguration implements IntentConfiguration { } IntentMode _$IntentModeFromJson(Map json) { - return _IntentMode.fromJson(json); + switch (json['runtimeType']) { + case 'paymentMode': + return _PaymentMode.fromJson(json); + case 'setupMode': + return _SetupMode.fromJson(json); + + default: + throw CheckedFromJsonException(json, 'runtimeType', 'IntentMode', + 'Invalid union type "${json['runtimeType']}"!'); + } } /// @nodoc mixin _$IntentMode { - String get currencyCode => throw _privateConstructorUsedError; - int get amount => throw _privateConstructorUsedError; + String? get currencyCode => throw _privateConstructorUsedError; /// Data related to the future payment intent IntentFutureUsage? get setupFutureUsage => throw _privateConstructorUsedError; - - /// Capture method for the future payment intent - CaptureMethod? get captureMethod => throw _privateConstructorUsedError; - + @optionalTypeArgs + TResult when({ + required TResult Function(String currencyCode, int amount, + IntentFutureUsage? setupFutureUsage, CaptureMethod? captureMethod) + paymentMode, + required TResult Function( + String? currencyCode, IntentFutureUsage setupFutureUsage) + setupMode, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String currencyCode, int amount, + IntentFutureUsage? setupFutureUsage, CaptureMethod? captureMethod)? + paymentMode, + TResult? Function(String? currencyCode, IntentFutureUsage setupFutureUsage)? + setupMode, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String currencyCode, int amount, + IntentFutureUsage? setupFutureUsage, CaptureMethod? captureMethod)? + paymentMode, + TResult Function(String? currencyCode, IntentFutureUsage setupFutureUsage)? + setupMode, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_PaymentMode value) paymentMode, + required TResult Function(_SetupMode value) setupMode, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_PaymentMode value)? paymentMode, + TResult? Function(_SetupMode value)? setupMode, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_PaymentMode value)? paymentMode, + TResult Function(_SetupMode value)? setupMode, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) $IntentModeCopyWith get copyWith => @@ -1220,11 +1272,7 @@ abstract class $IntentModeCopyWith<$Res> { IntentMode value, $Res Function(IntentMode) then) = _$IntentModeCopyWithImpl<$Res, IntentMode>; @useResult - $Res call( - {String currencyCode, - int amount, - IntentFutureUsage? setupFutureUsage, - CaptureMethod? captureMethod}); + $Res call({String currencyCode, IntentFutureUsage setupFutureUsage}); } /// @nodoc @@ -1241,37 +1289,27 @@ class _$IntentModeCopyWithImpl<$Res, $Val extends IntentMode> @override $Res call({ Object? currencyCode = null, - Object? amount = null, - Object? setupFutureUsage = freezed, - Object? captureMethod = freezed, + Object? setupFutureUsage = null, }) { return _then(_value.copyWith( currencyCode: null == currencyCode - ? _value.currencyCode + ? _value.currencyCode! : currencyCode // ignore: cast_nullable_to_non_nullable as String, - amount: null == amount - ? _value.amount - : amount // ignore: cast_nullable_to_non_nullable - as int, - setupFutureUsage: freezed == setupFutureUsage - ? _value.setupFutureUsage + setupFutureUsage: null == setupFutureUsage + ? _value.setupFutureUsage! : setupFutureUsage // ignore: cast_nullable_to_non_nullable - as IntentFutureUsage?, - captureMethod: freezed == captureMethod - ? _value.captureMethod - : captureMethod // ignore: cast_nullable_to_non_nullable - as CaptureMethod?, + as IntentFutureUsage, ) as $Val); } } /// @nodoc -abstract class _$$IntentModeImplCopyWith<$Res> +abstract class _$$PaymentModeImplCopyWith<$Res> implements $IntentModeCopyWith<$Res> { - factory _$$IntentModeImplCopyWith( - _$IntentModeImpl value, $Res Function(_$IntentModeImpl) then) = - __$$IntentModeImplCopyWithImpl<$Res>; + factory _$$PaymentModeImplCopyWith( + _$PaymentModeImpl value, $Res Function(_$PaymentModeImpl) then) = + __$$PaymentModeImplCopyWithImpl<$Res>; @override @useResult $Res call( @@ -1282,11 +1320,11 @@ abstract class _$$IntentModeImplCopyWith<$Res> } /// @nodoc -class __$$IntentModeImplCopyWithImpl<$Res> - extends _$IntentModeCopyWithImpl<$Res, _$IntentModeImpl> - implements _$$IntentModeImplCopyWith<$Res> { - __$$IntentModeImplCopyWithImpl( - _$IntentModeImpl _value, $Res Function(_$IntentModeImpl) _then) +class __$$PaymentModeImplCopyWithImpl<$Res> + extends _$IntentModeCopyWithImpl<$Res, _$PaymentModeImpl> + implements _$$PaymentModeImplCopyWith<$Res> { + __$$PaymentModeImplCopyWithImpl( + _$PaymentModeImpl _value, $Res Function(_$PaymentModeImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -1297,7 +1335,7 @@ class __$$IntentModeImplCopyWithImpl<$Res> Object? setupFutureUsage = freezed, Object? captureMethod = freezed, }) { - return _then(_$IntentModeImpl( + return _then(_$PaymentModeImpl( currencyCode: null == currencyCode ? _value.currencyCode : currencyCode // ignore: cast_nullable_to_non_nullable @@ -1321,15 +1359,17 @@ class __$$IntentModeImplCopyWithImpl<$Res> /// @nodoc @JsonSerializable(explicitToJson: true, includeIfNull: false) -class _$IntentModeImpl implements _IntentMode { - const _$IntentModeImpl( +class _$PaymentModeImpl implements _PaymentMode { + const _$PaymentModeImpl( {required this.currencyCode, required this.amount, this.setupFutureUsage, - this.captureMethod}); + this.captureMethod, + final String? $type}) + : $type = $type ?? 'paymentMode'; - factory _$IntentModeImpl.fromJson(Map json) => - _$$IntentModeImplFromJson(json); + factory _$PaymentModeImpl.fromJson(Map json) => + _$$PaymentModeImplFromJson(json); @override final String currencyCode; @@ -1344,16 +1384,19 @@ class _$IntentModeImpl implements _IntentMode { @override final CaptureMethod? captureMethod; + @JsonKey(name: 'runtimeType') + final String $type; + @override String toString() { - return 'IntentMode(currencyCode: $currencyCode, amount: $amount, setupFutureUsage: $setupFutureUsage, captureMethod: $captureMethod)'; + return 'IntentMode.paymentMode(currencyCode: $currencyCode, amount: $amount, setupFutureUsage: $setupFutureUsage, captureMethod: $captureMethod)'; } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$IntentModeImpl && + other is _$PaymentModeImpl && (identical(other.currencyCode, currencyCode) || other.currencyCode == currencyCode) && (identical(other.amount, amount) || other.amount == amount) && @@ -1371,42 +1414,298 @@ class _$IntentModeImpl implements _IntentMode { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$IntentModeImplCopyWith<_$IntentModeImpl> get copyWith => - __$$IntentModeImplCopyWithImpl<_$IntentModeImpl>(this, _$identity); + _$$PaymentModeImplCopyWith<_$PaymentModeImpl> get copyWith => + __$$PaymentModeImplCopyWithImpl<_$PaymentModeImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String currencyCode, int amount, + IntentFutureUsage? setupFutureUsage, CaptureMethod? captureMethod) + paymentMode, + required TResult Function( + String? currencyCode, IntentFutureUsage setupFutureUsage) + setupMode, + }) { + return paymentMode(currencyCode, amount, setupFutureUsage, captureMethod); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String currencyCode, int amount, + IntentFutureUsage? setupFutureUsage, CaptureMethod? captureMethod)? + paymentMode, + TResult? Function(String? currencyCode, IntentFutureUsage setupFutureUsage)? + setupMode, + }) { + return paymentMode?.call( + currencyCode, amount, setupFutureUsage, captureMethod); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String currencyCode, int amount, + IntentFutureUsage? setupFutureUsage, CaptureMethod? captureMethod)? + paymentMode, + TResult Function(String? currencyCode, IntentFutureUsage setupFutureUsage)? + setupMode, + required TResult orElse(), + }) { + if (paymentMode != null) { + return paymentMode(currencyCode, amount, setupFutureUsage, captureMethod); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_PaymentMode value) paymentMode, + required TResult Function(_SetupMode value) setupMode, + }) { + return paymentMode(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_PaymentMode value)? paymentMode, + TResult? Function(_SetupMode value)? setupMode, + }) { + return paymentMode?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_PaymentMode value)? paymentMode, + TResult Function(_SetupMode value)? setupMode, + required TResult orElse(), + }) { + if (paymentMode != null) { + return paymentMode(this); + } + return orElse(); + } @override Map toJson() { - return _$$IntentModeImplToJson( + return _$$PaymentModeImplToJson( this, ); } } -abstract class _IntentMode implements IntentMode { - const factory _IntentMode( +abstract class _PaymentMode implements IntentMode { + const factory _PaymentMode( {required final String currencyCode, required final int amount, final IntentFutureUsage? setupFutureUsage, - final CaptureMethod? captureMethod}) = _$IntentModeImpl; + final CaptureMethod? captureMethod}) = _$PaymentModeImpl; - factory _IntentMode.fromJson(Map json) = - _$IntentModeImpl.fromJson; + factory _PaymentMode.fromJson(Map json) = + _$PaymentModeImpl.fromJson; @override String get currencyCode; - @override int get amount; @override /// Data related to the future payment intent IntentFutureUsage? get setupFutureUsage; - @override /// Capture method for the future payment intent CaptureMethod? get captureMethod; @override @JsonKey(ignore: true) - _$$IntentModeImplCopyWith<_$IntentModeImpl> get copyWith => + _$$PaymentModeImplCopyWith<_$PaymentModeImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$SetupModeImplCopyWith<$Res> + implements $IntentModeCopyWith<$Res> { + factory _$$SetupModeImplCopyWith( + _$SetupModeImpl value, $Res Function(_$SetupModeImpl) then) = + __$$SetupModeImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String? currencyCode, IntentFutureUsage setupFutureUsage}); +} + +/// @nodoc +class __$$SetupModeImplCopyWithImpl<$Res> + extends _$IntentModeCopyWithImpl<$Res, _$SetupModeImpl> + implements _$$SetupModeImplCopyWith<$Res> { + __$$SetupModeImplCopyWithImpl( + _$SetupModeImpl _value, $Res Function(_$SetupModeImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? currencyCode = freezed, + Object? setupFutureUsage = null, + }) { + return _then(_$SetupModeImpl( + currencyCode: freezed == currencyCode + ? _value.currencyCode + : currencyCode // ignore: cast_nullable_to_non_nullable + as String?, + setupFutureUsage: null == setupFutureUsage + ? _value.setupFutureUsage + : setupFutureUsage // ignore: cast_nullable_to_non_nullable + as IntentFutureUsage, + )); + } +} + +/// @nodoc + +@JsonSerializable(explicitToJson: true) +class _$SetupModeImpl implements _SetupMode { + const _$SetupModeImpl( + {this.currencyCode, required this.setupFutureUsage, final String? $type}) + : $type = $type ?? 'setupMode'; + + factory _$SetupModeImpl.fromJson(Map json) => + _$$SetupModeImplFromJson(json); + + @override + final String? currencyCode; + + /// Data related to the future payment intent + @override + final IntentFutureUsage setupFutureUsage; + + @JsonKey(name: 'runtimeType') + final String $type; + + @override + String toString() { + return 'IntentMode.setupMode(currencyCode: $currencyCode, setupFutureUsage: $setupFutureUsage)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SetupModeImpl && + (identical(other.currencyCode, currencyCode) || + other.currencyCode == currencyCode) && + (identical(other.setupFutureUsage, setupFutureUsage) || + other.setupFutureUsage == setupFutureUsage)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, currencyCode, setupFutureUsage); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$SetupModeImplCopyWith<_$SetupModeImpl> get copyWith => + __$$SetupModeImplCopyWithImpl<_$SetupModeImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String currencyCode, int amount, + IntentFutureUsage? setupFutureUsage, CaptureMethod? captureMethod) + paymentMode, + required TResult Function( + String? currencyCode, IntentFutureUsage setupFutureUsage) + setupMode, + }) { + return setupMode(currencyCode, setupFutureUsage); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String currencyCode, int amount, + IntentFutureUsage? setupFutureUsage, CaptureMethod? captureMethod)? + paymentMode, + TResult? Function(String? currencyCode, IntentFutureUsage setupFutureUsage)? + setupMode, + }) { + return setupMode?.call(currencyCode, setupFutureUsage); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String currencyCode, int amount, + IntentFutureUsage? setupFutureUsage, CaptureMethod? captureMethod)? + paymentMode, + TResult Function(String? currencyCode, IntentFutureUsage setupFutureUsage)? + setupMode, + required TResult orElse(), + }) { + if (setupMode != null) { + return setupMode(currencyCode, setupFutureUsage); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_PaymentMode value) paymentMode, + required TResult Function(_SetupMode value) setupMode, + }) { + return setupMode(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_PaymentMode value)? paymentMode, + TResult? Function(_SetupMode value)? setupMode, + }) { + return setupMode?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_PaymentMode value)? paymentMode, + TResult Function(_SetupMode value)? setupMode, + required TResult orElse(), + }) { + if (setupMode != null) { + return setupMode(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$SetupModeImplToJson( + this, + ); + } +} + +abstract class _SetupMode implements IntentMode { + const factory _SetupMode( + {final String? currencyCode, + required final IntentFutureUsage setupFutureUsage}) = _$SetupModeImpl; + + factory _SetupMode.fromJson(Map json) = + _$SetupModeImpl.fromJson; + + @override + String? get currencyCode; + @override + + /// Data related to the future payment intent + IntentFutureUsage get setupFutureUsage; + @override + @JsonKey(ignore: true) + _$$SetupModeImplCopyWith<_$SetupModeImpl> get copyWith => throw _privateConstructorUsedError; } @@ -1636,7 +1935,7 @@ class _$PaymentSheetApplePayImpl implements _PaymentSheetApplePay { } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetApplePayImpl && @@ -1928,7 +2227,7 @@ class _$PaymentSheetGooglePayImpl implements _PaymentSheetGooglePay { } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetGooglePayImpl && @@ -2201,7 +2500,7 @@ class _$PaymentSheetAppearanceImpl implements _PaymentSheetAppearance { } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetAppearanceImpl && @@ -2631,7 +2930,7 @@ class _$PaymentSheetAppearanceColorsImpl } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetAppearanceColorsImpl && @@ -2941,7 +3240,7 @@ class _$PaymentSheetShapeImpl implements _PaymentSheetShape { } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetShapeImpl && @@ -3169,7 +3468,7 @@ class _$PaymentSheetShadowParamsImpl implements _PaymentSheetShadowParams { } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetShadowParamsImpl && @@ -3348,7 +3647,7 @@ class _$PaymentSheetShadowOffsetImpl implements _PaymentSheetShadowOffset { } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetShadowOffsetImpl && @@ -3563,7 +3862,7 @@ class _$PaymentSheetPrimaryButtonAppearanceImpl } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetPrimaryButtonAppearanceImpl && @@ -3784,7 +4083,7 @@ class _$PaymentSheetPrimaryButtonShapeImpl } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetPrimaryButtonShapeImpl && @@ -4010,7 +4309,7 @@ class _$PaymentSheetPrimaryButtonThemeImpl } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetPrimaryButtonThemeImpl && @@ -4229,7 +4528,7 @@ class _$PaymentSheetPrimaryButtonThemeColorsImpl } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetPrimaryButtonThemeColorsImpl && @@ -4430,7 +4729,7 @@ class _$PresentParametersImpl implements _PresentParameters { } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PresentParametersImpl && @@ -4600,7 +4899,7 @@ class _$PaymentSheetPresentOptionsImpl implements _PaymentSheetPresentOptions { } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetPresentOptionsImpl && @@ -4769,7 +5068,7 @@ class _$PaymentSheetPaymentOptionImpl implements _PaymentSheetPaymentOption { } @override - bool operator ==(Object other) { + bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PaymentSheetPaymentOptionImpl && @@ -5031,7 +5330,7 @@ class _$BillingDetailsCollectionConfigurationImpl } @override - bool operator ==(Object other) { + bool operator ==(dynamic 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 887c27c43..2ef5e69d1 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 @@ -120,17 +120,18 @@ Map _$$IntentConfigurationImplToJson( 'paymentMethodTypes': instance.paymentMethodTypes, }; -_$IntentModeImpl _$$IntentModeImplFromJson(Map json) => - _$IntentModeImpl( +_$PaymentModeImpl _$$PaymentModeImplFromJson(Map json) => + _$PaymentModeImpl( currencyCode: json['currencyCode'] as String, - amount: (json['amount'] as num).toInt(), + amount: json['amount'] as int, setupFutureUsage: $enumDecodeNullable( _$IntentFutureUsageEnumMap, json['setupFutureUsage']), captureMethod: $enumDecodeNullable(_$CaptureMethodEnumMap, json['captureMethod']), + $type: json['runtimeType'] as String?, ); -Map _$$IntentModeImplToJson(_$IntentModeImpl instance) { +Map _$$PaymentModeImplToJson(_$PaymentModeImpl instance) { final val = { 'currencyCode': instance.currencyCode, 'amount': instance.amount, @@ -145,6 +146,7 @@ Map _$$IntentModeImplToJson(_$IntentModeImpl instance) { writeNotNull('setupFutureUsage', _$IntentFutureUsageEnumMap[instance.setupFutureUsage]); writeNotNull('captureMethod', _$CaptureMethodEnumMap[instance.captureMethod]); + val['runtimeType'] = instance.$type; return val; } @@ -160,6 +162,22 @@ const _$CaptureMethodEnumMap = { CaptureMethod.Unknown: 'Unknown', }; +_$SetupModeImpl _$$SetupModeImplFromJson(Map json) => + _$SetupModeImpl( + currencyCode: json['currencyCode'] as String?, + setupFutureUsage: + $enumDecode(_$IntentFutureUsageEnumMap, json['setupFutureUsage']), + $type: json['runtimeType'] as String?, + ); + +Map _$$SetupModeImplToJson(_$SetupModeImpl instance) => + { + 'currencyCode': instance.currencyCode, + 'setupFutureUsage': + _$IntentFutureUsageEnumMap[instance.setupFutureUsage]!, + 'runtimeType': instance.$type, + }; + _$PaymentSheetApplePayImpl _$$PaymentSheetApplePayImplFromJson( Map json) => _$PaymentSheetApplePayImpl( @@ -432,7 +450,7 @@ Map _$$PresentParametersImplToJson( _$PaymentSheetPresentOptionsImpl _$$PaymentSheetPresentOptionsImplFromJson( Map json) => _$PaymentSheetPresentOptionsImpl( - timeout: (json['timeout'] as num?)?.toInt(), + timeout: json['timeout'] as int?, ); Map _$$PaymentSheetPresentOptionsImplToJson( diff --git a/packages/stripe_platform_interface/pubspec.yaml b/packages/stripe_platform_interface/pubspec.yaml index 5d23d70b7..5508fcb78 100644 --- a/packages/stripe_platform_interface/pubspec.yaml +++ b/packages/stripe_platform_interface/pubspec.yaml @@ -5,7 +5,7 @@ repository: https://github.com/flutter-stripe/flutter_stripe homepage: https://pub.dev/packages/flutter_stripe environment: - sdk: ">=2.17.0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" flutter: ">=3.0.0" dependencies: diff --git a/packages/stripe_web/pubspec.yaml b/packages/stripe_web/pubspec.yaml index aae4defad..31f5dc7aa 100644 --- a/packages/stripe_web/pubspec.yaml +++ b/packages/stripe_web/pubspec.yaml @@ -4,7 +4,7 @@ version: 5.2.0 homepage: https://github.com/flutter-stripe/flutter_stripe environment: - sdk: ">=2.17.0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" flutter: ">=3.0.0" dependencies: diff --git a/pubspec.yaml b/pubspec.yaml index 874a406f9..019607d10 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: stripe_workspace environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dev_dependencies: melos: ^3.1.0