diff --git a/packages/stripe/CHANGELOG.md b/packages/stripe/CHANGELOG.md index eecf786cb..380f8c5ab 100644 --- a/packages/stripe/CHANGELOG.md +++ b/packages/stripe/CHANGELOG.md @@ -1,3 +1,8 @@ +## 11.2.1 + +**Features** +- Add deferred payment methods for web + ## 11.2.0 **Features** diff --git a/packages/stripe/lib/src/stripe.dart b/packages/stripe/lib/src/stripe.dart index dccdd468c..bb2a9b446 100644 --- a/packages/stripe/lib/src/stripe.dart +++ b/packages/stripe/lib/src/stripe.dart @@ -141,6 +141,18 @@ class Stripe { return isSupported; } + Future availableMobilePayOptions({ + IsGooglePaySupportedParams? googlePay, + PlatformPayWebPaymentRequestCreateOptions? webPaymentRequestCreateOptions, + }) async { + await _awaitForSettings(); + + return await _platform.availableMobilePayOptions( + params: googlePay, + paymentRequestOptions: webPaymentRequestCreateOptions, + ); + } + /// Launches the relevant native wallsheet (Apple Pay on iOS and Google Pay on Android) /// in order to create a payment intent /// @@ -284,6 +296,16 @@ class Stripe { } } + Future createPaymentMethodWithElements() => + _platform.createPaymentMethodWithElements(); + + Future elementsSubmit() => _platform.elementsSubmit(); + + Future handleCardAction( + final String paymentIntentClientSecret, + ) => + _platform.handleCardAction(paymentIntentClientSecret); + /// Creates a single-use token that represents a credit card’s details. /// /// Tokens are considered legacy, use [PaymentMethod] and [PaymentIntent] @@ -696,6 +718,7 @@ class Stripe { } bool _needsSettings = true; + void markNeedsSettings() { _needsSettings = true; if (!_platform.updateSettingsLazily) { diff --git a/packages/stripe/pubspec.yaml b/packages/stripe/pubspec.yaml index a56dcfe50..a12970633 100644 --- a/packages/stripe/pubspec.yaml +++ b/packages/stripe/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_stripe description: Flutter library for Stripe. Supports PaymentSheets, Apple & Google Pay, SCA, PSD2 and much more. -version: 11.2.0 +version: 11.2.1 homepage: https://github.com/flutter-stripe/flutter_stripe repository: https://github.com/flutter-stripe/flutter_stripe @@ -24,7 +24,7 @@ dependencies: meta: ^1.8.0 stripe_android: ^11.2.0 stripe_ios: ^11.2.0 - stripe_platform_interface: ^11.2.0 + stripe_platform_interface: ^11.2.1 dev_dependencies: flutter_test: sdk: flutter diff --git a/packages/stripe_js/CHANGELOG.md b/packages/stripe_js/CHANGELOG.md index 2b86a167f..5b23af8c9 100644 --- a/packages/stripe_js/CHANGELOG.md +++ b/packages/stripe_js/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.3.0 +**Features** +- add method for deferred payment + ## 6.2.1 **Features** - Add support for any kind of payment method in setup intent with [confirmSetup] diff --git a/packages/stripe_js/lib/src/api/payment_intents/confirm_payment_options.dart b/packages/stripe_js/lib/src/api/payment_intents/confirm_payment_options.dart index ebb7132ba..ba593a203 100644 --- a/packages/stripe_js/lib/src/api/payment_intents/confirm_payment_options.dart +++ b/packages/stripe_js/lib/src/api/payment_intents/confirm_payment_options.dart @@ -1,8 +1,7 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:stripe_js/src/api/converters/js_converter.dart'; import 'package:stripe_js/stripe_api.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - part 'confirm_payment_options.freezed.dart'; part 'confirm_payment_options.g.dart'; @@ -11,6 +10,7 @@ class ConfirmPaymentOptions with _$ConfirmPaymentOptions { const factory ConfirmPaymentOptions({ /// The Elements instance that was used to create the Payment Element. @ElementsConverter() required Elements elements, + String? clientSecret, /// Parameters that will be passed on to the Stripe API. /// Refer to the Payment Intents API for a full list of parameters. diff --git a/packages/stripe_js/lib/src/api/payment_intents/confirm_payment_options.freezed.dart b/packages/stripe_js/lib/src/api/payment_intents/confirm_payment_options.freezed.dart index c32606df4..196e8c4f7 100644 --- a/packages/stripe_js/lib/src/api/payment_intents/confirm_payment_options.freezed.dart +++ b/packages/stripe_js/lib/src/api/payment_intents/confirm_payment_options.freezed.dart @@ -24,6 +24,7 @@ mixin _$ConfirmPaymentOptions { /// The Elements instance that was used to create the Payment Element. @ElementsConverter() Elements get elements => throw _privateConstructorUsedError; + String? get clientSecret => throw _privateConstructorUsedError; /// Parameters that will be passed on to the Stripe API. /// Refer to the Payment Intents API for a full list of parameters. @@ -60,6 +61,7 @@ abstract class $ConfirmPaymentOptionsCopyWith<$Res> { @useResult $Res call( {@ElementsConverter() Elements elements, + String? clientSecret, ConfirmPaymentParams confirmParams, PaymentConfirmationRedirect? redirect}); @@ -83,6 +85,7 @@ class _$ConfirmPaymentOptionsCopyWithImpl<$Res, @override $Res call({ Object? elements = null, + Object? clientSecret = freezed, Object? confirmParams = null, Object? redirect = freezed, }) { @@ -91,6 +94,10 @@ class _$ConfirmPaymentOptionsCopyWithImpl<$Res, ? _value.elements : elements // ignore: cast_nullable_to_non_nullable as Elements, + clientSecret: freezed == clientSecret + ? _value.clientSecret + : clientSecret // ignore: cast_nullable_to_non_nullable + as String?, confirmParams: null == confirmParams ? _value.confirmParams : confirmParams // ignore: cast_nullable_to_non_nullable @@ -124,6 +131,7 @@ abstract class _$$ConfirmPaymentOptionsImplCopyWith<$Res> @useResult $Res call( {@ElementsConverter() Elements elements, + String? clientSecret, ConfirmPaymentParams confirmParams, PaymentConfirmationRedirect? redirect}); @@ -146,6 +154,7 @@ class __$$ConfirmPaymentOptionsImplCopyWithImpl<$Res> @override $Res call({ Object? elements = null, + Object? clientSecret = freezed, Object? confirmParams = null, Object? redirect = freezed, }) { @@ -154,6 +163,10 @@ class __$$ConfirmPaymentOptionsImplCopyWithImpl<$Res> ? _value.elements : elements // ignore: cast_nullable_to_non_nullable as Elements, + clientSecret: freezed == clientSecret + ? _value.clientSecret + : clientSecret // ignore: cast_nullable_to_non_nullable + as String?, confirmParams: null == confirmParams ? _value.confirmParams : confirmParams // ignore: cast_nullable_to_non_nullable @@ -171,6 +184,7 @@ class __$$ConfirmPaymentOptionsImplCopyWithImpl<$Res> class _$ConfirmPaymentOptionsImpl implements _ConfirmPaymentOptions { const _$ConfirmPaymentOptionsImpl( {@ElementsConverter() required this.elements, + this.clientSecret, required this.confirmParams, this.redirect}); @@ -181,6 +195,8 @@ class _$ConfirmPaymentOptionsImpl implements _ConfirmPaymentOptions { @override @ElementsConverter() final Elements elements; + @override + final String? clientSecret; /// Parameters that will be passed on to the Stripe API. /// Refer to the Payment Intents API for a full list of parameters. @@ -202,7 +218,7 @@ class _$ConfirmPaymentOptionsImpl implements _ConfirmPaymentOptions { @override String toString() { - return 'ConfirmPaymentOptions(elements: $elements, confirmParams: $confirmParams, redirect: $redirect)'; + return 'ConfirmPaymentOptions(elements: $elements, clientSecret: $clientSecret, confirmParams: $confirmParams, redirect: $redirect)'; } @override @@ -212,6 +228,8 @@ class _$ConfirmPaymentOptionsImpl implements _ConfirmPaymentOptions { other is _$ConfirmPaymentOptionsImpl && (identical(other.elements, elements) || other.elements == elements) && + (identical(other.clientSecret, clientSecret) || + other.clientSecret == clientSecret) && (identical(other.confirmParams, confirmParams) || other.confirmParams == confirmParams) && (identical(other.redirect, redirect) || @@ -221,7 +239,7 @@ class _$ConfirmPaymentOptionsImpl implements _ConfirmPaymentOptions { @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => - Object.hash(runtimeType, elements, confirmParams, redirect); + Object.hash(runtimeType, elements, clientSecret, confirmParams, redirect); /// Create a copy of ConfirmPaymentOptions /// with the given fields replaced by the non-null parameter values. @@ -243,6 +261,7 @@ class _$ConfirmPaymentOptionsImpl implements _ConfirmPaymentOptions { abstract class _ConfirmPaymentOptions implements ConfirmPaymentOptions { const factory _ConfirmPaymentOptions( {@ElementsConverter() required final Elements elements, + final String? clientSecret, required final ConfirmPaymentParams confirmParams, final PaymentConfirmationRedirect? redirect}) = _$ConfirmPaymentOptionsImpl; @@ -254,6 +273,8 @@ abstract class _ConfirmPaymentOptions implements ConfirmPaymentOptions { @override @ElementsConverter() Elements get elements; + @override + String? get clientSecret; /// Parameters that will be passed on to the Stripe API. /// Refer to the Payment Intents API for a full list of parameters. diff --git a/packages/stripe_js/lib/src/api/payment_intents/confirm_payment_options.g.dart b/packages/stripe_js/lib/src/api/payment_intents/confirm_payment_options.g.dart index a1718bdd0..77ce119b2 100644 --- a/packages/stripe_js/lib/src/api/payment_intents/confirm_payment_options.g.dart +++ b/packages/stripe_js/lib/src/api/payment_intents/confirm_payment_options.g.dart @@ -9,6 +9,7 @@ part of 'confirm_payment_options.dart'; _$ConfirmPaymentOptionsImpl _$$ConfirmPaymentOptionsImplFromJson(Map json) => _$ConfirmPaymentOptionsImpl( elements: const ElementsConverter().fromJson(json['elements']), + clientSecret: json['clientSecret'] as String?, confirmParams: ConfirmPaymentParams.fromJson( Map.from(json['confirmParams'] as Map)), redirect: $enumDecodeNullable( @@ -26,6 +27,7 @@ Map _$$ConfirmPaymentOptionsImplToJson( } writeNotNull('elements', const ElementsConverter().toJson(instance.elements)); + writeNotNull('clientSecret', instance.clientSecret); val['confirmParams'] = instance.confirmParams.toJson(); writeNotNull( 'redirect', _$PaymentConfirmationRedirectEnumMap[instance.redirect]); diff --git a/packages/stripe_js/lib/src/api/payment_methods/create_payment_method_with_elements_data.dart b/packages/stripe_js/lib/src/api/payment_methods/create_payment_method_with_elements_data.dart new file mode 100644 index 000000000..ac47435b8 --- /dev/null +++ b/packages/stripe_js/lib/src/api/payment_methods/create_payment_method_with_elements_data.dart @@ -0,0 +1,18 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:stripe_js/src/api/converters/js_converter.dart'; +import 'package:stripe_js/src/api/elements/elements.dart'; + +part 'create_payment_method_with_elements_data.freezed.dart'; +part 'create_payment_method_with_elements_data.g.dart'; + +@freezed +class CreatePaymentMethodWithElementsData + with _$CreatePaymentMethodWithElementsData { + const factory CreatePaymentMethodWithElementsData({ + @ElementsConverter() required Elements elements, + }) = _CreatePaymentMethodWithElementsData; + + factory CreatePaymentMethodWithElementsData.fromJson( + Map json) => + _$CreatePaymentMethodWithElementsDataFromJson(json); +} diff --git a/packages/stripe_js/lib/src/api/payment_methods/create_payment_method_with_elements_data.freezed.dart b/packages/stripe_js/lib/src/api/payment_methods/create_payment_method_with_elements_data.freezed.dart new file mode 100644 index 000000000..e47af5695 --- /dev/null +++ b/packages/stripe_js/lib/src/api/payment_methods/create_payment_method_with_elements_data.freezed.dart @@ -0,0 +1,173 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'create_payment_method_with_elements_data.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +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'); + +CreatePaymentMethodWithElementsData + _$CreatePaymentMethodWithElementsDataFromJson(Map json) { + return _CreatePaymentMethodWithElementsData.fromJson(json); +} + +/// @nodoc +mixin _$CreatePaymentMethodWithElementsData { + @ElementsConverter() + Elements get elements => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $CreatePaymentMethodWithElementsDataCopyWith< + CreatePaymentMethodWithElementsData> + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $CreatePaymentMethodWithElementsDataCopyWith<$Res> { + factory $CreatePaymentMethodWithElementsDataCopyWith( + CreatePaymentMethodWithElementsData value, + $Res Function(CreatePaymentMethodWithElementsData) then) = + _$CreatePaymentMethodWithElementsDataCopyWithImpl<$Res, + CreatePaymentMethodWithElementsData>; + @useResult + $Res call({@ElementsConverter() Elements elements}); +} + +/// @nodoc +class _$CreatePaymentMethodWithElementsDataCopyWithImpl<$Res, + $Val extends CreatePaymentMethodWithElementsData> + implements $CreatePaymentMethodWithElementsDataCopyWith<$Res> { + _$CreatePaymentMethodWithElementsDataCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? elements = null, + }) { + return _then(_value.copyWith( + elements: null == elements + ? _value.elements + : elements // ignore: cast_nullable_to_non_nullable + as Elements, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$CreatePaymentMethodWithElementsDataImplCopyWith<$Res> + implements $CreatePaymentMethodWithElementsDataCopyWith<$Res> { + factory _$$CreatePaymentMethodWithElementsDataImplCopyWith( + _$CreatePaymentMethodWithElementsDataImpl value, + $Res Function(_$CreatePaymentMethodWithElementsDataImpl) then) = + __$$CreatePaymentMethodWithElementsDataImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({@ElementsConverter() Elements elements}); +} + +/// @nodoc +class __$$CreatePaymentMethodWithElementsDataImplCopyWithImpl<$Res> + extends _$CreatePaymentMethodWithElementsDataCopyWithImpl<$Res, + _$CreatePaymentMethodWithElementsDataImpl> + implements _$$CreatePaymentMethodWithElementsDataImplCopyWith<$Res> { + __$$CreatePaymentMethodWithElementsDataImplCopyWithImpl( + _$CreatePaymentMethodWithElementsDataImpl _value, + $Res Function(_$CreatePaymentMethodWithElementsDataImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? elements = null, + }) { + return _then(_$CreatePaymentMethodWithElementsDataImpl( + elements: null == elements + ? _value.elements + : elements // ignore: cast_nullable_to_non_nullable + as Elements, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$CreatePaymentMethodWithElementsDataImpl + implements _CreatePaymentMethodWithElementsData { + const _$CreatePaymentMethodWithElementsDataImpl( + {@ElementsConverter() required this.elements}); + + factory _$CreatePaymentMethodWithElementsDataImpl.fromJson( + Map json) => + _$$CreatePaymentMethodWithElementsDataImplFromJson(json); + + @override + @ElementsConverter() + final Elements elements; + + @override + String toString() { + return 'CreatePaymentMethodWithElementsData(elements: $elements)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$CreatePaymentMethodWithElementsDataImpl && + (identical(other.elements, elements) || + other.elements == elements)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, elements); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$CreatePaymentMethodWithElementsDataImplCopyWith< + _$CreatePaymentMethodWithElementsDataImpl> + get copyWith => __$$CreatePaymentMethodWithElementsDataImplCopyWithImpl< + _$CreatePaymentMethodWithElementsDataImpl>(this, _$identity); + + @override + Map toJson() { + return _$$CreatePaymentMethodWithElementsDataImplToJson( + this, + ); + } +} + +abstract class _CreatePaymentMethodWithElementsData + implements CreatePaymentMethodWithElementsData { + const factory _CreatePaymentMethodWithElementsData( + {@ElementsConverter() required final Elements elements}) = + _$CreatePaymentMethodWithElementsDataImpl; + + factory _CreatePaymentMethodWithElementsData.fromJson( + Map json) = + _$CreatePaymentMethodWithElementsDataImpl.fromJson; + + @override + @ElementsConverter() + Elements get elements; + @override + @JsonKey(ignore: true) + _$$CreatePaymentMethodWithElementsDataImplCopyWith< + _$CreatePaymentMethodWithElementsDataImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/packages/stripe_js/lib/src/api/payment_methods/create_payment_method_with_elements_data.g.dart b/packages/stripe_js/lib/src/api/payment_methods/create_payment_method_with_elements_data.g.dart new file mode 100644 index 000000000..d560d807a --- /dev/null +++ b/packages/stripe_js/lib/src/api/payment_methods/create_payment_method_with_elements_data.g.dart @@ -0,0 +1,27 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'create_payment_method_with_elements_data.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$CreatePaymentMethodWithElementsDataImpl + _$$CreatePaymentMethodWithElementsDataImplFromJson(Map json) => + _$CreatePaymentMethodWithElementsDataImpl( + elements: const ElementsConverter().fromJson(json['elements']), + ); + +Map _$$CreatePaymentMethodWithElementsDataImplToJson( + _$CreatePaymentMethodWithElementsDataImpl instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('elements', const ElementsConverter().toJson(instance.elements)); + return val; +} diff --git a/packages/stripe_js/lib/src/api/payment_methods/payment_method.dart b/packages/stripe_js/lib/src/api/payment_methods/payment_method.dart index b40573d5e..3cd791803 100644 --- a/packages/stripe_js/lib/src/api/payment_methods/payment_method.dart +++ b/packages/stripe_js/lib/src/api/payment_methods/payment_method.dart @@ -78,6 +78,7 @@ class PaymentMethod with _$PaymentMethod { /// An additional hash is included on the PaymentMethod with a name /// matching this value. /// It contains additional information specific to the PaymentMethod type. + @JsonKey(unknownEnumValue: PaymentMethodType.unknown) required PaymentMethodType type, }) = _PaymentMethod; diff --git a/packages/stripe_js/lib/src/api/payment_methods/payment_method.freezed.dart b/packages/stripe_js/lib/src/api/payment_methods/payment_method.freezed.dart index 9dff56802..5413cd168 100644 --- a/packages/stripe_js/lib/src/api/payment_methods/payment_method.freezed.dart +++ b/packages/stripe_js/lib/src/api/payment_methods/payment_method.freezed.dart @@ -78,6 +78,7 @@ mixin _$PaymentMethod { /// An additional hash is included on the PaymentMethod with a name /// matching this value. /// It contains additional information specific to the PaymentMethod type. + @JsonKey(unknownEnumValue: PaymentMethodType.unknown) PaymentMethodType get type => throw _privateConstructorUsedError; /// Serializes this PaymentMethod to a JSON map. @@ -113,6 +114,7 @@ abstract class $PaymentMethodCopyWith<$Res> { Fpx? fpx, Upi? upi, UsBankAccount? usBankAccount, + @JsonKey(unknownEnumValue: PaymentMethodType.unknown) PaymentMethodType type}); $BillingDetailsCopyWith<$Res>? get billingDetails; @@ -398,6 +400,7 @@ abstract class _$$PaymentMethodImplCopyWith<$Res> Fpx? fpx, Upi? upi, UsBankAccount? usBankAccount, + @JsonKey(unknownEnumValue: PaymentMethodType.unknown) PaymentMethodType type}); @override @@ -547,7 +550,7 @@ class _$PaymentMethodImpl implements _PaymentMethod { this.fpx, this.upi, this.usBankAccount, - required this.type}) + @JsonKey(unknownEnumValue: PaymentMethodType.unknown) required this.type}) : _metadata = metadata; factory _$PaymentMethodImpl.fromJson(Map json) => @@ -640,6 +643,7 @@ class _$PaymentMethodImpl implements _PaymentMethod { /// matching this value. /// It contains additional information specific to the PaymentMethod type. @override + @JsonKey(unknownEnumValue: PaymentMethodType.unknown) final PaymentMethodType type; @override @@ -734,6 +738,7 @@ abstract class _PaymentMethod implements PaymentMethod { final Fpx? fpx, final Upi? upi, final UsBankAccount? usBankAccount, + @JsonKey(unknownEnumValue: PaymentMethodType.unknown) required final PaymentMethodType type}) = _$PaymentMethodImpl; factory _PaymentMethod.fromJson(Map json) = @@ -814,6 +819,7 @@ abstract class _PaymentMethod implements PaymentMethod { /// matching this value. /// It contains additional information specific to the PaymentMethod type. @override + @JsonKey(unknownEnumValue: PaymentMethodType.unknown) PaymentMethodType get type; /// Create a copy of PaymentMethod diff --git a/packages/stripe_js/lib/src/api/payment_methods/payment_method.g.dart b/packages/stripe_js/lib/src/api/payment_methods/payment_method.g.dart index 1658020c6..c20d85ff8 100644 --- a/packages/stripe_js/lib/src/api/payment_methods/payment_method.g.dart +++ b/packages/stripe_js/lib/src/api/payment_methods/payment_method.g.dart @@ -53,7 +53,8 @@ _$PaymentMethodImpl _$$PaymentMethodImplFromJson(Map json) => ? null : UsBankAccount.fromJson( Map.from(json['usBankAccount'] as Map)), - type: $enumDecode(_$PaymentMethodTypeEnumMap, json['type']), + type: $enumDecode(_$PaymentMethodTypeEnumMap, json['type'], + unknownValue: PaymentMethodType.unknown), ); Map _$$PaymentMethodImplToJson(_$PaymentMethodImpl instance) { diff --git a/packages/stripe_js/lib/src/api/payment_methods/payment_methods.dart b/packages/stripe_js/lib/src/api/payment_methods/payment_methods.dart index 7ef80bfd3..38af1932f 100644 --- a/packages/stripe_js/lib/src/api/payment_methods/payment_methods.dart +++ b/packages/stripe_js/lib/src/api/payment_methods/payment_methods.dart @@ -1,4 +1,5 @@ export 'create_payment_method_data.dart'; +export 'create_payment_method_with_elements_data.dart'; export 'payment_method.dart'; export 'payment_method_details.dart'; export 'payment_method_params.dart'; diff --git a/packages/stripe_js/lib/src/js/elements/element_creation_options.dart b/packages/stripe_js/lib/src/js/elements/element_creation_options.dart index ce1debc46..e30b2d5e8 100644 --- a/packages/stripe_js/lib/src/js/elements/element_creation_options.dart +++ b/packages/stripe_js/lib/src/js/elements/element_creation_options.dart @@ -8,6 +8,11 @@ extension type JsElementsCreateOptions._(JSObject o) { JSArray? fonts, String? locale, String? clientSecret, + int? amount, + String? mode, + String? currency, + JSArray? paymentMethodTypes, + String? paymentMethodCreation, JsElementAppearance? appearance, String? customerSessionClientSecret, String loader, @@ -17,6 +22,11 @@ extension type JsElementsCreateOptions._(JSObject o) { external String locale; external String clientSecret; external String customerSessionClientSecret; + external int amount; + external String mode; + external String currency; + external JSArray paymentMethodTypes; + external String paymentMethodCreation; external JsElementAppearance appearance; } diff --git a/packages/stripe_js/lib/src/js/elements/elements.dart b/packages/stripe_js/lib/src/js/elements/elements.dart index f88b0d5b5..28dff6a1d 100644 --- a/packages/stripe_js/lib/src/js/elements/elements.dart +++ b/packages/stripe_js/lib/src/js/elements/elements.dart @@ -5,4 +5,5 @@ export 'element_express_checkout/element_express_checkout.dart'; export 'element_payment.dart'; export 'element_payment_request_button.dart'; export 'elements_base.dart'; +export 'elements_submit.dart'; export 'styles.dart'; diff --git a/packages/stripe_js/lib/src/js/elements/elements_submit.dart b/packages/stripe_js/lib/src/js/elements/elements_submit.dart new file mode 100644 index 000000000..614b1d57b --- /dev/null +++ b/packages/stripe_js/lib/src/js/elements/elements_submit.dart @@ -0,0 +1,10 @@ +import 'dart:js_interop'; + +import 'package:stripe_js/stripe_js.dart'; + +extension ExtensionElementsSubmit on StripeElements { + Future submit() => _submit().toDart; + + @JS('submit') + external JSPromise _submit(); +} diff --git a/packages/stripe_js/lib/src/js/payment_intents/handle_next_action.dart b/packages/stripe_js/lib/src/js/payment_intents/handle_next_action.dart new file mode 100644 index 000000000..c80d2e128 --- /dev/null +++ b/packages/stripe_js/lib/src/js/payment_intents/handle_next_action.dart @@ -0,0 +1,24 @@ +import 'dart:js_interop'; + +import 'package:stripe_js/stripe_api.dart'; +import 'package:stripe_js/stripe_js.dart'; + +import '../utils/utils.dart'; + +extension ExtensionHandleNextAction on Stripe { + /// Use stripe.handleNextAction in the finalizing payments on the server flow + /// to finish confirmation of a PaymentIntent with the requires_action status. + /// It will throw an error if the PaymentIntent has a different status. + + /// Depending on the payment method and required action, the customer may be + /// temporarily redirected from your site and brought back to the return_url + /// parameter provided when the PaymentIntent is confirmed. + Future handleNextAction(String clientSecret) { + return _handleNextAction({'clientSecret': clientSecret}.jsify()) + .toDart + .then((response) => response.toDart); + } + + @JS('handleNextAction') + external JSPromise _handleNextAction(JSAny? clientSecret); +} diff --git a/packages/stripe_js/lib/src/js/payment_intents/payment_intents.dart b/packages/stripe_js/lib/src/js/payment_intents/payment_intents.dart index 7a2a6e8ee..a85f370ad 100644 --- a/packages/stripe_js/lib/src/js/payment_intents/payment_intents.dart +++ b/packages/stripe_js/lib/src/js/payment_intents/payment_intents.dart @@ -5,4 +5,5 @@ export 'confirm_ideal_payment.dart'; export 'confirm_payment.dart'; export 'confirm_sepa_debit_payment.dart'; export 'handle_card_action.dart'; +export 'handle_next_action.dart'; export 'retrieve_payment_intent.dart'; diff --git a/packages/stripe_js/lib/src/js/payment_methods/create_payment_method.dart b/packages/stripe_js/lib/src/js/payment_methods/create_payment_method.dart index 9ca8e1dcd..cd0c02e83 100644 --- a/packages/stripe_js/lib/src/js/payment_methods/create_payment_method.dart +++ b/packages/stripe_js/lib/src/js/payment_methods/create_payment_method.dart @@ -1,5 +1,6 @@ import 'package:stripe_js/stripe_api.dart'; import 'package:stripe_js/stripe_js.dart'; + import '../utils/utils.dart'; import 'dart:js_interop'; diff --git a/packages/stripe_js/lib/src/js/payment_methods/create_payment_method_with_elements.dart b/packages/stripe_js/lib/src/js/payment_methods/create_payment_method_with_elements.dart new file mode 100644 index 000000000..db83fb6b3 --- /dev/null +++ b/packages/stripe_js/lib/src/js/payment_methods/create_payment_method_with_elements.dart @@ -0,0 +1,30 @@ +import 'dart:js_interop'; + +import 'package:stripe_js/stripe_api.dart'; +import 'package:stripe_js/stripe_js.dart'; + +import '../utils/utils.dart'; + +extension ExtensionCreatePaymentMethodWithElements on Stripe { + /// Use stripe.createPaymentMethod to convert payment information collected by + /// elements into a PaymentMethod object that you safely pass to your server + /// to use in an API call. + + /// NOTE: In most integrations, you will not need to use this method. Instead, + ///use methods like stripe.confirmPayment, which will automatically create a + /// PaymentMethod when you confirm a PaymentIntent. + /// + /// https://docs.stripe.com/js/payment_methods/create_payment_method_elements + Future createPaymentMethodWithElements( + CreatePaymentMethodWithElementsData data, + ) { + final jsData = data.toJson().jsify(); + + return _createPaymentMethod(jsData) + .toDart + .then((response) => response.toDart); + } + + @JS('createPaymentMethod') + external JSPromise _createPaymentMethod(JSAny? data); +} diff --git a/packages/stripe_js/lib/src/js/payment_methods/payment_methods.dart b/packages/stripe_js/lib/src/js/payment_methods/payment_methods.dart index 2c942e205..41526a312 100644 --- a/packages/stripe_js/lib/src/js/payment_methods/payment_methods.dart +++ b/packages/stripe_js/lib/src/js/payment_methods/payment_methods.dart @@ -1 +1,2 @@ export 'create_payment_method.dart'; +export 'create_payment_method_with_elements.dart'; diff --git a/packages/stripe_js/pubspec.yaml b/packages/stripe_js/pubspec.yaml index f37802fd2..fa93daca6 100644 --- a/packages/stripe_js/pubspec.yaml +++ b/packages/stripe_js/pubspec.yaml @@ -1,6 +1,6 @@ name: stripe_js description: Stripe.js bindings for dart. This package is used by Stripe web so that the Stripe js sdk can be invoked directly. -version: 6.2.1 +version: 6.3.0 homepage: https://github.com/flutter-stripe/flutter_stripe environment: diff --git a/packages/stripe_platform_interface/CHANGELOG.md b/packages/stripe_platform_interface/CHANGELOG.md index 2b79cf82f..6ff5dade2 100644 --- a/packages/stripe_platform_interface/CHANGELOG.md +++ b/packages/stripe_platform_interface/CHANGELOG.md @@ -1,3 +1,8 @@ +## 11.2.1 + +**Features** +- add methods for deferred payment on web + ## 11.2.0 **Features** diff --git a/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart b/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart index ce017789f..41878abee 100644 --- a/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart +++ b/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart @@ -13,6 +13,7 @@ import 'package:stripe_platform_interface/src/models/wallet.dart'; import 'package:stripe_platform_interface/src/result_parser.dart'; import 'models/app_info.dart'; +import 'models/available_mobile_pay_options.dart'; import 'models/card_details.dart'; import 'models/errors.dart'; import 'models/payment_intents.dart'; @@ -91,6 +92,19 @@ class MethodChannelStripe extends StripePlatform { .parse(result: result!, successResultKey: 'paymentMethod'); } + @override + Future createPaymentMethodWithElements() => + throw UnimplementedError(); + + @override + Future elementsSubmit() => throw UnimplementedError(); + + @override + Future handleCardAction( + final String paymentIntentClientSecret, + ) => + throw UnimplementedError(); + @override Future confirmPayment( String paymentIntentClientSecret, @@ -417,6 +431,28 @@ class MethodChannelStripe extends StripePlatform { return isSupported ?? false; } + @override + Future availableMobilePayOptions({ + IsGooglePaySupportedParams? params, + PlatformPayWebPaymentRequestCreateOptions? paymentRequestOptions, + }) async { + final bool isSupported; + if (params == null) { + isSupported = + await _methodChannel.invokeMethod('isPlatformPaySupported', { + 'params': {}, + }); + } else { + isSupported = await _methodChannel + .invokeMethod('isPlatformPaySupported', {'params': params.toJson()}); + } + + return AvailableMobilePayOptions( + googlePay: isSupported && _platformIsAndroid, + applePay: isSupported && _platformIsIos, + ); + } + @override Future isPlatformPaySupported({ IsGooglePaySupportedParams? params, diff --git a/packages/stripe_platform_interface/lib/src/models/available_mobile_pay_options.dart b/packages/stripe_platform_interface/lib/src/models/available_mobile_pay_options.dart new file mode 100644 index 000000000..48d209897 --- /dev/null +++ b/packages/stripe_platform_interface/lib/src/models/available_mobile_pay_options.dart @@ -0,0 +1,12 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'available_mobile_pay_options.freezed.dart'; + +@freezed +class AvailableMobilePayOptions with _$AvailableMobilePayOptions { + const factory AvailableMobilePayOptions({ + @Default(false) bool googlePay, + @Default(false) bool applePay, + @Default(false) bool link, + }) = _AvailableMobilePayOptions; +} diff --git a/packages/stripe_platform_interface/lib/src/models/available_mobile_pay_options.freezed.dart b/packages/stripe_platform_interface/lib/src/models/available_mobile_pay_options.freezed.dart new file mode 100644 index 000000000..7789e8d32 --- /dev/null +++ b/packages/stripe_platform_interface/lib/src/models/available_mobile_pay_options.freezed.dart @@ -0,0 +1,178 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'available_mobile_pay_options.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +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'); + +/// @nodoc +mixin _$AvailableMobilePayOptions { + bool get googlePay => throw _privateConstructorUsedError; + bool get applePay => throw _privateConstructorUsedError; + bool get link => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $AvailableMobilePayOptionsCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $AvailableMobilePayOptionsCopyWith<$Res> { + factory $AvailableMobilePayOptionsCopyWith(AvailableMobilePayOptions value, + $Res Function(AvailableMobilePayOptions) then) = + _$AvailableMobilePayOptionsCopyWithImpl<$Res, AvailableMobilePayOptions>; + @useResult + $Res call({bool googlePay, bool applePay, bool link}); +} + +/// @nodoc +class _$AvailableMobilePayOptionsCopyWithImpl<$Res, + $Val extends AvailableMobilePayOptions> + implements $AvailableMobilePayOptionsCopyWith<$Res> { + _$AvailableMobilePayOptionsCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? googlePay = null, + Object? applePay = null, + Object? link = null, + }) { + return _then(_value.copyWith( + googlePay: null == googlePay + ? _value.googlePay + : googlePay // ignore: cast_nullable_to_non_nullable + as bool, + applePay: null == applePay + ? _value.applePay + : applePay // ignore: cast_nullable_to_non_nullable + as bool, + link: null == link + ? _value.link + : link // ignore: cast_nullable_to_non_nullable + as bool, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$AvailableMobilePayOptionsImplCopyWith<$Res> + implements $AvailableMobilePayOptionsCopyWith<$Res> { + factory _$$AvailableMobilePayOptionsImplCopyWith( + _$AvailableMobilePayOptionsImpl value, + $Res Function(_$AvailableMobilePayOptionsImpl) then) = + __$$AvailableMobilePayOptionsImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({bool googlePay, bool applePay, bool link}); +} + +/// @nodoc +class __$$AvailableMobilePayOptionsImplCopyWithImpl<$Res> + extends _$AvailableMobilePayOptionsCopyWithImpl<$Res, + _$AvailableMobilePayOptionsImpl> + implements _$$AvailableMobilePayOptionsImplCopyWith<$Res> { + __$$AvailableMobilePayOptionsImplCopyWithImpl( + _$AvailableMobilePayOptionsImpl _value, + $Res Function(_$AvailableMobilePayOptionsImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? googlePay = null, + Object? applePay = null, + Object? link = null, + }) { + return _then(_$AvailableMobilePayOptionsImpl( + googlePay: null == googlePay + ? _value.googlePay + : googlePay // ignore: cast_nullable_to_non_nullable + as bool, + applePay: null == applePay + ? _value.applePay + : applePay // ignore: cast_nullable_to_non_nullable + as bool, + link: null == link + ? _value.link + : link // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc + +class _$AvailableMobilePayOptionsImpl implements _AvailableMobilePayOptions { + const _$AvailableMobilePayOptionsImpl( + {this.googlePay = false, this.applePay = false, this.link = false}); + + @override + @JsonKey() + final bool googlePay; + @override + @JsonKey() + final bool applePay; + @override + @JsonKey() + final bool link; + + @override + String toString() { + return 'AvailableMobilePayOptions(googlePay: $googlePay, applePay: $applePay, link: $link)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$AvailableMobilePayOptionsImpl && + (identical(other.googlePay, googlePay) || + other.googlePay == googlePay) && + (identical(other.applePay, applePay) || + other.applePay == applePay) && + (identical(other.link, link) || other.link == link)); + } + + @override + int get hashCode => Object.hash(runtimeType, googlePay, applePay, link); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$AvailableMobilePayOptionsImplCopyWith<_$AvailableMobilePayOptionsImpl> + get copyWith => __$$AvailableMobilePayOptionsImplCopyWithImpl< + _$AvailableMobilePayOptionsImpl>(this, _$identity); +} + +abstract class _AvailableMobilePayOptions implements AvailableMobilePayOptions { + const factory _AvailableMobilePayOptions( + {final bool googlePay, + final bool applePay, + final bool link}) = _$AvailableMobilePayOptionsImpl; + + @override + bool get googlePay; + @override + bool get applePay; + @override + bool get link; + @override + @JsonKey(ignore: true) + _$$AvailableMobilePayOptionsImplCopyWith<_$AvailableMobilePayOptionsImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart b/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart index 6f750aae2..1c67972ff 100644 --- a/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart +++ b/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart @@ -39,9 +39,15 @@ abstract class StripePlatform extends PlatformInterface { PaymentMethodOptions? options, ]); + Future createPaymentMethodWithElements(); + Future handleNextAction(String paymentIntentClientSecret, {String? returnURL}); + Future handleCardAction( + String paymentIntentClientSecret, + ); + Future handleNextActionForSetupIntent( String setupIntentClientSecret, {String? returnURL}); @@ -102,6 +108,11 @@ abstract class StripePlatform extends PlatformInterface { Future isCardInWallet(String cardLastFour); + Future availableMobilePayOptions({ + IsGooglePaySupportedParams? params, + PlatformPayWebPaymentRequestCreateOptions? paymentRequestOptions, + }); + /// Check if either google pay or apple pay is supported on device. Future isPlatformPaySupported({ IsGooglePaySupportedParams? params, @@ -165,6 +176,8 @@ abstract class StripePlatform extends PlatformInterface { Future collectFinancialConnectionsAccounts( {required String clientSecret}); + Future elementsSubmit(); + /// Updates the internal card details. This method will not validate the card /// information so you should validate the information yourself. /// WARNING!!! Only do this if you're certain that you fulfill the necessary diff --git a/packages/stripe_platform_interface/lib/stripe_platform_interface.dart b/packages/stripe_platform_interface/lib/stripe_platform_interface.dart index 4d7d91c3e..44e68b273 100644 --- a/packages/stripe_platform_interface/lib/stripe_platform_interface.dart +++ b/packages/stripe_platform_interface/lib/stripe_platform_interface.dart @@ -6,6 +6,7 @@ export 'src/models/address.dart'; export 'src/models/app_info.dart'; export 'src/models/apple_pay.dart'; export 'src/models/aubecs_form.dart'; +export 'src/models/available_mobile_pay_options.dart'; export 'src/models/capture_method.dart'; export 'src/models/card_brand.dart'; export 'src/models/card_details.dart'; diff --git a/packages/stripe_platform_interface/pubspec.yaml b/packages/stripe_platform_interface/pubspec.yaml index 238dee57e..b110b5a95 100644 --- a/packages/stripe_platform_interface/pubspec.yaml +++ b/packages/stripe_platform_interface/pubspec.yaml @@ -1,6 +1,6 @@ name: stripe_platform_interface description: Platform interface for stripe sdk -version: 11.2.0 +version: 11.2.1 repository: https://github.com/flutter-stripe/flutter_stripe homepage: https://pub.dev/packages/flutter_stripe diff --git a/packages/stripe_web/CHANGELOG.md b/packages/stripe_web/CHANGELOG.md index 5804518e8..d5aad9b28 100644 --- a/packages/stripe_web/CHANGELOG.md +++ b/packages/stripe_web/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.2.1 + +**Features** +- add methods for deferred payments + ## 6.2.0 **Features** - Add basic support for Expresscheckout on the web diff --git a/packages/stripe_web/lib/src/web_stripe.dart b/packages/stripe_web/lib/src/web_stripe.dart index 2679d7dd9..7d940c644 100644 --- a/packages/stripe_web/lib/src/web_stripe.dart +++ b/packages/stripe_web/lib/src/web_stripe.dart @@ -1,7 +1,6 @@ //@dart=2.12 import 'dart:async'; import 'dart:developer' as dev; -import 'package:web/web.dart' as web; import 'dart:ui' as ui; import 'package:flutter/widgets.dart'; @@ -10,6 +9,7 @@ import 'package:flutter_stripe_web/platform_pay_button.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; import 'package:stripe_js/stripe_api.dart' as stripe_js; import 'package:stripe_js/stripe_js.dart' as stripe_js; +import 'package:web/web.dart' as web; import 'parser/payment_intent.dart'; import 'parser/payment_methods.dart'; @@ -270,8 +270,19 @@ class WebStripe extends StripePlatform { @override Future handleNextAction(String paymentIntentClientSecret, {String? returnURL}) async { + final stripe_js.PaymentIntentResponse response = + await _stripe.handleNextAction(paymentIntentClientSecret); + + return response.paymentIntent!.parse(); + } + + @override + Future handleCardAction( + String paymentIntentClientSecret, + ) async { final stripe_js.PaymentIntentResponse response = await _stripe.handleCardAction(paymentIntentClientSecret); + return response.paymentIntent!.parse(); } @@ -349,8 +360,11 @@ class WebStripe extends StripePlatform { } @override - Future retrievePaymentIntent(String clientSecret) async { - throw UnimplementedError(); + Future retrievePaymentIntent(final String clientSecret) async { + final stripe_js.PaymentIntentResponse response = + await _stripe.retrievePaymentIntent(clientSecret); + + return response.paymentIntent!.parse(); } @override @@ -393,11 +407,13 @@ class WebStripe extends StripePlatform { } Future confirmPaymentElement( - ConfirmPaymentElementOptions options, - ) async { + ConfirmPaymentElementOptions options, [ + String? clientSecret, + ]) async { final response = await js.confirmPayment( stripe_js.ConfirmPaymentOptions( elements: elements!, + clientSecret: clientSecret, confirmParams: options.confirmParams, redirect: options.redirect, ), @@ -409,6 +425,26 @@ class WebStripe extends StripePlatform { } } + Future elementsSubmit() => elements!.submit(); + + @override + Future createPaymentMethodWithElements() async { + try { + final response = await js.createPaymentMethodWithElements( + stripe_js.CreatePaymentMethodWithElementsData(elements: elements!), + ); + + if (response.error != null) { + throw response.error!; + } + + return response.paymentMethod!.parse(); + } catch (e) { + dev.log('Error $e'); + rethrow; + } + } + @override Widget buildCard({ Key? key, @@ -504,6 +540,24 @@ class WebStripe extends StripePlatform { throw WebUnsupportedError.method('resetPaymentSheet'); } + @override + Future availableMobilePayOptions({ + IsGooglePaySupportedParams? params, + PlatformPayWebPaymentRequestCreateOptions? paymentRequestOptions, + }) async { + final paymentRequest = js.paymentRequest((paymentRequestOptions ?? + PlatformPayWebPaymentRequestCreateOptions.defaultOptions) + .toJS()); + + final paymentOptions = await paymentRequest.canMakePayment(); + + return AvailableMobilePayOptions( + googlePay: paymentOptions?.googlePay ?? false, + applePay: paymentOptions?.applePay ?? false, + link: paymentOptions?.link ?? false, + ); + } + @override Future isPlatformPaySupported({ IsGooglePaySupportedParams? params, diff --git a/packages/stripe_web/lib/src/widgets/payment_element.dart b/packages/stripe_web/lib/src/widgets/payment_element.dart index eddbb6c28..6d7cb57d7 100644 --- a/packages/stripe_web/lib/src/widgets/payment_element.dart +++ b/packages/stripe_web/lib/src/widgets/payment_element.dart @@ -10,13 +10,27 @@ import 'package:web/web.dart' as web; import '../../flutter_stripe_web.dart'; export 'package:stripe_js/stripe_api.dart' - show PaymentElementLayout, ElementAppearance, ElementTheme; - -typedef PaymentElementTheme = js.ElementTheme; + show + ElementAppearance, + ElementTheme, + ElementAppearanceLabels, + PaymentElementLayout, + PaymentElementDefaultValues, + PaymentElementBillingDetails, + PaymentElementBillingDetailsAddress, + PaymentElementWalletOptions, + PaymentElementFieldRequired; class PaymentElement extends StatefulWidget { - final String clientSecret; + final String? clientSecret; final String? customerSessionClientSecret; + + final int? amount; + final String? currency; + final String? mode; + final String? paymentMethodCreation; + final List? paymentMethodTypes; + final double? width; final double? height; final CardStyle? style; @@ -36,11 +50,17 @@ class PaymentElement extends StatefulWidget { final js.PaymentElementOptionsTerms? terms; final js.PaymentElementWalletOptions? wallets; final js.PaymentElementApplePayOptions? applePay; + final String? locale; PaymentElement({ super.key, - required this.clientSecret, + this.clientSecret, this.customerSessionClientSecret, + this.amount, + this.currency, + this.mode, + this.paymentMethodTypes, + this.paymentMethodCreation, this.width, this.height, this.style, @@ -52,6 +72,7 @@ class PaymentElement extends StatefulWidget { required this.onCardChanged, this.layout = PaymentElementLayout.accordion, this.appearance, + this.locale, this.defaultValues, this.business, this.paymentMethodOrder, @@ -68,6 +89,7 @@ class PaymentElement extends StatefulWidget { class PaymentElementState extends State { web.HTMLDivElement _divElement = web.HTMLDivElement(); + // 2 is the first size generated by the iframe, O will not work. double height = 2.0; @@ -121,7 +143,9 @@ class PaymentElementState extends State { ..id = 'payment-element' ..style.border = 'none' ..style.width = '100%' - ..style.height = '${height}'; + ..style.height = '${height}' + ..style.overflow = 'scroll' + ..style.overflowX = 'hidden'; elements = WebStripe.js.elements(createOptions()); mutationObserver!.observe( @@ -137,9 +161,11 @@ class PaymentElementState extends State { } js.PaymentElement? get element => WebStripe.element as js.PaymentElement?; + set element(js.StripeElement? value) => WebStripe.element = value; js.StripeElements? get elements => WebStripe.elements; + set elements(js.StripeElements? value) => WebStripe.elements = value; void requestBlur(response) { @@ -160,6 +186,7 @@ class PaymentElementState extends State { } final FocusNode _focusNode = FocusNode(debugLabel: 'CardField'); + FocusNode get _effectiveNode => widget.focusNode ?? _focusNode; @override @@ -184,10 +211,27 @@ class PaymentElementState extends State { js.JsElementsCreateOptions createOptions() { final appearance = widget.appearance ?? js.ElementAppearance(); + + if (widget.clientSecret?.isNotEmpty == true) { + return js.JsElementsCreateOptions( + clientSecret: widget.clientSecret, + customerSessionClientSecret: widget.customerSessionClientSecret, + appearance: appearance.toJson().jsify() as js.JsElementAppearance, + locale: widget.locale, + ); + } + return js.JsElementsCreateOptions( - clientSecret: widget.clientSecret, - customerSessionClientSecret: widget.customerSessionClientSecret, + amount: widget.amount, + currency: widget.currency, + mode: widget.mode, + paymentMethodTypes: widget.paymentMethodTypes + ?.map((pmt) => pmt.toJS) + .toList(growable: false) + .toJS, + paymentMethodCreation: widget.paymentMethodCreation, appearance: appearance.toJson().jsify() as js.JsElementAppearance, + locale: widget.locale, ); } diff --git a/packages/stripe_web/pubspec.yaml b/packages/stripe_web/pubspec.yaml index e0b7c2a86..c5a2eaaf0 100644 --- a/packages/stripe_web/pubspec.yaml +++ b/packages/stripe_web/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_stripe_web description: Stripe sdk bindings for the Flutter web platform. This package contains the implementation of the platform interface for web. -version: 6.2.0 +version: 6.2.1 homepage: https://github.com/flutter-stripe/flutter_stripe environment: @@ -13,8 +13,8 @@ dependencies: flutter_web_plugins: sdk: flutter freezed_annotation: ^2.0.3 - stripe_platform_interface: ^11.2.0 - stripe_js: ^6.2.0 + stripe_platform_interface: ^11.2.1 + stripe_js: ^6.3.0 web: ^1.0.0 dev_dependencies: