From 3c91ec051319f68bce346f0402c5da3ed8087cbe Mon Sep 17 00:00:00 2001 From: Remon Date: Sun, 3 Nov 2024 17:28:20 +0000 Subject: [PATCH] feat: add onbehalfof to cardfield --- example/ios/Runner/AppDelegate.swift | 2 +- packages/stripe/lib/src/widgets/card_field.dart | 8 ++++++++ .../com/flutter/stripe/StripeSdkCardPlatformView.kt | 3 +++ packages/stripe_ios/ios/Classes/CardFieldFactory.swift | 4 ++++ .../lib/src/models/payment_sheet.freezed.dart | 6 ------ 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/example/ios/Runner/AppDelegate.swift b/example/ios/Runner/AppDelegate.swift index 70693e4a8..b63630348 100644 --- a/example/ios/Runner/AppDelegate.swift +++ b/example/ios/Runner/AppDelegate.swift @@ -1,7 +1,7 @@ import UIKit import Flutter -@UIApplicationMain +@main @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, diff --git a/packages/stripe/lib/src/widgets/card_field.dart b/packages/stripe/lib/src/widgets/card_field.dart index 2fe16c9fd..4c001978c 100644 --- a/packages/stripe/lib/src/widgets/card_field.dart +++ b/packages/stripe/lib/src/widgets/card_field.dart @@ -31,6 +31,7 @@ class CardField extends StatefulWidget { this.postalCodeHintText, this.controller, this.preferredNetworks, + this.onBehalfOf, this.androidPlatformViewRenderType = AndroidPlatformViewRenderType.expensiveAndroidView, }); @@ -50,6 +51,9 @@ class CardField extends StatefulWidget { /// Color of the cursor when a field gets focus. final Color? cursorColor; + /// The account (if any) for which the funds of the intent are intended. + final String? onBehalfOf; + /// Whether or not to show the postalcode field in the form. /// /// Defaults is `false`. If your configuration in Stripe requires a postalcode @@ -197,6 +201,7 @@ class _CardFieldState extends State { focusNode: _node, style: style, placeholder: placeholder, + onBehalfOf: widget.onBehalfOf, enablePostalCode: widget.enablePostalCode, countryCode: widget.countryCode, dangerouslyGetFullCardDetails: @@ -295,6 +300,7 @@ class _MethodChannelCardField extends StatefulWidget { this.preferredNetworks, this.dangerouslyGetFullCardDetails = false, this.dangerouslyUpdateFullCardDetails = false, + this.onBehalfOf, this.autofocus = false, }) : assert(constraints == null || constraints.debugAssertIsValid()), constraints = (width != null || height != null) @@ -317,6 +323,7 @@ class _MethodChannelCardField extends StatefulWidget { final bool dangerouslyUpdateFullCardDetails; final AndroidPlatformViewRenderType androidPlatformViewRenderType; final List? preferredNetworks; + final String? onBehalfOf; // This is used in the platform side to register the view. static const _viewType = 'flutter.stripe/card_field'; @@ -405,6 +412,7 @@ class _MethodChannelCardFieldState extends State<_MethodChannelCardField> 'placeholder': placeholder.toJson(), 'postalCodeEnabled': widget.enablePostalCode, 'countryCode': widget.countryCode, + if (widget.onBehalfOf != null) 'onBehalfOf': widget.onBehalfOf, if (widget.preferredNetworks != null) 'preferredNetworks': widget.preferredNetworks?.map((e) => e.brandValue).toList(), diff --git a/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt b/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt index 3d8d47797..d8a9d1bb6 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt @@ -38,6 +38,9 @@ class StripeSdkCardPlatformView( if (creationParams?.containsKey("postalCodeEnabled") == true) { stripeSdkCardViewManager.setPostalCodeEnabled(cardView, creationParams["postalCodeEnabled"] as Boolean) } + if(creationParams?.containsKey("onBehalfOf")==true){ + stripeSdkCardViewManager.setOnBehalfOf(cardView, creationParams["onBehalfOf"] as String) + } if (creationParams?.containsKey("countryCode") == true) { stripeSdkCardViewManager.setCountryCode(cardView, creationParams["countryCode"] as? String) } diff --git a/packages/stripe_ios/ios/Classes/CardFieldFactory.swift b/packages/stripe_ios/ios/Classes/CardFieldFactory.swift index 082a55824..59293d39e 100644 --- a/packages/stripe_ios/ios/Classes/CardFieldFactory.swift +++ b/packages/stripe_ios/ios/Classes/CardFieldFactory.swift @@ -137,6 +137,10 @@ class CardFieldPlatformView: NSObject, FlutterPlatformView, STPPaymentCardTextFi cardField.disabled = disabled } + if let onBehalfOf = arguments["onBehalfOf"] as? String{ + cardField.onBehalfOf = onBehalfOf + } + if let preferredNetworks = arguments["preferredNetworks"] as? Array{ cardField.preferredNetworks = preferredNetworks } 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 802254fa5..185da72bb 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 @@ -877,14 +877,11 @@ abstract class _SetupParameters implements SetupPaymentSheetParameters { ///A temp key can be used for API operations that require a secret key. String? get customerEphemeralKeySecret; @override -<<<<<<< HEAD -======= /// (Experimental) This parameter can be changed or removed at any time (use at your own risk). /// The client secret of this Customer Session. Used on the client to set up secure access to the given customer. String? get customerSessionClientSecret; @override ->>>>>>> d1fce74 (feat: add customer session client secret to payment sheet) /// Secret used for client-side retrieval using a publishable key. /// @@ -2336,10 +2333,7 @@ abstract class _PaymentSheetGooglePay implements PaymentSheetGooglePay { @override /// The Google Pay button type to use. Set to "Pay" by default. -<<<<<<< HEAD @JsonKey(toJson: PaymentSheetGooglePay.platformButtonTypeToJson) -======= ->>>>>>> d1fce74 (feat: add customer session client secret to payment sheet) PlatformButtonType? get buttonType; @override @JsonKey(ignore: true)