diff --git a/example/server/src/index.ts b/example/server/src/index.ts index ef36faddd..c75c8640a 100644 --- a/example/server/src/index.ts +++ b/example/server/src/index.ts @@ -746,6 +746,34 @@ app.post('/create-checkout-session', async (req, res) => { }); }); +app.post('/customer-sheet', async (_, res) => { + const { secret_key } = getKeys(); + + const stripe = new Stripe(secret_key as string, { + apiVersion: '2023-08-16', + typescript: true, + }); + + // Use an existing Customer ID if this is a returning customer. + const customer = await stripe.customers.create(); + + // Use the same version as the SDK + const ephemeralKey = await stripe.ephemeralKeys.create( + { customer: customer.id }, + { apiVersion: '2020-08-27' } + ); + + const setupIntent = await stripe.setupIntents.create({ + customer: customer.id, + }); + + res.json({ + customer: customer.id, + ephemeralKeySecret: ephemeralKey.secret, + setupIntent: setupIntent.client_secret, + }); +}); + app.post('/fetch-payment-methods', async (req, res) => { const { secret_key } = getKeys(); 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 c274595ec..2b8b09f9e 100644 --- a/packages/stripe_platform_interface/lib/src/models/payment_sheet.dart +++ b/packages/stripe_platform_interface/lib/src/models/payment_sheet.dart @@ -457,7 +457,7 @@ class PaymentSheetPaymentOption with _$PaymentSheetPaymentOption { required String label, /// String decoding of the image - required String image, + String? image, }) = _PaymentSheetPaymentOption; factory PaymentSheetPaymentOption.fromJson(Map 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 8c6683022..29efe6615 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 @@ -4471,7 +4471,7 @@ mixin _$PaymentSheetPaymentOption { String get label => throw _privateConstructorUsedError; /// String decoding of the image - String get image => throw _privateConstructorUsedError; + String? get image => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -4485,7 +4485,7 @@ abstract class $PaymentSheetPaymentOptionCopyWith<$Res> { $Res Function(PaymentSheetPaymentOption) then) = _$PaymentSheetPaymentOptionCopyWithImpl<$Res, PaymentSheetPaymentOption>; @useResult - $Res call({String label, String image}); + $Res call({String label, String? image}); } /// @nodoc @@ -4503,17 +4503,17 @@ class _$PaymentSheetPaymentOptionCopyWithImpl<$Res, @override $Res call({ Object? label = null, - Object? image = null, + Object? image = freezed, }) { return _then(_value.copyWith( label: null == label ? _value.label : label // ignore: cast_nullable_to_non_nullable as String, - image: null == image + image: freezed == image ? _value.image : image // ignore: cast_nullable_to_non_nullable - as String, + as String?, ) as $Val); } } @@ -4527,7 +4527,7 @@ abstract class _$$_PaymentSheetPaymentOptionCopyWith<$Res> __$$_PaymentSheetPaymentOptionCopyWithImpl<$Res>; @override @useResult - $Res call({String label, String image}); + $Res call({String label, String? image}); } /// @nodoc @@ -4544,17 +4544,17 @@ class __$$_PaymentSheetPaymentOptionCopyWithImpl<$Res> @override $Res call({ Object? label = null, - Object? image = null, + Object? image = freezed, }) { return _then(_$_PaymentSheetPaymentOption( label: null == label ? _value.label : label // ignore: cast_nullable_to_non_nullable as String, - image: null == image + image: freezed == image ? _value.image : image // ignore: cast_nullable_to_non_nullable - as String, + as String?, )); } } @@ -4563,8 +4563,7 @@ class __$$_PaymentSheetPaymentOptionCopyWithImpl<$Res> @JsonSerializable(explicitToJson: true) class _$_PaymentSheetPaymentOption implements _PaymentSheetPaymentOption { - const _$_PaymentSheetPaymentOption( - {required this.label, required this.image}); + const _$_PaymentSheetPaymentOption({required this.label, this.image}); factory _$_PaymentSheetPaymentOption.fromJson(Map json) => _$$_PaymentSheetPaymentOptionFromJson(json); @@ -4575,7 +4574,7 @@ class _$_PaymentSheetPaymentOption implements _PaymentSheetPaymentOption { /// String decoding of the image @override - final String image; + final String? image; @override String toString() { @@ -4613,7 +4612,7 @@ class _$_PaymentSheetPaymentOption implements _PaymentSheetPaymentOption { abstract class _PaymentSheetPaymentOption implements PaymentSheetPaymentOption { const factory _PaymentSheetPaymentOption( {required final String label, - required final String image}) = _$_PaymentSheetPaymentOption; + final String? image}) = _$_PaymentSheetPaymentOption; factory _PaymentSheetPaymentOption.fromJson(Map json) = _$_PaymentSheetPaymentOption.fromJson; @@ -4625,7 +4624,7 @@ abstract class _PaymentSheetPaymentOption implements PaymentSheetPaymentOption { @override /// String decoding of the image - String get image; + String? get image; @override @JsonKey(ignore: true) _$$_PaymentSheetPaymentOptionCopyWith<_$_PaymentSheetPaymentOption> 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 88171e318..2a4c063c2 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 @@ -403,7 +403,7 @@ _$_PaymentSheetPaymentOption _$$_PaymentSheetPaymentOptionFromJson( Map json) => _$_PaymentSheetPaymentOption( label: json['label'] as String, - image: json['image'] as String, + image: json['image'] as String?, ); Map _$$_PaymentSheetPaymentOptionToJson(