Skip to content

Commit 5842402

Browse files
committed
Pass along style config from MPE to FC
1 parent 4c816d2 commit 5842402

File tree

10 files changed

+56
-7
lines changed

10 files changed

+56
-7
lines changed

Example/FinancialConnections Example/FinancialConnections Example/Playground/PlaygroundViewModel.swift

+6
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,12 @@ private func PresentPaymentSheet(
648648
configuration.defaultBillingDetails.email = config.email
649649
configuration.defaultBillingDetails.phone = config.phone
650650

651+
switch config.style {
652+
case .automatic: configuration.style = .automatic
653+
case .alwaysLight: configuration.style = .alwaysLight
654+
case .alwaysDark: configuration.style = .alwaysDark
655+
}
656+
651657
let isUITest = (ProcessInfo.processInfo.environment["UITesting"] != nil)
652658
// disable app-to-app for UI tests
653659
configuration.returnURL = isUITest ? nil : "financial-connections-example://redirect"

StripeCore/StripeCore/Source/Connections Bindings/ElementsSessionContext.swift

+12-1
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,22 @@ import Foundation
4444
}
4545
}
4646

47+
/// Intermediary object between `PaymentSheet.Configuration.UserInterfaceStyle`
48+
/// and `FinancialConnectionsSheet.Configuration.UserInterfaceStyle`.
49+
@_spi(STP) @frozen public enum StyleConfig {
50+
case automatic
51+
case alwaysLight
52+
case alwaysDark
53+
}
54+
4755
@_spi(STP) public let amount: Int?
4856
@_spi(STP) public let currency: String?
4957
@_spi(STP) public let prefillDetails: PrefillDetails?
5058
@_spi(STP) public let intentId: IntentID?
5159
@_spi(STP) public let linkMode: LinkMode?
5260
@_spi(STP) public let billingDetails: BillingDetails?
5361
@_spi(STP) public let eligibleForIncentive: Bool
62+
@_spi(STP) public let styleConfig: StyleConfig?
5463

5564
@_spi(STP) public var billingAddress: BillingAddress? {
5665
BillingAddress(from: billingDetails)
@@ -70,7 +79,8 @@ import Foundation
7079
intentId: IntentID? = nil,
7180
linkMode: LinkMode? = nil,
7281
billingDetails: BillingDetails? = nil,
73-
eligibleForIncentive: Bool = false
82+
eligibleForIncentive: Bool = false,
83+
styleConfig: StyleConfig? = nil
7484
) {
7585
self.amount = amount
7686
self.currency = currency
@@ -79,6 +89,7 @@ import Foundation
7989
self.linkMode = linkMode
8090
self.billingDetails = billingDetails
8191
self.eligibleForIncentive = eligibleForIncentive
92+
self.styleConfig = styleConfig
8293
}
8394
}
8495

StripeFinancialConnections/StripeFinancialConnections/Source/FinancialConnectionsSDK/FinancialConnectionsSDKImplementation.swift

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ public class FinancialConnectionsSDKImplementation: FinancialConnectionsSDKInter
3232
financialConnectionsSheet.apiClient = apiClient
3333
financialConnectionsSheet.elementsSessionContext = elementsSessionContext
3434
financialConnectionsSheet.onEvent = onEvent
35+
36+
var configuration = FinancialConnectionsSheet.Configuration()
37+
if let styleConfig = elementsSessionContext?.styleConfig {
38+
switch styleConfig {
39+
case .automatic: configuration.style = .automatic
40+
case .alwaysLight: configuration.style = .alwaysLight
41+
case .alwaysDark: configuration.style = .alwaysDark
42+
}
43+
}
44+
financialConnectionsSheet.configuration = configuration
3545
// Captures self explicitly until the callback is invoked
3646
financialConnectionsSheet.present(
3747
from: presentingViewController,

StripeFinancialConnections/StripeFinancialConnections/Source/FinancialConnectionsSheet.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,19 @@ final public class FinancialConnectionsSheet {
5050
@_spi(STP) @frozen public enum UserInterfaceStyle {
5151
/// (default) Financial Connections will automatically switch between light and dark mode compatible colors based on device settings.
5252
case automatic
53+
5354
/// Financial Connections will always use colors appropriate for light mode UI.
5455
case alwaysLight
56+
5557
/// Financial Connections will always use colors appropriate for dark mode UI.
5658
case alwaysDark
5759

5860
/// Applies the specified user interface style to the given view controller.
5961
func configure(_ viewController: UIViewController?) {
60-
guard let viewController else { return }
6162
guard ExperimentStore.shared.supportsDynamicStyle else {
6263
return
6364
}
65+
guard let viewController else { return }
6466

6567
switch self {
6668
case .automatic:

StripeFinancialConnections/StripeFinancialConnections/Source/Native/NativeFlowController.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,7 @@ private func CreatePaneViewController(
16381638
)
16391639
}
16401640

1641+
// Applies the style configuration to each view controller.
16411642
dataManager.configuration.style.configure(viewController)
16421643
return viewController
16431644
}

StripeFinancialConnections/StripeFinancialConnections/Source/Native/Shared/ExperimentStore.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import Foundation
99

10-
/// Internal store to access exoerimental features,
10+
/// Internal singleton store to access experimental features.
11+
/// Enabling any of these might result in unexpected behavior.
1112
@_spi(STP) public class ExperimentStore {
1213
@_spi(STP) public static let shared = ExperimentStore()
1314

StripeFinancialConnections/StripeFinancialConnectionsTests/FinancialConnectionsSheetTests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ class FinancialConnectionsSheetTests: XCTestCase {
5252
apiClient: mockApiClient,
5353
analyticsClientV1: mockAnalyticsClient,
5454
clientSecret: "test",
55-
elementsSessionContext: nil,
5655
returnURL: nil,
56+
configuration: .init(),
57+
elementsSessionContext: nil,
5758
publishableKey: "test",
5859
stripeAccount: nil
5960
)

StripeFinancialConnections/StripeFinancialConnectionsTests/FinancialConnectionsWebFlowTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ final class FinancialConnectionsWebFlowTests: XCTestCase {
208208
)
209209
XCTAssertEqual(additionalParameters, "&return_payment_method=true&expand_payment_method=true&billingDetails%5Bname%5D=Foo%20Bar&billingDetails%5Bemail%5D=foo%40bar.com&billingDetails%5Bphone%5D=+1%20(123)%20456-7890&billingDetails%5Baddress%5D%5Bcity%5D=Toronto&billingDetails%5Baddress%5D%5Bcountry%5D=CA&billingDetails%5Baddress%5D%5Bline1%5D=123%20Main%20St&billingDetails%5Baddress%5D%5Bpostal_code%5D=A0B%201C2&billingDetails%5Baddress%5D%5Bstate%5D=ON")
210210
}
211-
211+
212212
func test_additionalParameters_incentiveEligible() {
213213
let additionalParameters = FinancialConnectionsWebFlowViewController.buildEncodedUrlParameters(
214214
startingAdditionalParameters: nil,

StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/Link/LinkPaymentController.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,23 @@ import UIKit
314314
)
315315
)
316316

317+
let styleConfig: ElementsSessionContext.StyleConfig = {
318+
switch configuration.style {
319+
case .automatic: return .automatic
320+
case .alwaysLight: return .alwaysLight
321+
case .alwaysDark: return .alwaysDark
322+
}
323+
}()
324+
317325
return ElementsSessionContext(
318326
amount: mode.amount,
319327
currency: mode.currency,
320328
prefillDetails: makePrefillDetails(),
321329
intentId: nil,
322330
linkMode: nil,
323331
billingDetails: billingDetails,
324-
eligibleForIncentive: false
332+
eligibleForIncentive: false,
333+
styleConfig: styleConfig
325334
)
326335
}
327336

StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/ViewControllers/PaymentMethodFormViewController.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ extension PaymentMethodFormViewController {
264264
)
265265
let linkMode = elementsSession.linkSettings?.linkMode
266266
let billingDetails = instantDebitsFormElement?.billingDetails
267+
let styleConfig: ElementsSessionContext.StyleConfig = {
268+
switch configuration.style {
269+
case .automatic: return .automatic
270+
case .alwaysLight: return .alwaysLight
271+
case .alwaysDark: return .alwaysDark
272+
}
273+
}()
267274

268275
return ElementsSessionContext(
269276
amount: intent.amount,
@@ -272,7 +279,8 @@ extension PaymentMethodFormViewController {
272279
intentId: intentId,
273280
linkMode: linkMode,
274281
billingDetails: billingDetails,
275-
eligibleForIncentive: instantDebitsFormElement?.incentive != nil
282+
eligibleForIncentive: instantDebitsFormElement?.incentive != nil,
283+
styleConfig: styleConfig
276284
)
277285
}
278286

0 commit comments

Comments
 (0)