Skip to content

Commit

Permalink
Pass along style config from MPE to FC
Browse files Browse the repository at this point in the history
  • Loading branch information
mats-stripe committed Jan 29, 2025
1 parent 2000339 commit f0ee717
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,12 @@ private func PresentPaymentSheet(
configuration.defaultBillingDetails.email = config.email
configuration.defaultBillingDetails.phone = config.phone

switch config.style {
case .automatic: configuration.style = .automatic
case .alwaysLight: configuration.style = .alwaysLight
case .alwaysDark: configuration.style = .alwaysDark
}

let isUITest = (ProcessInfo.processInfo.environment["UITesting"] != nil)
// disable app-to-app for UI tests
configuration.returnURL = isUITest ? nil : "financial-connections-example://redirect"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,22 @@ 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 @@ -70,7 +79,8 @@ import Foundation
intentId: IntentID? = nil,
linkMode: LinkMode? = nil,
billingDetails: BillingDetails? = nil,
eligibleForIncentive: Bool = false
eligibleForIncentive: Bool = false,
styleConfig: StyleConfig? = nil
) {
self.amount = amount
self.currency = currency
Expand All @@ -79,6 +89,7 @@ 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
Expand Up @@ -32,6 +32,16 @@ public class FinancialConnectionsSDKImplementation: FinancialConnectionsSDKInter
financialConnectionsSheet.apiClient = apiClient
financialConnectionsSheet.elementsSessionContext = elementsSessionContext
financialConnectionsSheet.onEvent = onEvent

var configuration = FinancialConnectionsSheet.Configuration()
if let styleConfig = elementsSessionContext?.styleConfig {
switch styleConfig {
case .automatic: configuration.style = .automatic
case .alwaysLight: configuration.style = .alwaysLight
case .alwaysDark: configuration.style = .alwaysDark
}
}
financialConnectionsSheet.configuration = configuration
// Captures self explicitly until the callback is invoked
financialConnectionsSheet.present(
from: presentingViewController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,21 @@ final public class FinancialConnectionsSheet {
@_spi(STP) public struct Configuration {
/// Style options for colors in Financial Connections.
@_spi(STP) @frozen public enum UserInterfaceStyle {
/// (default) Financial Connections will automatically switch between light and dark mode compatible colors based on device settings.
/// Financial Connections will automatically switch between light and dark mode compatible colors based on device settings.
case automatic
/// Financial Connections will always use colors appropriate for light mode UI.

/// (default) Financial Connections will always use colors appropriate for light mode UI.
case alwaysLight

/// Financial Connections will always use colors appropriate for dark mode UI.
case alwaysDark

/// Applies the specified user interface style to the given view controller.
func configure(_ viewController: UIViewController?) {
guard let viewController else { return }
guard ExperimentStore.shared.supportsDynamicStyle else {
return
}
guard let viewController else { return }

switch self {
case .automatic:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,7 @@ private func CreatePaneViewController(
)
}

// Applies the style configuration to each view controller.
dataManager.configuration.style.configure(viewController)
return viewController
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import Foundation

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ class FinancialConnectionsSheetTests: XCTestCase {
apiClient: mockApiClient,
analyticsClientV1: mockAnalyticsClient,
clientSecret: "test",
elementsSessionContext: nil,
returnURL: nil,
configuration: .init(),
elementsSessionContext: nil,
publishableKey: "test",
stripeAccount: nil
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,23 @@ import UIKit
)
)

let styleConfig: ElementsSessionContext.StyleConfig = {
switch configuration.style {
case .automatic: return .automatic
case .alwaysLight: return .alwaysLight
case .alwaysDark: return .alwaysDark
}
}()

return ElementsSessionContext(
amount: mode.amount,
currency: mode.currency,
prefillDetails: makePrefillDetails(),
intentId: nil,
linkMode: nil,
billingDetails: billingDetails,
eligibleForIncentive: false
eligibleForIncentive: false,
styleConfig: styleConfig
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ extension PaymentMethodFormViewController {
)
let linkMode = elementsSession.linkSettings?.linkMode
let billingDetails = instantDebitsFormElement?.billingDetails
let styleConfig: ElementsSessionContext.StyleConfig = {
switch configuration.style {
case .automatic: return .automatic
case .alwaysLight: return .alwaysLight
case .alwaysDark: return .alwaysDark
}
}()

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

Expand Down

0 comments on commit f0ee717

Please sign in to comment.