Skip to content

Commit

Permalink
feat: add onbehalfof to cardfield
Browse files Browse the repository at this point in the history
  • Loading branch information
Remon committed Nov 3, 2024
1 parent d1fce74 commit 18b2194
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
8 changes: 8 additions & 0 deletions packages/stripe/lib/src/widgets/card_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CardField extends StatefulWidget {
this.postalCodeHintText,
this.controller,
this.preferredNetworks,
this.onBehalfOf,
this.androidPlatformViewRenderType =
AndroidPlatformViewRenderType.expensiveAndroidView,
});
Expand All @@ -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
Expand Down Expand Up @@ -197,6 +201,7 @@ class _CardFieldState extends State<CardField> {
focusNode: _node,
style: style,
placeholder: placeholder,
onBehalfOf: widget.onBehalfOf,
enablePostalCode: widget.enablePostalCode,
countryCode: widget.countryCode,
dangerouslyGetFullCardDetails:
Expand Down Expand Up @@ -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)
Expand All @@ -317,6 +323,7 @@ class _MethodChannelCardField extends StatefulWidget {
final bool dangerouslyUpdateFullCardDetails;
final AndroidPlatformViewRenderType androidPlatformViewRenderType;
final List<CardBrand>? preferredNetworks;
final String? onBehalfOf;

// This is used in the platform side to register the view.
static const _viewType = 'flutter.stripe/card_field';
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions packages/stripe_ios/ios/Classes/CardFieldFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int>{
cardField.preferredNetworks = preferredNetworks
}
Expand Down

0 comments on commit 18b2194

Please sign in to comment.