Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Financial Connections: added extra networking support for non- payment flows #3110

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ struct PlaygroundMainView: View {
.italic()
}

Toggle("Enable Data Mode", isOn: $viewModel.enableDataMode)

Toggle("Enable Test Mode", isOn: $viewModel.enableTestMode)
// test mode color
.toggleStyle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ final class PlaygroundMainViewModel: ObservableObject {
}
}

@Published var enableDataMode: Bool = PlaygroundUserDefaults.enableDataMode {
didSet {
PlaygroundUserDefaults.enableDataMode = enableDataMode
}
}

@Published var email: String = PlaygroundUserDefaults.email {
didSet {
PlaygroundUserDefaults.email = email
Expand Down Expand Up @@ -162,7 +168,8 @@ final class PlaygroundMainViewModel: ObservableObject {
enableBalancesPermission: enableBalancesPermission,
customScenario: customScenario.rawValue,
customPublicKey: customPublicKey,
customSecretKey: customSecretKey
customSecretKey: customSecretKey,
enableDataMode: enableDataMode
) { [weak self] setupPlaygroundResponse in
if let setupPlaygroundResponse = setupPlaygroundResponse {
PresentFinancialConnectionsSheet(
Expand Down Expand Up @@ -231,6 +238,7 @@ private func SetupPlayground(
customScenario: String,
customPublicKey: String,
customSecretKey: String,
enableDataMode: Bool,
completionHandler: @escaping ([String: String]?) -> Void
) {
if !enableTestMode && email == "[email protected]" {
Expand All @@ -253,6 +261,7 @@ private func SetupPlayground(
requestBody["custom_scenario"] = customScenario
requestBody["custom_public_key"] = customPublicKey
requestBody["custom_secret_key"] = customSecretKey
requestBody["enable_data_mode"] = enableDataMode
return try! JSONSerialization.data(
withJSONObject: requestBody,
options: .prettyPrinted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ final class PlaygroundUserDefaults {
)
static var enableAppToApp: Bool

@UserDefault(
key: "FINANCIAL_CONNECTIONS_EXAMPLE_APP_ENABLE_DATA_MODE",
defaultValue: false
)
static var enableDataMode: Bool

@UserDefault(
key: "FINANCIAL_CONNECTIONS_EXAMPLE_APP_ENABLE_TEST_MODE",
defaultValue: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@ struct FinancialConnectionsSessionManifest: Decodable {
let accountholderCustomerEmailAddress: String?
let accountholderPhoneNumber: String?
let stepUpAuthenticationRequired: Bool?

var shouldAttachLinkedPaymentMethod: Bool {
return (paymentMethodType != nil)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ protocol AccountPickerDataSource: AnyObject {
var selectedAccounts: [FinancialConnectionsPartnerAccount] { get }
var analyticsClient: FinancialConnectionsAnalyticsClient { get }
var reduceManualEntryProminenceInErrors: Bool { get }
var consumerSessionClientSecret: String? { get }

func pollAuthSessionAccounts() -> Future<FinancialConnectionsAuthSessionAccounts>
func updateSelectedAccounts(_ selectedAccounts: [FinancialConnectionsPartnerAccount])
func selectAuthSessionAccounts() -> Promise<FinancialConnectionsAuthSessionAccounts>
func saveToLink(consumerSessionClientSecret: String) -> Future<Void>
}

final class AccountPickerDataSourceImplementation: AccountPickerDataSource {
Expand All @@ -39,6 +41,7 @@ final class AccountPickerDataSourceImplementation: AccountPickerDataSource {
let institution: FinancialConnectionsInstitution
let analyticsClient: FinancialConnectionsAnalyticsClient
let reduceManualEntryProminenceInErrors: Bool
let consumerSessionClientSecret: String?

private(set) var selectedAccounts: [FinancialConnectionsPartnerAccount] = [] {
didSet {
Expand All @@ -54,7 +57,8 @@ final class AccountPickerDataSourceImplementation: AccountPickerDataSource {
manifest: FinancialConnectionsSessionManifest,
institution: FinancialConnectionsInstitution,
analyticsClient: FinancialConnectionsAnalyticsClient,
reduceManualEntryProminenceInErrors: Bool
reduceManualEntryProminenceInErrors: Bool,
consumerSessionClientSecret: String?
) {
self.apiClient = apiClient
self.clientSecret = clientSecret
Expand All @@ -63,6 +67,7 @@ final class AccountPickerDataSourceImplementation: AccountPickerDataSource {
self.institution = institution
self.analyticsClient = analyticsClient
self.reduceManualEntryProminenceInErrors = reduceManualEntryProminenceInErrors
self.consumerSessionClientSecret = consumerSessionClientSecret
}

func pollAuthSessionAccounts() -> Future<FinancialConnectionsAuthSessionAccounts> {
Expand All @@ -84,6 +89,20 @@ final class AccountPickerDataSourceImplementation: AccountPickerDataSource {
selectedAccountIds: selectedAccounts.map({ $0.id })
)
}

func saveToLink(consumerSessionClientSecret: String) -> Future<Void> {
return apiClient.saveAccountsToLink(
emailAddress: nil,
phoneNumber: nil,
country: nil,
selectedAccountIds: selectedAccounts.map({ $0.id }),
consumerSessionClientSecret: consumerSessionClientSecret,
clientSecret: clientSecret
)
.chained { _ in
return Promise(value: ())
}
}
}

private func AuthSessionAccountsInitialPollDelay(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import UIKit
protocol AccountPickerViewControllerDelegate: AnyObject {
func accountPickerViewController(
_ viewController: AccountPickerViewController,
didSelectAccounts selectedAccounts: [FinancialConnectionsPartnerAccount]
didSelectAccounts selectedAccounts: [FinancialConnectionsPartnerAccount],
nextPane: FinancialConnectionsSessionManifest.NextPane?
)
func accountPickerViewControllerDidSelectAnotherBank(_ viewController: AccountPickerViewController)
func accountPickerViewControllerDidSelectManualEntry(_ viewController: AccountPickerViewController)
Expand Down Expand Up @@ -167,7 +168,8 @@ final class AccountPickerViewController: UIViewController {
} else if shouldSkipAccountSelection {
self.delegate?.accountPickerViewController(
self,
didSelectAccounts: accounts
didSelectAccounts: accounts,
nextPane: nil
)
} else if self.dataSource.manifest.singleAccount,
self.dataSource.authSession.institutionSkipAccountSelection ?? false,
Expand Down Expand Up @@ -341,10 +343,31 @@ final class AccountPickerViewController: UIViewController {
guard let self = self else { return }
switch result {
case .success(let linkedAccounts):
self.delegate?.accountPickerViewController(
self,
didSelectAccounts: linkedAccounts.data
)
if
self.dataSource.manifest.isNetworkingUserFlow == true,
self.dataSource.manifest.accountholderIsLinkConsumer == true,
!self.dataSource.manifest.shouldAttachLinkedPaymentMethod,
numberOfSelectedAccounts > 0,
let consumerSessionClientSecret = self.dataSource.consumerSessionClientSecret
{
self.dataSource.saveToLink(
consumerSessionClientSecret: consumerSessionClientSecret
)
.observe { [weak self] _ in
guard let self = self else { return }
self.delegate?.accountPickerViewController(
self,
didSelectAccounts: linkedAccounts.data,
nextPane: .success
)
}
} else {
self.delegate?.accountPickerViewController(
self,
didSelectAccounts: linkedAccounts.data,
nextPane: linkedAccounts.nextPane
)
}
case .failure(let error):
self.dataSource
.analyticsClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,16 @@ extension NativeFlowController: AccountPickerViewControllerDelegate {

func accountPickerViewController(
_ viewController: AccountPickerViewController,
didSelectAccounts selectedAccounts: [FinancialConnectionsPartnerAccount]
didSelectAccounts selectedAccounts: [FinancialConnectionsPartnerAccount],
nextPane: FinancialConnectionsSessionManifest.NextPane?
) {
dataManager.linkedAccounts = selectedAccounts

// if let nextPane = nextPane {
//
// }

let shouldAttachLinkedPaymentAccount = (dataManager.manifest.paymentMethodType != nil)
if shouldAttachLinkedPaymentAccount {
if dataManager.manifest.shouldAttachLinkedPaymentMethod {
// this prevents an unnecessary push transition when presenting `attachLinkedPaymentAccount`
//
// `attachLinkedPaymentAccount` looks the same as the last step of `accountPicker`
Expand Down Expand Up @@ -886,7 +890,8 @@ private func CreatePaneViewController(
manifest: dataManager.manifest,
institution: institution,
analyticsClient: dataManager.analyticsClient,
reduceManualEntryProminenceInErrors: dataManager.reduceManualEntryProminenceInErrors
reduceManualEntryProminenceInErrors: dataManager.reduceManualEntryProminenceInErrors,
consumerSessionClientSecret: dataManager.consumerSession?.clientSecret
)
let accountPickerViewController = AccountPickerViewController(dataSource: accountPickerDataSource)
accountPickerViewController.delegate = nativeFlowController
Expand Down