Skip to content

Commit

Permalink
Add public configuration field for bank account collector API
Browse files Browse the repository at this point in the history
  • Loading branch information
mats-stripe committed Feb 10, 2025
1 parent b7b11b7 commit 0806fd7
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 42 deletions.
4 changes: 4 additions & 0 deletions StripeCore/StripeCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
45DAE581F74EF7E11C64212B /* InstallMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21E64986F72C7BD8B1105A95 /* InstallMethod.swift */; };
48A6CCB4008A5060C2655C5F /* XCTestCase+Stripe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DE48D0086BED21F9E837D0B /* XCTestCase+Stripe.swift */; };
4910B9282C3D8F3F00B030D4 /* Result+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4910B9272C3D8F3F00B030D4 /* Result+Extensions.swift */; };
491785452D5A6027007B4BDF /* FinancialConnectionsConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 491785442D5A6027007B4BDF /* FinancialConnectionsConfiguration.swift */; };
492039932CA47A8600CE2072 /* ElementsSessionContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 492039922CA47A8600CE2072 /* ElementsSessionContext.swift */; };
493B33062CA3015600E3622F /* LinkMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 493B33052CA3015600E3622F /* LinkMode.swift */; };
49E8CE2A2CD146CE0009DFBB /* KeyedEncodingContainer+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49E8CE292CD146CE0009DFBB /* KeyedEncodingContainer+Extensions.swift */; };
Expand Down Expand Up @@ -245,6 +246,7 @@
4689F6B4384244D9FD282560 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
48A3D6592296104A1512AE92 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
4910B9272C3D8F3F00B030D4 /* Result+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Result+Extensions.swift"; sourceTree = "<group>"; };
491785442D5A6027007B4BDF /* FinancialConnectionsConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinancialConnectionsConfiguration.swift; sourceTree = "<group>"; };
492039922CA47A8600CE2072 /* ElementsSessionContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ElementsSessionContext.swift; sourceTree = "<group>"; };
493B33052CA3015600E3622F /* LinkMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkMode.swift; sourceTree = "<group>"; };
49424775D3233411D9C2473B /* StripeCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StripeCodable.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -498,6 +500,7 @@
CB0E9DC72CB9C79E00E083D1 /* LinkBankPaymentMethod.swift */,
CB8035292D31BA79008F0556 /* AvailableIncentives.swift */,
CB80352B2D31BAC7008F0556 /* LinkConsumerIncentive.swift */,
491785442D5A6027007B4BDF /* FinancialConnectionsConfiguration.swift */,
);
path = "Connections Bindings";
sourceTree = "<group>";
Expand Down Expand Up @@ -1021,6 +1024,7 @@
6A05FB472BCF24370001D128 /* FinancialConnectionsLinkedBank.swift in Sources */,
9FBA50345D53E82AA974F672 /* STPAPIClient+FileUpload.swift in Sources */,
31AD3BDC2B0C23E40080C800 /* Locale+StripeCore.swift in Sources */,
491785452D5A6027007B4BDF /* FinancialConnectionsConfiguration.swift in Sources */,
C164984958CDC2C9CA4B6316 /* STPAPIClient.swift in Sources */,
97D0B2120678A75F75648D84 /* STPAppInfo.swift in Sources */,
12FF091C555F75B914464475 /* STPMultipartFormDataEncoder.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,13 @@ import Foundation
}
}

/// Intermediary object between `PaymentSheet.Configuration.UserInterfaceStyle`
/// and `FinancialConnectionsSheet.Configuration.UserInterfaceStyle`.
@_spi(STP) @frozen public enum StyleConfig {
case automatic
case alwaysLight
case alwaysDark
}

@_spi(STP) public let amount: Int?
@_spi(STP) public let currency: String?
@_spi(STP) public let prefillDetails: PrefillDetails?
@_spi(STP) public let intentId: IntentID?
@_spi(STP) public let linkMode: LinkMode?
@_spi(STP) public let billingDetails: BillingDetails?
@_spi(STP) public let eligibleForIncentive: Bool
@_spi(STP) public let styleConfig: StyleConfig?

@_spi(STP) public var billingAddress: BillingAddress? {
BillingAddress(from: billingDetails)
Expand All @@ -79,8 +70,7 @@ import Foundation
intentId: IntentID? = nil,
linkMode: LinkMode? = nil,
billingDetails: BillingDetails? = nil,
eligibleForIncentive: Bool = false,
styleConfig: StyleConfig? = nil
eligibleForIncentive: Bool = false
) {
self.amount = amount
self.currency = currency
Expand All @@ -89,7 +79,6 @@ import Foundation
self.linkMode = linkMode
self.billingDetails = billingDetails
self.eligibleForIncentive = eligibleForIncentive
self.styleConfig = styleConfig
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// FinancialConnectionsConfiguration.swift
// StripeCore
//
// Created by Mat Schmid on 2025-02-10.
//

import Foundation

/// Intermediary object between `PaymentSheet.Configuration` / `STPBankAccountCollectorConfiguration`
/// and `FinancialConnectionsSheet.Configuration`.
@_spi(STP) public struct FinancialConnectionsConfiguration {
@_spi(STP) @frozen public enum StyleConfig {
case automatic
case alwaysLight
case alwaysDark
}

@_spi(STP) public let styleConfig: StyleConfig

@_spi(STP) public init(styleConfig: StyleConfig = .automatic) {
self.styleConfig = styleConfig
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import UIKit
apiClient: STPAPIClient,
clientSecret: String,
returnURL: String?,
sheetConfiguration: FinancialConnectionsConfiguration?,
elementsSessionContext: ElementsSessionContext?,
onEvent: ((FinancialConnectionsEvent) -> Void)?,
from presentingViewController: UIViewController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class FinancialConnectionsSDKImplementation: FinancialConnectionsSDKInter
apiClient: STPAPIClient,
clientSecret: String,
returnURL: String?,
sheetConfiguration: FinancialConnectionsConfiguration?,
elementsSessionContext: ElementsSessionContext?,
onEvent: ((StripeCore.FinancialConnectionsEvent) -> Void)?,
from presentingViewController: UIViewController,
Expand All @@ -34,7 +35,7 @@ public class FinancialConnectionsSDKImplementation: FinancialConnectionsSDKInter
financialConnectionsSheet.onEvent = onEvent

var configuration = FinancialConnectionsSheet.Configuration()
if let styleConfig = elementsSessionContext?.styleConfig {
if let styleConfig = sheetConfiguration?.styleConfig {
switch styleConfig {
case .automatic: configuration.style = .automatic
case .alwaysLight: configuration.style = .alwaysLight
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@
47B19F96CCEA290541E3B988 /* CardSectionElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D03000A6807B09BFD8E6CB1 /* CardSectionElement.swift */; };
48DA2EFE0944E737B0F197B0 /* OHHTTPStubs in Frameworks */ = {isa = PBXBuildFile; productRef = B2AFFAD776D5F21DF837F1BD /* OHHTTPStubs */; };
49803444CD948F1ED28FF021 /* PaymentSheetFormFactory+FormSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD7A1EFF100C589FDFF4D516 /* PaymentSheetFormFactory+FormSpec.swift */; };
49AED8FB2D4C46A700FD7C23 /* ElementsSessionContext+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49AED8FA2D4C46A700FD7C23 /* ElementsSessionContext+Extensions.swift */; };
49F62EDF394F18E5BB201D53 /* StripePaymentSheet.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AA6166F234C3A2129CBD573 /* StripePaymentSheet.h */; settings = {ATTRIBUTES = (Public, ); }; };
4A1A0A542B824C830A200BE0 /* StubbedBackend.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBF8498CCD12A5190F9267CD /* StubbedBackend.swift */; };
4A8C7B2AFB290567C961DAB0 /* StripePaymentsUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F22354BD25171B8DC2B922D2 /* StripePaymentsUI.framework */; };
Expand Down Expand Up @@ -560,7 +559,6 @@
45B6DC9BD9183495E5649369 /* LinkAccountService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkAccountService.swift; sourceTree = "<group>"; };
47C5DB8C01BA7137369C8B4D /* TextFieldElement+Card.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TextFieldElement+Card.swift"; sourceTree = "<group>"; };
492B254E43F3BB9F9CEAEA06 /* PaymentSheetLoaderStubbedTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentSheetLoaderStubbedTest.swift; sourceTree = "<group>"; };
49AED8FA2D4C46A700FD7C23 /* ElementsSessionContext+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ElementsSessionContext+Extensions.swift"; sourceTree = "<group>"; };
4BEFE8C0CFEAE73F9FD736D3 /* STPStringUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPStringUtils.swift; sourceTree = "<group>"; };
4C6AA41454A6757B3E26AE67 /* StripePaymentSheetTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = StripePaymentSheetTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
4D595AA033BC84CB4E1C277F /* PaymentSheetFormFactorySnapshotTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentSheetFormFactorySnapshotTest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1237,7 +1235,6 @@
4DA1B1B7662E177725062922 /* StripePaymentSheet+Exports.swift */,
70ED08B0F303B7C2334602C3 /* StripePaymentSheetBundleLocator.swift */,
6103F2BB2BE45990002D67F8 /* SavedPaymentMethodManager.swift */,
49AED8FA2D4C46A700FD7C23 /* ElementsSessionContext+Extensions.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -2286,7 +2283,6 @@
B2979A0740F8730FC14DFEC1 /* BottomSheetViewController.swift in Sources */,
2E4C37C73AD202C8A3DD2E4E /* LoadingViewController.swift in Sources */,
A8ECBDF889E258F03B86BC2E /* PaymentSheetFlowControllerViewController.swift in Sources */,
49AED8FB2D4C46A700FD7C23 /* ElementsSessionContext+Extensions.swift in Sources */,
247A8FEE5184E5976720599E /* PaymentSheetViewController.swift in Sources */,
6B31B9BA2B90FCE60064E210 /* CustomerSession.swift in Sources */,
4DDECA1F7EC6B624C00D549E /* PollingViewController.swift in Sources */,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,25 @@ extension CustomerAddPaymentMethodViewController {
}
}

let bankAccountCollectorConfiguration: STPBankAccountCollectorConfiguration = {
let style: STPBankAccountCollectorConfiguration.UserInterfaceStyle = {
switch configuration.style {
case .automatic: return .automatic
case .alwaysLight: return .alwaysLight
case .alwaysDark: return .alwaysDark
}
}()
return .init(style: style)
}()

let additionalParameters: [String: Any] = [
"hosted_surface": "customer_sheet",
]
client.collectBankAccountForSetup(
clientSecret: clientSecret,
returnURL: configuration.returnURL,
additionalParameters: additionalParameters,
configuration: bankAccountCollectorConfiguration,
onEvent: nil,
params: params,
from: viewController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,15 @@ import UIKit
)

let elementsSessionContext = makeElementsSessionContext()
let bankAccountCollectorConfiguration = makeBankAccountCollectorConfiguration()

switch mode {
case .paymentIntentClientSecret(let string):
bankAccountCollector.collectBankAccountForPayment(
clientSecret: string,
returnURL: configuration.returnURL,
additionalParameters: additionalParameters,
configuration: bankAccountCollectorConfiguration,
elementsSessionContext: elementsSessionContext,
onEvent: nil,
params: params,
Expand All @@ -265,6 +267,7 @@ import UIKit
clientSecret: string,
returnURL: configuration.returnURL,
additionalParameters: additionalParameters,
configuration: bankAccountCollectorConfiguration,
elementsSessionContext: elementsSessionContext,
onEvent: nil,
params: params,
Expand All @@ -290,6 +293,7 @@ import UIKit
currency: currency,
onBehalfOf: nil,
additionalParameters: additionalParameters,
configuration: bankAccountCollectorConfiguration,
elementsSessionContext: elementsSessionContext,
from: presentingViewController,
financialConnectionsCompletion: completionHandler
Expand All @@ -314,19 +318,28 @@ import UIKit
)
)

let styleConfig = ElementsSessionContext.StyleConfig(from: configuration.style)
return ElementsSessionContext(
amount: mode.amount,
currency: mode.currency,
prefillDetails: makePrefillDetails(),
intentId: nil,
linkMode: nil,
billingDetails: billingDetails,
eligibleForIncentive: false,
styleConfig: styleConfig
eligibleForIncentive: false
)
}

private func makeBankAccountCollectorConfiguration() -> STPBankAccountCollectorConfiguration {
let style: STPBankAccountCollectorConfiguration.UserInterfaceStyle = {
switch configuration.style {
case .automatic: return .automatic
case .alwaysLight: return .alwaysLight
case .alwaysDark: return .alwaysDark
}
}()
return .init(style: style)
}

private func makePrefillDetails() -> ElementsSessionContext.PrefillDetails {
var billingPhone: PhoneNumber?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ extension PaymentMethodFormViewController {
)
let linkMode = elementsSession.linkSettings?.linkMode
let billingDetails = instantDebitsFormElement?.billingDetails
let styleConfig = ElementsSessionContext.StyleConfig(from: configuration.style)

return ElementsSessionContext(
amount: intent.amount,
Expand All @@ -284,11 +283,21 @@ extension PaymentMethodFormViewController {
intentId: intentId,
linkMode: linkMode,
billingDetails: billingDetails,
eligibleForIncentive: instantDebitsFormElement?.displayableIncentive != nil,
styleConfig: styleConfig
eligibleForIncentive: instantDebitsFormElement?.displayableIncentive != nil
)
}

private var bankAccountCollectorConfiguration: STPBankAccountCollectorConfiguration {
let style: STPBankAccountCollectorConfiguration.UserInterfaceStyle = {
switch configuration.style {
case .automatic: return .automatic
case .alwaysLight: return .alwaysLight
case .alwaysDark: return .alwaysDark
}
}()
return .init(style: style)
}

private var shouldOverridePrimaryButton: Bool {
if paymentMethodType == .stripe(.USBankAccount) {
if case .new = paymentOption {
Expand Down Expand Up @@ -394,6 +403,7 @@ extension PaymentMethodFormViewController {
clientSecret: paymentIntent.clientSecret,
returnURL: configuration.returnURL,
additionalParameters: additionalParameters,
configuration: bankAccountCollectorConfiguration,
elementsSessionContext: elementsSessionContext,
onEvent: nil,
params: params,
Expand All @@ -405,6 +415,7 @@ extension PaymentMethodFormViewController {
clientSecret: setupIntent.clientSecret,
returnURL: configuration.returnURL,
additionalParameters: additionalParameters,
configuration: bankAccountCollectorConfiguration,
elementsSessionContext: elementsSessionContext,
onEvent: nil,
params: params,
Expand All @@ -430,6 +441,7 @@ extension PaymentMethodFormViewController {
currency: currency,
onBehalfOf: intentConfig.onBehalfOf,
additionalParameters: additionalParameters,
configuration: bankAccountCollectorConfiguration,
elementsSessionContext: elementsSessionContext,
from: viewController,
financialConnectionsCompletion: financialConnectionsCompletion
Expand Down Expand Up @@ -495,6 +507,7 @@ extension PaymentMethodFormViewController {
clientSecret: paymentIntent.clientSecret,
returnURL: configuration.returnURL,
additionalParameters: additionalParameters,
configuration: bankAccountCollectorConfiguration,
elementsSessionContext: elementsSessionContext,
onEvent: nil,
params: params,
Expand All @@ -506,6 +519,7 @@ extension PaymentMethodFormViewController {
clientSecret: setupIntent.clientSecret,
returnURL: configuration.returnURL,
additionalParameters: additionalParameters,
configuration: bankAccountCollectorConfiguration,
elementsSessionContext: elementsSessionContext,
onEvent: nil,
params: params,
Expand All @@ -531,6 +545,7 @@ extension PaymentMethodFormViewController {
currency: currency,
onBehalfOf: intentConfig.onBehalfOf,
additionalParameters: additionalParameters,
configuration: bankAccountCollectorConfiguration,
elementsSessionContext: elementsSessionContext,
from: viewController,
financialConnectionsCompletion: financialConnectionsCompletion
Expand Down
Loading

0 comments on commit 0806fd7

Please sign in to comment.