Skip to content

Commit

Permalink
[PoC] Additional params in the Financial Connections sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
mats-stripe committed Sep 12, 2024
1 parent 23be946 commit 25370a2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import UIKit
apiClient: STPAPIClient,
clientSecret: String,
returnURL: String?,
additionalParameters: [String: Any],
onEvent: ((FinancialConnectionsEvent) -> Void)?,
from presentingViewController: UIViewController,
completion: @escaping (FinancialConnectionsSDKResult) -> Void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class HostController {
private let returnURL: String?
private let analyticsClient: FinancialConnectionsAnalyticsClient
private let analyticsClientV1: STPAnalyticsClientProtocol
private let additionalParameters: [String: Any]

private var nativeFlowController: NativeFlowController?
lazy var hostViewController = HostViewController(
Expand All @@ -57,6 +58,13 @@ class HostController {

weak var delegate: HostControllerDelegate?

private var isPantherPayment: Bool {
guard let linkMode = additionalParameters["link_mode"] as? String else {
return false
}
return linkMode == "link_card_brand"
}

// MARK: - Init

init(
Expand All @@ -65,13 +73,15 @@ class HostController {
clientSecret: String,
returnURL: String?,
publishableKey: String?,
stripeAccount: String?
stripeAccount: String?,
additionalParameters: [String: Any]
) {
self.apiClient = apiClient
self.analyticsClientV1 = analyticsClientV1
self.clientSecret = clientSecret
self.returnURL = returnURL
self.analyticsClient = FinancialConnectionsAnalyticsClient()
self.additionalParameters = additionalParameters
analyticsClient.setAdditionalParameters(
linkAccountSessionClientSecret: clientSecret,
publishableKey: publishableKey,
Expand Down Expand Up @@ -171,7 +181,8 @@ private extension HostController {
accountPickerPane: synchronizePayload.text?.accountPickerPane,
apiClient: apiClient,
clientSecret: clientSecret,
analyticsClient: analyticsClient
analyticsClient: analyticsClient,
isPantherPayment: isPantherPayment
)
nativeFlowController = NativeFlowController(
dataManager: dataManager,
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?,
additionalParameters: [String: Any],
onEvent: ((StripeCore.FinancialConnectionsEvent) -> Void)?,
from presentingViewController: UIViewController,
completion: @escaping (FinancialConnectionsSDKResult) -> Void
Expand All @@ -30,6 +31,7 @@ public class FinancialConnectionsSDKImplementation: FinancialConnectionsSDKInter
)
financialConnectionsSheet.apiClient = apiClient
financialConnectionsSheet.onEvent = onEvent
financialConnectionsSheet.additionalParameters = additionalParameters
// 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 @@ -77,6 +77,9 @@ final public class FinancialConnectionsSheet {
// Analytics client to use for logging analytics
@_spi(STP) public let analyticsClient: STPAnalyticsClientProtocol

// Any additional parameters useful for the financial connections SDK to know.
@_spi(STP) public var additionalParameters: [String: Any] = [:]

// MARK: - Init

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ protocol NativeFlowDataManager: AnyObject {
var lastPaneLaunched: FinancialConnectionsSessionManifest.NextPane? { get set }
var customSuccessPaneCaption: String? { get set }
var customSuccessPaneSubCaption: String? { get set }
var isPantherPayment: Bool { get }

func createPaymentDetails(
consumerSessionClientSecret: String,
Expand Down Expand Up @@ -83,6 +84,7 @@ class NativeFlowAPIDataManager: NativeFlowDataManager {
let apiClient: FinancialConnectionsAPIClient
let clientSecret: String
let analyticsClient: FinancialConnectionsAnalyticsClient
let isPantherPayment: Bool

var institution: FinancialConnectionsInstitution?
var authSession: FinancialConnectionsAuthSession?
Expand Down Expand Up @@ -117,7 +119,8 @@ class NativeFlowAPIDataManager: NativeFlowDataManager {
accountPickerPane: FinancialConnectionsAccountPickerPane?,
apiClient: FinancialConnectionsAPIClient,
clientSecret: String,
analyticsClient: FinancialConnectionsAnalyticsClient
analyticsClient: FinancialConnectionsAnalyticsClient,
isPantherPayment: Bool
) {
self.manifest = manifest
self.visualUpdate = visualUpdate
Expand All @@ -131,6 +134,7 @@ class NativeFlowAPIDataManager: NativeFlowDataManager {
self.authSession = manifest.activeAuthSession
// If the server returns active institution use that, otherwise resort to initial institution.
self.institution = manifest.activeInstitution ?? manifest.initialInstitution
self.isPantherPayment = isPantherPayment
didUpdateManifest()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ final class FinancialConnectionsWebFlowViewController: UIViewController {
private let sessionFetcher: FinancialConnectionsSessionFetcher
private let manifest: FinancialConnectionsSessionManifest
private let returnURL: String?
private let isPantherPayment: Bool

// MARK: - UI

Expand All @@ -94,13 +95,15 @@ final class FinancialConnectionsWebFlowViewController: UIViewController {
apiClient: FinancialConnectionsAPIClient,
manifest: FinancialConnectionsSessionManifest,
sessionFetcher: FinancialConnectionsSessionFetcher,
returnURL: String?
returnURL: String?,
isPantherPayment: Bool
) {
self.clientSecret = clientSecret
self.apiClient = apiClient
self.manifest = manifest
self.sessionFetcher = sessionFetcher
self.returnURL = returnURL
self.isPantherPayment = isPantherPayment
super.init(nibName: nil, bundle: nil)
}

Expand Down Expand Up @@ -153,6 +156,9 @@ extension FinancialConnectionsWebFlowViewController {
var additionalQueryParameters = additionalQueryParameters
if manifest.isProductInstantDebits {
additionalQueryParameters = (additionalQueryParameters ?? "") + "&return_payment_method=true"
if isPantherPayment {
additionalQueryParameters = (additionalQueryParameters ?? "") + "&link_mode=link_card_brand"
}
}
authSessionManager?
.start(additionalQueryParameters: additionalQueryParameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public class STPBankAccountCollector: NSObject {
apiClient: self.apiClient,
clientSecret: linkAccountSession.clientSecret,
returnURL: returnURL,
additionalParameters: additionalParameters,
onEvent: onEvent,
from: viewController
) { result in
Expand Down Expand Up @@ -507,6 +508,7 @@ public class STPBankAccountCollector: NSObject {
apiClient: self.apiClient,
clientSecret: linkAccountSession.clientSecret,
returnURL: returnURL,
additionalParameters: additionalParameters,
onEvent: onEvent,
from: viewController
) { result in
Expand Down Expand Up @@ -596,6 +598,7 @@ public class STPBankAccountCollector: NSObject {
apiClient: self.apiClient,
clientSecret: linkAccountSession.clientSecret,
returnURL: returnURL,
additionalParameters: additionalParameters,
onEvent: onEvent,
from: viewController
) { result in
Expand Down

0 comments on commit 25370a2

Please sign in to comment.