diff --git a/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_data.dart b/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_data.dart new file mode 100644 index 000000000..34dd2afe3 --- /dev/null +++ b/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_data.dart @@ -0,0 +1,34 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:stripe_js/stripe_api.dart'; + +part 'confirm_p24_payment_data.freezed.dart'; +part 'confirm_p24_payment_data.g.dart'; + +@freezed +class ConfirmP24PaymentData with _$ConfirmP24PaymentData { + const factory ConfirmP24PaymentData({ + /// Either the ID of an existing PaymentMethod, or an object containing + /// data to create a PaymentMethod with. + /// + /// This is required to process the payment. If you already have a PaymentMethod + /// attached to the PaymentIntent, you do not need to specify this field. + /// + /// See the official Stripe documentation for additional details: + /// https://stripe.com/docs/payments/p24 + @paymentMethodDetailJsonKey P24PaymentMethodDetails? paymentMethod, + + /// The url your customer will be directed to after they complete authentication. + @JsonKey(name: "return_url") String? returnUrl, + + /// To set up a SEPA Direct Debit payment method using the bank details + /// from this P24 payment, set this parameter to off_session. + /// When using this parameter, a customer will need to be set on the + /// PaymentIntent. The newly created SEPA Direct Debit PaymentMethod + /// will be attached to this customer. + @JsonKey(name: "setup_future_usage") + PaymentIntentSetupFutureUsage? setupFutureUsage, + }) = _ConfirmP24PaymentData; + + factory ConfirmP24PaymentData.fromJson(Map json) => + _$ConfirmP24PaymentDataFromJson(json); +} diff --git a/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_data.freezed.dart b/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_data.freezed.dart new file mode 100644 index 000000000..052cd449b --- /dev/null +++ b/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_data.freezed.dart @@ -0,0 +1,285 @@ +// 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 'confirm_p24_payment_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'); + +ConfirmP24PaymentData _$ConfirmP24PaymentDataFromJson( + Map json) { + return _ConfirmP24PaymentData.fromJson(json); +} + +/// @nodoc +mixin _$ConfirmP24PaymentData { + /// Either the id of an existing PaymentMethod, or an object containing + /// data to create a PaymentMethod with. + /// See the use case sections below for details. + @paymentMethodDetailJsonKey + P24PaymentMethodDetails? get paymentMethod => + throw _privateConstructorUsedError; + + /// The url your customer will be directed to after they complete authentication. + @JsonKey(name: "return_url") + String? get returnUrl => throw _privateConstructorUsedError; + + /// To set up a SEPA Direct Debit payment method using the bank details + /// from this iDEAL payment, set this parameter to off_session. + /// When using this parameter, a customer will need to be set on the + /// PaymentIntent. The newly created SEPA Direct Debit PaymentMethod + /// will be attached to this customer. + @JsonKey(name: "setup_future_usage") + PaymentIntentSetupFutureUsage? get setupFutureUsage => + throw _privateConstructorUsedError; + + /// Serializes this ConfirmP24PaymentData to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of ConfirmP24PaymentData + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $ConfirmP24PaymentDataCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ConfirmP24PaymentDataCopyWith<$Res> { + factory $ConfirmP24PaymentDataCopyWith(ConfirmP24PaymentData value, + $Res Function(ConfirmP24PaymentData) then) = + _$ConfirmP24PaymentDataCopyWithImpl<$Res, ConfirmP24PaymentData>; + @useResult + $Res call( + {@paymentMethodDetailJsonKey P24PaymentMethodDetails? paymentMethod, + @JsonKey(name: "return_url") String? returnUrl, + @JsonKey(name: "setup_future_usage") + PaymentIntentSetupFutureUsage? setupFutureUsage}); + + $P24PaymentMethodDetailsCopyWith<$Res>? get paymentMethod; +} + +/// @nodoc +class _$ConfirmP24PaymentDataCopyWithImpl<$Res, + $Val extends ConfirmP24PaymentData> + implements $ConfirmP24PaymentDataCopyWith<$Res> { + _$ConfirmP24PaymentDataCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of ConfirmP24PaymentData + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? paymentMethod = freezed, + Object? returnUrl = freezed, + Object? setupFutureUsage = freezed, + }) { + return _then(_value.copyWith( + paymentMethod: freezed == paymentMethod + ? _value.paymentMethod + : paymentMethod // ignore: cast_nullable_to_non_nullable + as P24PaymentMethodDetails?, + returnUrl: freezed == returnUrl + ? _value.returnUrl + : returnUrl // ignore: cast_nullable_to_non_nullable + as String?, + setupFutureUsage: freezed == setupFutureUsage + ? _value.setupFutureUsage + : setupFutureUsage // ignore: cast_nullable_to_non_nullable + as PaymentIntentSetupFutureUsage?, + ) as $Val); + } + + /// Create a copy of ConfirmP24PaymentData + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $P24PaymentMethodDetailsCopyWith<$Res>? get paymentMethod { + if (_value.paymentMethod == null) { + return null; + } + + return $P24PaymentMethodDetailsCopyWith<$Res>(_value.paymentMethod!, + (value) { + return _then(_value.copyWith(paymentMethod: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$ConfirmP24PaymentDataImplCopyWith<$Res> + implements $ConfirmP24PaymentDataCopyWith<$Res> { + factory _$$ConfirmP24PaymentDataImplCopyWith( + _$ConfirmP24PaymentDataImpl value, + $Res Function(_$ConfirmP24PaymentDataImpl) then) = + __$$ConfirmP24PaymentDataImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@paymentMethodDetailJsonKey P24PaymentMethodDetails? paymentMethod, + @JsonKey(name: "return_url") String? returnUrl, + @JsonKey(name: "setup_future_usage") + PaymentIntentSetupFutureUsage? setupFutureUsage}); + + @override + $P24PaymentMethodDetailsCopyWith<$Res>? get paymentMethod; +} + +/// @nodoc +class __$$ConfirmP24PaymentDataImplCopyWithImpl<$Res> + extends _$ConfirmP24PaymentDataCopyWithImpl<$Res, + _$ConfirmP24PaymentDataImpl> + implements _$$ConfirmP24PaymentDataImplCopyWith<$Res> { + __$$ConfirmP24PaymentDataImplCopyWithImpl(_$ConfirmP24PaymentDataImpl _value, + $Res Function(_$ConfirmP24PaymentDataImpl) _then) + : super(_value, _then); + + /// Create a copy of ConfirmP24PaymentData + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? paymentMethod = freezed, + Object? returnUrl = freezed, + Object? setupFutureUsage = freezed, + }) { + return _then(_$ConfirmP24PaymentDataImpl( + paymentMethod: freezed == paymentMethod + ? _value.paymentMethod + : paymentMethod // ignore: cast_nullable_to_non_nullable + as P24PaymentMethodDetails?, + returnUrl: freezed == returnUrl + ? _value.returnUrl + : returnUrl // ignore: cast_nullable_to_non_nullable + as String?, + setupFutureUsage: freezed == setupFutureUsage + ? _value.setupFutureUsage + : setupFutureUsage // ignore: cast_nullable_to_non_nullable + as PaymentIntentSetupFutureUsage?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$ConfirmP24PaymentDataImpl implements _ConfirmP24PaymentData { + const _$ConfirmP24PaymentDataImpl( + {@paymentMethodDetailJsonKey this.paymentMethod, + @JsonKey(name: "return_url") this.returnUrl, + @JsonKey(name: "setup_future_usage") this.setupFutureUsage}); + + factory _$ConfirmP24PaymentDataImpl.fromJson(Map json) => + _$$ConfirmP24PaymentDataImplFromJson(json); + + /// Either the id of an existing PaymentMethod, or an object containing + /// data to create a PaymentMethod with. + /// See the use case sections below for details. + @override + @paymentMethodDetailJsonKey + final P24PaymentMethodDetails? paymentMethod; + + /// The url your customer will be directed to after they complete authentication. + @override + @JsonKey(name: "return_url") + final String? returnUrl; + + /// To set up a SEPA Direct Debit payment method using the bank details + /// from this iDEAL payment, set this parameter to off_session. + /// When using this parameter, a customer will need to be set on the + /// PaymentIntent. The newly created SEPA Direct Debit PaymentMethod + /// will be attached to this customer. + @override + @JsonKey(name: "setup_future_usage") + final PaymentIntentSetupFutureUsage? setupFutureUsage; + + @override + String toString() { + return 'ConfirmP24PaymentData(paymentMethod: $paymentMethod, returnUrl: $returnUrl, setupFutureUsage: $setupFutureUsage)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ConfirmP24PaymentDataImpl && + (identical(other.paymentMethod, paymentMethod) || + other.paymentMethod == paymentMethod) && + (identical(other.returnUrl, returnUrl) || + other.returnUrl == returnUrl) && + (identical(other.setupFutureUsage, setupFutureUsage) || + other.setupFutureUsage == setupFutureUsage)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => + Object.hash(runtimeType, paymentMethod, returnUrl, setupFutureUsage); + + /// Create a copy of ConfirmP24PaymentData + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ConfirmP24PaymentDataImplCopyWith<_$ConfirmP24PaymentDataImpl> + get copyWith => __$$ConfirmP24PaymentDataImplCopyWithImpl< + _$ConfirmP24PaymentDataImpl>(this, _$identity); + + @override + Map toJson() { + return _$$ConfirmP24PaymentDataImplToJson( + this, + ); + } +} + +abstract class _ConfirmP24PaymentData implements ConfirmP24PaymentData { + const factory _ConfirmP24PaymentData( + {@paymentMethodDetailJsonKey final P24PaymentMethodDetails? paymentMethod, + @JsonKey(name: "return_url") final String? returnUrl, + @JsonKey(name: "setup_future_usage") + final PaymentIntentSetupFutureUsage? + setupFutureUsage}) = _$ConfirmP24PaymentDataImpl; + + factory _ConfirmP24PaymentData.fromJson(Map json) = + _$ConfirmP24PaymentDataImpl.fromJson; + + /// Either the id of an existing PaymentMethod, or an object containing + /// data to create a PaymentMethod with. + /// See the use case sections below for details. + @override + @paymentMethodDetailJsonKey + P24PaymentMethodDetails? get paymentMethod; + + /// The url your customer will be directed to after they complete authentication. + @override + @JsonKey(name: "return_url") + String? get returnUrl; + + /// To set up a SEPA Direct Debit payment method using the bank details + /// from this iDEAL payment, set this parameter to off_session. + /// When using this parameter, a customer will need to be set on the + /// PaymentIntent. The newly created SEPA Direct Debit PaymentMethod + /// will be attached to this customer. + @override + @JsonKey(name: "setup_future_usage") + PaymentIntentSetupFutureUsage? get setupFutureUsage; + + /// Create a copy of ConfirmP24PaymentData + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ConfirmP24PaymentDataImplCopyWith<_$ConfirmP24PaymentDataImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_data.g.dart b/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_data.g.dart new file mode 100644 index 000000000..a534a9d82 --- /dev/null +++ b/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_data.g.dart @@ -0,0 +1,35 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'confirm_p24_payment_data.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$ConfirmP24PaymentDataImpl _$$ConfirmP24PaymentDataImplFromJson(Map json) => + _$ConfirmP24PaymentDataImpl( + paymentMethod: json['payment_method'] == null + ? null + : P24PaymentMethodDetails.fromJson( + Map.from(json['payment_method'] as Map)), + returnUrl: json['return_url'] as String?, + setupFutureUsage: $enumDecodeNullable( + _$PaymentIntentSetupFutureUsageEnumMap, json['setup_future_usage']), + ); + +Map _$$ConfirmP24PaymentDataImplToJson( + _$ConfirmP24PaymentDataImpl instance) => + { + if (PaymentMethodDetails.toJsonConverter(instance.paymentMethod) + case final value?) + 'payment_method': value, + if (instance.returnUrl case final value?) 'return_url': value, + if (_$PaymentIntentSetupFutureUsageEnumMap[instance.setupFutureUsage] + case final value?) + 'setup_future_usage': value, + }; + +const _$PaymentIntentSetupFutureUsageEnumMap = { + PaymentIntentSetupFutureUsage.onSession: 'on_session', + PaymentIntentSetupFutureUsage.offSession: 'off_session', +}; diff --git a/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_options.dart b/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_options.dart new file mode 100644 index 000000000..aa0106774 --- /dev/null +++ b/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_options.dart @@ -0,0 +1,16 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'confirm_p24_payment_options.freezed.dart'; +part 'confirm_p24_payment_options.g.dart'; + +@freezed +class ConfirmP24PaymentOptions with _$ConfirmP24PaymentOptions { + const factory ConfirmP24PaymentOptions({ + /// Set this to false if you want to manually handle + /// the authorization redirect. Default is true. + @Default(true) bool? handleActions, + }) = _ConfirmP24PaymentOptions; + + factory ConfirmP24PaymentOptions.fromJson(Map json) => + _$ConfirmP24PaymentOptionsFromJson(json); +} diff --git a/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_options.freezed.dart b/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_options.freezed.dart new file mode 100644 index 000000000..f3fe7e07f --- /dev/null +++ b/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_options.freezed.dart @@ -0,0 +1,179 @@ +// 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 'confirm_p24_payment_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'); + +ConfirmP24PaymentOptions _$ConfirmP24PaymentOptionsFromJson( + Map json) { + return _ConfirmP24PaymentOptions.fromJson(json); +} + +/// @nodoc +mixin _$ConfirmP24PaymentOptions { + /// Set this to false if you want to manually handle + /// the authorization redirect. Default is true. + bool? get handleActions => throw _privateConstructorUsedError; + + /// Serializes this ConfirmP24PaymentOptions to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of ConfirmP24PaymentOptions + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $ConfirmP24PaymentOptionsCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ConfirmP24PaymentOptionsCopyWith<$Res> { + factory $ConfirmP24PaymentOptionsCopyWith(ConfirmP24PaymentOptions value, + $Res Function(ConfirmP24PaymentOptions) then) = + _$ConfirmP24PaymentOptionsCopyWithImpl<$Res, ConfirmP24PaymentOptions>; + @useResult + $Res call({bool? handleActions}); +} + +/// @nodoc +class _$ConfirmP24PaymentOptionsCopyWithImpl<$Res, + $Val extends ConfirmP24PaymentOptions> + implements $ConfirmP24PaymentOptionsCopyWith<$Res> { + _$ConfirmP24PaymentOptionsCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of ConfirmP24PaymentOptions + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? handleActions = freezed, + }) { + return _then(_value.copyWith( + handleActions: freezed == handleActions + ? _value.handleActions + : handleActions // ignore: cast_nullable_to_non_nullable + as bool?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$ConfirmP24PaymentOptionsImplCopyWith<$Res> + implements $ConfirmP24PaymentOptionsCopyWith<$Res> { + factory _$$ConfirmP24PaymentOptionsImplCopyWith( + _$ConfirmP24PaymentOptionsImpl value, + $Res Function(_$ConfirmP24PaymentOptionsImpl) then) = + __$$ConfirmP24PaymentOptionsImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({bool? handleActions}); +} + +/// @nodoc +class __$$ConfirmP24PaymentOptionsImplCopyWithImpl<$Res> + extends _$ConfirmP24PaymentOptionsCopyWithImpl<$Res, + _$ConfirmP24PaymentOptionsImpl> + implements _$$ConfirmP24PaymentOptionsImplCopyWith<$Res> { + __$$ConfirmP24PaymentOptionsImplCopyWithImpl( + _$ConfirmP24PaymentOptionsImpl _value, + $Res Function(_$ConfirmP24PaymentOptionsImpl) _then) + : super(_value, _then); + + /// Create a copy of ConfirmP24PaymentOptions + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? handleActions = freezed, + }) { + return _then(_$ConfirmP24PaymentOptionsImpl( + handleActions: freezed == handleActions + ? _value.handleActions + : handleActions // ignore: cast_nullable_to_non_nullable + as bool?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$ConfirmP24PaymentOptionsImpl implements _ConfirmP24PaymentOptions { + const _$ConfirmP24PaymentOptionsImpl({this.handleActions = true}); + + factory _$ConfirmP24PaymentOptionsImpl.fromJson(Map json) => + _$$ConfirmP24PaymentOptionsImplFromJson(json); + + /// Set this to false if you want to manually handle + /// the authorization redirect. Default is true. + @override + @JsonKey() + final bool? handleActions; + + @override + String toString() { + return 'ConfirmP24PaymentOptions(handleActions: $handleActions)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ConfirmP24PaymentOptionsImpl && + (identical(other.handleActions, handleActions) || + other.handleActions == handleActions)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, handleActions); + + /// Create a copy of ConfirmP24PaymentOptions + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ConfirmP24PaymentOptionsImplCopyWith<_$ConfirmP24PaymentOptionsImpl> + get copyWith => __$$ConfirmP24PaymentOptionsImplCopyWithImpl< + _$ConfirmP24PaymentOptionsImpl>(this, _$identity); + + @override + Map toJson() { + return _$$ConfirmP24PaymentOptionsImplToJson( + this, + ); + } +} + +abstract class _ConfirmP24PaymentOptions implements ConfirmP24PaymentOptions { + const factory _ConfirmP24PaymentOptions({final bool? handleActions}) = + _$ConfirmP24PaymentOptionsImpl; + + factory _ConfirmP24PaymentOptions.fromJson(Map json) = + _$ConfirmP24PaymentOptionsImpl.fromJson; + + /// Set this to false if you want to manually handle + /// the authorization redirect. Default is true. + @override + bool? get handleActions; + + /// Create a copy of ConfirmP24PaymentOptions + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ConfirmP24PaymentOptionsImplCopyWith<_$ConfirmP24PaymentOptionsImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_options.g.dart b/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_options.g.dart new file mode 100644 index 000000000..81b9c2198 --- /dev/null +++ b/packages/stripe_js/lib/src/api/payment_intents/confirm_p24_payment_options.g.dart @@ -0,0 +1,19 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'confirm_p24_payment_options.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$ConfirmP24PaymentOptionsImpl _$$ConfirmP24PaymentOptionsImplFromJson( + Map json) => + _$ConfirmP24PaymentOptionsImpl( + handleActions: json['handleActions'] as bool? ?? true, + ); + +Map _$$ConfirmP24PaymentOptionsImplToJson( + _$ConfirmP24PaymentOptionsImpl instance) => + { + if (instance.handleActions case final value?) 'handleActions': value, + }; diff --git a/packages/stripe_js/lib/src/api/payment_intents/payment_intents.dart b/packages/stripe_js/lib/src/api/payment_intents/payment_intents.dart index 896c4d6e7..50c590793 100644 --- a/packages/stripe_js/lib/src/api/payment_intents/payment_intents.dart +++ b/packages/stripe_js/lib/src/api/payment_intents/payment_intents.dart @@ -6,6 +6,8 @@ export 'confirm_card_payment_data.dart'; export 'confirm_card_payment_options.dart'; export 'confirm_ideal_payment_data.dart'; export 'confirm_ideal_payment_options.dart'; +export 'confirm_p24_payment_data.dart'; +export 'confirm_p24_payment_options.dart'; export 'confirm_payment_options.dart'; export 'confirm_sepa_debit_payment_data.dart'; export 'payment_intent.dart'; diff --git a/packages/stripe_js/lib/src/js/payment_intents/confirm_p24_payment.dart b/packages/stripe_js/lib/src/js/payment_intents/confirm_p24_payment.dart new file mode 100644 index 000000000..dc9137d37 --- /dev/null +++ b/packages/stripe_js/lib/src/js/payment_intents/confirm_p24_payment.dart @@ -0,0 +1,45 @@ +import 'dart:js_interop'; + +import 'package:stripe_js/stripe_api.dart'; +import 'package:stripe_js/stripe_js.dart'; + +import '../utils/utils.dart'; + +extension ExtensionP24Payment on Stripe { + /// Use stripe.confirmP24Payment in the Przelewy24 (P24) Payments flow when the customer + /// submits your payment form. When called, it will confirm the PaymentIntent with the + /// data you provide and will automatically redirect the customer to authorize the + /// transaction. Once authorization is complete, the customer will be redirected + /// back to your specified return_url. + /// + /// When you confirm a PaymentIntent, it needs to have an attached PaymentMethod of type P24. + /// In addition to confirming the PaymentIntent, this method can automatically create + /// and attach a new PaymentMethod for you. If you have already attached a PaymentMethod, + /// you can call this method without needing to provide any additional data. These use cases + /// are detailed in the sections that follow. + /// + /// https://docs.stripe.com/js/payment_intents/confirm_p24_payment + /// + /// Note that stripe.confirmP24Payment may take several seconds to complete. During that + /// time, you should disable your form from being resubmitted and show a waiting indicator + /// like a spinner. If you receive an error result, you should be sure to show that error + /// to the customer, re-enable the form, and hide the waiting indicator. + Future confirmP24Payment( + String clientSecret, { + ConfirmP24PaymentData? data, + ConfirmP24PaymentOptions? options, + }) { + final jsData = (data?.toJson() ?? {}).jsify(); + final jsOptions = (options?.toJson() ?? {}).jsify(); + return _confirmP24Payment(clientSecret, jsData, jsOptions) + .toDart + .then((response) => response.toDart); + } + + @JS('confirmP24Payment') + external JSPromise _confirmP24Payment( + String clientSecret, [ + JSAny? data, + JSAny? options, + ]); +} 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..a27d654a6 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 @@ -2,6 +2,7 @@ export 'confirm_acss_debit_payment.dart'; export 'confirm_alipay_payment.dart'; export 'confirm_card_payment.dart'; export 'confirm_ideal_payment.dart'; +export 'confirm_p24_payment.dart'; export 'confirm_payment.dart'; export 'confirm_sepa_debit_payment.dart'; export 'handle_card_action.dart'; diff --git a/packages/stripe_web/lib/src/web_stripe.dart b/packages/stripe_web/lib/src/web_stripe.dart index 51f0dfee7..f4ff72d1f 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'; @@ -180,6 +180,19 @@ class WebStripe extends StripePlatform { ), ); }, + p24: (paymentData) { + return js.confirmP24Payment( + paymentIntentClientSecret, + data: stripe_js.ConfirmP24PaymentData( + paymentMethod: stripe_js.P24PaymentMethodDetails( + billingDetails: paymentData.billingDetails!.toJs(), + ), + returnUrl: urlScheme, + // recommended + // setup_future_usage: + ), + ); + }, orElse: () { throw WebUnsupportedError(); },