Skip to content

Commit ced6d1d

Browse files
Move consumer session creation before verification screens (#4632)
## Summary <!-- Simple summary of what was changed. --> This pull request aligns the Financial Connections iOS SDK with Android and Web, where we create a consumer session before we display any verification screens. This removes a decent amount of error handling code (for very unlikely errors) and will make implementing #4272 correctly easier. ## Motivation <!-- Why are you making this change? If it's for fixing a bug, if possible, please include a code snippet or example project that demonstrates the issue. --> ## Testing <!-- How was the code tested? Be as specific as possible. --> ## Changelog <!-- Is this a notable change that affects users? If so, add a line to `CHANGELOG.md` and prefix the line with one of the following: - [Added] for new features. - [Changed] for changes in existing functionality. - [Deprecated] for soon-to-be removed features. - [Removed] for now removed features. - [Fixed] for any bug fixes. - [Security] in case of vulnerabilities. --> --------- Co-authored-by: Mat Schmid <[email protected]>
1 parent 934574c commit ced6d1d

11 files changed

+188
-383
lines changed

StripeFinancialConnections/StripeFinancialConnections/Source/Native/NativeFlowController.swift

+21-60
Original file line numberDiff line numberDiff line change
@@ -1031,8 +1031,12 @@ extension NativeFlowController: NetworkingLinkSignupViewControllerDelegate {
10311031
extension NativeFlowController: NetworkingLinkLoginWarmupViewControllerDelegate {
10321032

10331033
func networkingLinkLoginWarmupViewControllerDidSelectContinue(
1034-
_ viewController: NetworkingLinkLoginWarmupViewController
1034+
_ viewController: NetworkingLinkLoginWarmupViewController,
1035+
withSession consumerSession: ConsumerSessionData,
1036+
consumerPublishableKey: String
10351037
) {
1038+
dataManager.consumerSession = consumerSession
1039+
dataManager.consumerPublishableKey = consumerPublishableKey
10361040
pushPane(.networkingLinkVerification, animated: true)
10371041
}
10381042

@@ -1063,6 +1067,17 @@ extension NativeFlowController: NetworkingLinkLoginWarmupViewControllerDelegate
10631067
) {
10641068
showTerminalError(error)
10651069
}
1070+
1071+
func networkingLinkLoginWarmupViewControllerDidFailAttestationVerdict(
1072+
_ viewController: NetworkingLinkLoginWarmupViewController,
1073+
prefillDetails: WebPrefillDetails
1074+
) {
1075+
delegate?.nativeFlowController(
1076+
self,
1077+
shouldLaunchWebFlow: dataManager.manifest,
1078+
prefillDetails: prefillDetails
1079+
)
1080+
}
10661081
}
10671082

10681083
// MARK: - TerminalErrorViewControllerDelegate
@@ -1119,10 +1134,6 @@ extension NativeFlowController: AttachLinkedPaymentAccountViewControllerDelegate
11191134
// MARK: - NetworkingLinkVerificationViewControllerDelegate
11201135

11211136
extension NativeFlowController: NetworkingLinkVerificationViewControllerDelegate {
1122-
func networkingLinkVerificationViewController(_ viewController: NetworkingLinkVerificationViewController, didReceiveConsumerPublishableKey consumerPublishableKey: String) {
1123-
dataManager.consumerPublishableKey = consumerPublishableKey
1124-
}
1125-
11261137
func networkingLinkVerificationViewController(
11271138
_ viewController: NetworkingLinkVerificationViewController,
11281139
didRequestNextPane nextPane: FinancialConnectionsSessionManifest.NextPane,
@@ -1139,17 +1150,6 @@ extension NativeFlowController: NetworkingLinkVerificationViewControllerDelegate
11391150
) {
11401151
showTerminalError(error)
11411152
}
1142-
1143-
func networkingLinkVerificationViewControllerDidFailAttestationVerdict(
1144-
_ viewController: NetworkingLinkVerificationViewController,
1145-
prefillDetails: WebPrefillDetails
1146-
) {
1147-
delegate?.nativeFlowController(
1148-
self,
1149-
shouldLaunchWebFlow: dataManager.manifest,
1150-
prefillDetails: prefillDetails
1151-
)
1152-
}
11531153
}
11541154

11551155
// MARK: - LinkAccountPickerViewControllerDelegate
@@ -1219,10 +1219,6 @@ extension NativeFlowController: LinkAccountPickerViewControllerDelegate {
12191219

12201220
extension NativeFlowController: NetworkingSaveToLinkVerificationViewControllerDelegate {
12211221

1222-
func networkingSaveToLinkVerificationViewController(_ viewController: NetworkingSaveToLinkVerificationViewController, didReceiveConsumerPublishableKey consumerPublishableKey: String) {
1223-
dataManager.consumerPublishableKey = consumerPublishableKey
1224-
}
1225-
12261222
func networkingSaveToLinkVerificationViewControllerDidFinish(
12271223
_ viewController: NetworkingSaveToLinkVerificationViewController,
12281224
saveToLinkWithStripeSucceeded: Bool?,
@@ -1241,27 +1237,12 @@ extension NativeFlowController: NetworkingSaveToLinkVerificationViewControllerDe
12411237
) {
12421238
showTerminalError(error)
12431239
}
1244-
1245-
func networkingSaveToLinkVerificationViewControllerDidFailAttestationVerdict(
1246-
_ viewController: NetworkingSaveToLinkVerificationViewController,
1247-
prefillDetails: WebPrefillDetails
1248-
) {
1249-
delegate?.nativeFlowController(
1250-
self,
1251-
shouldLaunchWebFlow: dataManager.manifest,
1252-
prefillDetails: prefillDetails
1253-
)
1254-
}
12551240
}
12561241

12571242
// MARK: - NetworkingLinkStepUpVerificationViewControllerDelegate
12581243

12591244
extension NativeFlowController: NetworkingLinkStepUpVerificationViewControllerDelegate {
12601245

1261-
func networkingLinkStepUpVerificationViewController(_ viewController: NetworkingLinkStepUpVerificationViewController, didReceiveConsumerPublishableKey consumerPublishableKey: String) {
1262-
dataManager.consumerPublishableKey = consumerPublishableKey
1263-
}
1264-
12651246
func networkingLinkStepUpVerificationViewController(
12661247
_ viewController: NetworkingLinkStepUpVerificationViewController,
12671248
didCompleteVerificationWithInstitution institution: FinancialConnectionsInstitution?,
@@ -1281,23 +1262,6 @@ extension NativeFlowController: NetworkingLinkStepUpVerificationViewControllerDe
12811262
) {
12821263
showTerminalError(error)
12831264
}
1284-
1285-
func networkingLinkStepUpVerificationViewControllerEncounteredSoftError(
1286-
_ viewController: NetworkingLinkStepUpVerificationViewController
1287-
) {
1288-
pushPane(.institutionPicker, animated: true)
1289-
}
1290-
1291-
func networkingLinkStepUpVerificationViewControllerDidFailAttestationVerdict(
1292-
_ viewController: NetworkingLinkStepUpVerificationViewController,
1293-
prefillDetails: WebPrefillDetails
1294-
) {
1295-
delegate?.nativeFlowController(
1296-
self,
1297-
shouldLaunchWebFlow: dataManager.manifest,
1298-
prefillDetails: prefillDetails
1299-
)
1300-
}
13011265
}
13021266

13031267
// MARK: - LinkLoginViewControllerDelegate
@@ -1538,15 +1502,13 @@ private func CreatePaneViewController(
15381502
networkingLinkSignupViewController.delegate = nativeFlowController
15391503
viewController = networkingLinkSignupViewController
15401504
case .networkingLinkVerification:
1541-
let accountholderCustomerEmailAddress = dataManager.manifest.accountholderCustomerEmailAddress
1542-
let consumerSessionEmailAddress = dataManager.consumerSession?.emailAddress
1543-
if let accountholderCustomerEmailAddress = consumerSessionEmailAddress ?? accountholderCustomerEmailAddress {
1505+
if let consumerSession = dataManager.consumerSession {
15441506
let networkingLinkVerificationDataSource = NetworkingLinkVerificationDataSourceImplementation(
1545-
accountholderCustomerEmailAddress: accountholderCustomerEmailAddress,
15461507
manifest: dataManager.manifest,
15471508
apiClient: dataManager.apiClient,
15481509
clientSecret: dataManager.clientSecret,
15491510
returnURL: dataManager.returnURL,
1511+
consumerSession: consumerSession,
15501512
analyticsClient: dataManager.analyticsClient
15511513
)
15521514
let networkingLinkVerificationViewController = NetworkingLinkVerificationViewController(dataSource: networkingLinkVerificationDataSource)
@@ -1557,9 +1519,7 @@ private func CreatePaneViewController(
15571519
viewController = nil
15581520
}
15591521
case .networkingSaveToLinkVerification:
1560-
if
1561-
let consumerSession = dataManager.consumerSession
1562-
{
1522+
if let consumerSession = dataManager.consumerSession {
15631523
let networkingSaveToLinkVerificationDataSource = NetworkingSaveToLinkVerificationDataSourceImplementation(
15641524
manifest: dataManager.manifest,
15651525
consumerSession: consumerSession,
@@ -1667,7 +1627,8 @@ private func CreatePaneViewController(
16671627
apiClient: dataManager.apiClient,
16681628
clientSecret: dataManager.clientSecret,
16691629
analyticsClient: dataManager.analyticsClient,
1670-
nextPaneOrDrawerOnSecondaryCta: parameters?.nextPaneOrDrawerOnSecondaryCta
1630+
nextPaneOrDrawerOnSecondaryCta: parameters?.nextPaneOrDrawerOnSecondaryCta,
1631+
elementsSessionContext: dataManager.elementsSessionContext
16711632
)
16721633
let networkingLinkWarmupViewController = NetworkingLinkLoginWarmupViewController(
16731634
dataSource: networkingLinkWarmupDataSource,

StripeFinancialConnections/StripeFinancialConnections/Source/Native/NetworkingLinkLoginWarmup/NetworkingLinkLoginWarmupDataSource.swift

+47-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ import Foundation
1111
protocol NetworkingLinkLoginWarmupDataSource: AnyObject {
1212
var manifest: FinancialConnectionsSessionManifest { get }
1313
var analyticsClient: FinancialConnectionsAnalyticsClient { get }
14+
var email: String? { get }
1415

16+
func lookupConsumerSession() -> Future<LookupConsumerSessionResponse>
1517
func disableNetworking() -> Future<FinancialConnectionsSessionManifest>
18+
func completeAssertionIfNeeded(
19+
possibleError: Error?,
20+
api: FinancialConnectionsAPIClientLogger.API
21+
) -> Error?
1622
}
1723

1824
final class NetworkingLinkLoginWarmupDataSourceImplementation: NetworkingLinkLoginWarmupDataSource {
@@ -22,19 +28,46 @@ final class NetworkingLinkLoginWarmupDataSourceImplementation: NetworkingLinkLog
2228
private let clientSecret: String
2329
let analyticsClient: FinancialConnectionsAnalyticsClient
2430
private let nextPaneOrDrawerOnSecondaryCta: String?
31+
private let elementsSessionContext: ElementsSessionContext?
32+
33+
var email: String? {
34+
manifest.accountholderCustomerEmailAddress ?? elementsSessionContext?.prefillDetails?.email
35+
}
2536

2637
init(
2738
manifest: FinancialConnectionsSessionManifest,
2839
apiClient: any FinancialConnectionsAPI,
2940
clientSecret: String,
3041
analyticsClient: FinancialConnectionsAnalyticsClient,
31-
nextPaneOrDrawerOnSecondaryCta: String?
42+
nextPaneOrDrawerOnSecondaryCta: String?,
43+
elementsSessionContext: ElementsSessionContext?
3244
) {
3345
self.manifest = manifest
3446
self.apiClient = apiClient
3547
self.clientSecret = clientSecret
3648
self.analyticsClient = analyticsClient
3749
self.nextPaneOrDrawerOnSecondaryCta = nextPaneOrDrawerOnSecondaryCta
50+
self.elementsSessionContext = elementsSessionContext
51+
}
52+
53+
func lookupConsumerSession() -> Future<LookupConsumerSessionResponse> {
54+
guard let email else {
55+
let error = FinancialConnectionsSheetError.unknown(debugDescription: "Unexpected nil email in warmup data source")
56+
analyticsClient.logUnexpectedError(
57+
error,
58+
errorName: "NoEmailInWarmupPaneError",
59+
pane: .networkingLinkLoginWarmup
60+
)
61+
return Promise(error: error)
62+
}
63+
return apiClient.consumerSessionLookup(
64+
emailAddress: email,
65+
clientSecret: clientSecret,
66+
sessionId: manifest.id,
67+
emailSource: .customerObject,
68+
useMobileEndpoints: manifest.verified,
69+
pane: .networkingLinkLoginWarmup
70+
)
3871
}
3972

4073
func disableNetworking() -> Future<FinancialConnectionsSessionManifest> {
@@ -44,4 +77,17 @@ final class NetworkingLinkLoginWarmupDataSourceImplementation: NetworkingLinkLog
4477
clientSecret: clientSecret
4578
)
4679
}
80+
81+
// Marks the assertion as completed and logs possible errors during verified flows.
82+
func completeAssertionIfNeeded(
83+
possibleError: Error?,
84+
api: FinancialConnectionsAPIClientLogger.API
85+
) -> Error? {
86+
guard manifest.verified else { return nil }
87+
return apiClient.completeAssertion(
88+
possibleError: possibleError,
89+
api: api,
90+
pane: .networkingLinkLoginWarmup
91+
)
92+
}
4793
}

0 commit comments

Comments
 (0)