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

Pass email and phone from MPE to Link Login pane #4182

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,33 @@ import Foundation
case setup(String)
}

/// These fields will be used to prefill the Financial Connections Link Login pane.
@_spi(STP) public struct PrefillDetails {
@_spi(STP) public let email: String?
@_spi(STP) public let phoneNumber: String?

@_spi(STP) public init(email: String?, phoneNumber: String?) {
self.email = email
self.phoneNumber = phoneNumber
}
}

@_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 init(
amount: Int?,
currency: String?,
prefillDetails: PrefillDetails?,
intentId: IntentID?,
linkMode: LinkMode?
) {
self.amount = amount
self.currency = currency
self.prefillDetails = prefillDetails
self.intentId = intentId
self.linkMode = linkMode
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation

protocol LinkLoginDataSource: AnyObject {
var manifest: FinancialConnectionsSessionManifest { get }
var elementsSessionContext: ElementsSessionContext? { get }
var analyticsClient: FinancialConnectionsAnalyticsClient { get }

func synchronize() -> Future<FinancialConnectionsLinkLoginPane>
Expand All @@ -28,12 +29,12 @@ final class LinkLoginDataSourceImplementation: LinkLoginDataSource {
private static let deallocatedError = FinancialConnectionsSheetError.unknown(debugDescription: "data source deallocated")

let manifest: FinancialConnectionsSessionManifest
let elementsSessionContext: ElementsSessionContext?
let analyticsClient: FinancialConnectionsAnalyticsClient

private let clientSecret: String
private let returnURL: String?
private let apiClient: FinancialConnectionsAPIClient
private let elementsSessionContext: ElementsSessionContext?

init(
manifest: FinancialConnectionsSessionManifest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ final class LinkLoginViewController: UIViewController {
paneLayoutView?.scrollView.keyboardDismissMode = .onDrag
#endif

let emailAddress = dataSource.manifest.accountholderCustomerEmailAddress
let emailAddress = dataSource.manifest.accountholderCustomerEmailAddress ?? dataSource.elementsSessionContext?.prefillDetails?.email
if let emailAddress, !emailAddress.isEmpty {
formView.prefillEmailAddress(emailAddress)

let phoneNumber = dataSource.manifest.accountholderPhoneNumber ?? dataSource.elementsSessionContext?.prefillDetails?.phoneNumber
formView.prefillPhoneNumber(phoneNumber)
} else {
// Slightly delay opening the keyboard to avoid a janky animation.
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { [weak self] in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ final class LinkSignupFormView: UIView {
emailTextField.text = emailAddress
}

func prefillPhoneNumber(_ phoneNumber: String?) {
guard let phoneNumber, !phoneNumber.isEmpty else {
return
}
phoneTextField.text = phoneNumber
}

func beginEditingEmailAddressField() {
_ = emailTextField.becomeFirstResponder()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,15 @@ extension PaymentMethodFormViewController {
}
}()

let prefillDetails = ElementsSessionContext.PrefillDetails(
email: instantDebitsFormElement?.email ?? configuration.defaultBillingDetails.name,
phoneNumber: instantDebitsFormElement?.phone ?? configuration.defaultBillingDetails.phone
)
let linkMode = elementsSession.linkSettings?.linkMode
return ElementsSessionContext(
amount: intent.amount,
currency: intent.currency,
prefillDetails: prefillDetails,
intentId: intentId,
linkMode: linkMode
)
Expand Down
Loading