Skip to content

Commit f953126

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

File tree

7 files changed

+51
-4
lines changed

7 files changed

+51
-4
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,12 @@ private func PresentPaymentSheet(
647647
configuration.allowsDelayedPaymentMethods = true
648648
configuration.defaultBillingDetails.email = config.email
649649
configuration.defaultBillingDetails.phone = config.phone
650+
651+
switch config.style {
652+
case .automatic: configuration.style = .automatic
653+
case .alwaysLight: configuration.style = .alwaysLight
654+
case .alwaysDark: configuration.style = .alwaysDark
655+
}
650656

651657
let isUITest = (ProcessInfo.processInfo.environment["UITesting"] != nil)
652658
// disable app-to-app for UI tests

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

+2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ 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

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
)

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ import UIKit
313313
state: defaultBillingDetails.address.state
314314
)
315315
)
316+
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+
}()
316324

317325
return ElementsSessionContext(
318326
amount: mode.amount,
@@ -321,7 +329,8 @@ import UIKit
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)