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

[PoC] Update email field in MPE Bank tab once Instant Debits completes #4146

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.
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 @@ -9,16 +9,20 @@ import Foundation

@_spi(STP) public struct InstantDebitsLinkedBank: Equatable {
public let paymentMethodId: String
public let email: String?
public let bankName: String?
public let last4: String?
public let linkMode: LinkMode?

public init(
paymentMethodId: String,
email: String?,
bankName: String?,
last4: String?,
linkMode: LinkMode?
) {
self.paymentMethodId = paymentMethodId
self.email = email
self.bankName = bankName
self.last4 = last4
self.linkMode = linkMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ extension NativeFlowController {
case .success(let paymentMethod):
let linkedBank = InstantDebitsLinkedBank(
paymentMethodId: paymentMethod.id,
email: self.dataManager.consumerSession?.emailAddress,
bankName: bankAccountDetails?.bankName,
last4: bankAccountDetails?.last4,
linkMode: linkMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ extension FinancialConnectionsWebFlowViewController {
{
let instantDebitsLinkedBank = InstantDebitsLinkedBank(
paymentMethodId: paymentMethodId,
email: Self.extractValue(from: returnUrl, key: "email"),
bankName: Self.extractValue(from: returnUrl, key: "bank_name")?
// backend can return "+" instead of a more-common encoding of "%20" for spaces
.replacingOccurrences(of: "+", with: " "),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extension TextFieldElement {
let defaultValue: String?
let cardBrandDropDown: DropdownFieldElement?
let cardFilter: CardBrandFilter
var isEditable: Bool = true

init(defaultValue: String? = nil, cardBrandDropDown: DropdownFieldElement? = nil, cardFilter: CardBrandFilter = .default) {
self.defaultValue = defaultValue
Expand Down Expand Up @@ -197,6 +198,7 @@ extension TextFieldElement {
let cardBrandProvider: () -> (STPCardBrand)
var label = String.Localized.cvc
let disallowedCharacters: CharacterSet = .stp_invertedAsciiDigit
var isEditable: Bool = true

func keyboardProperties(for text: String) -> KeyboardProperties {
return .init(type: .asciiCapableNumberPad, textContentType: nil, autocapitalization: .none)
Expand Down Expand Up @@ -235,6 +237,7 @@ extension TextFieldElement {
let accessibilityLabel: String = String.Localized.expiration_date_accessibility_label
let disallowedCharacters: CharacterSet = .stp_invertedAsciiDigit
let defaultValue: String?
var isEditable: Bool = true
func keyboardProperties(for text: String) -> KeyboardProperties {
return .init(type: .asciiCapableNumberPad, textContentType: nil, autocapitalization: .none)
}
Expand Down Expand Up @@ -316,7 +319,7 @@ extension TextFieldElement {
struct LastFourConfiguration: TextFieldElementConfiguration {
let label = String.Localized.card_brand
let lastFour: String
let isEditable = false
var isEditable = false
let cardBrandDropDown: DropdownFieldElement
let cardFilter: CardBrandFilter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extension TextFieldElement {
struct IBANConfiguration: TextFieldElementConfiguration {
let label: String = STPLocalizedString("IBAN", "Label for an IBAN field")
let defaultValue: String?
var isEditable: Bool = true
func maxLength(for text: String) -> Int {
return 34
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class AddPaymentMethodViewController: UIViewController {
paymentMethodTypesView.selected
}
var paymentOption: PaymentOption? {
paymentMethodFormViewController.paymentOption
print("**** didGet paymentOption, \(paymentMethodFormViewController.paymentOption != nil)")
return paymentMethodFormViewController.paymentOption
}

var overridePrimaryButtonState: OverridePrimaryButtonState? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,13 @@ extension PaymentSheetFormFactory {
}
}

func makeEmail(apiPath: String? = nil) -> PaymentMethodElementWrapper<TextFieldElement> {
func makeEmail(apiPath: String? = nil, isOptional: Bool = false) -> PaymentMethodElementWrapper<TextFieldElement> {
let defaultValue = defaultBillingDetails(emailAPIPath: apiPath).email
let element = TextFieldElement.makeEmail(defaultValue: defaultValue, theme: theme)
let element = TextFieldElement.makeEmail(
defaultValue: defaultValue,
isOptional: isOptional,
theme: theme
)
return PaymentMethodElementWrapper(element) { textField, params in
if let apiPath = apiPath {
params.paymentMethodParams.additionalAPIParameters[apiPath] = textField.text
Expand Down Expand Up @@ -656,7 +660,7 @@ extension PaymentSheetFormFactory {
)
}
}(),
emailElement: makeEmail(),
emailElement: makeEmail(isOptional: true),
theme: theme
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ final class InstantDebitsPaymentMethodElement: ContainerElement {
return [linkedBankInfoSectionElement]
}
private let linkedBankInfoSectionElement: SectionElement
private var linkedBank: InstantDebitsLinkedBank? {
didSet {
// Disable email field if we have a linked bank
emailElement.isEnabled = linkedBank == nil
}
}
private let emailElement: TextFieldElement
private let linkedBankInfoView: BankAccountInfoView
private var linkedBank: InstantDebitsLinkedBank?
private let theme: ElementsAppearance
var presentingViewControllerDelegate: PresentingViewControllerDelegate?

Expand Down Expand Up @@ -65,10 +70,16 @@ final class InstantDebitsPaymentMethodElement: ContainerElement {
}

var enableCTA: Bool {
return STPEmailAddressValidator.stringIsValidEmailAddress(email)
true
}

var email: String {
return emailElement.text
get {
emailElement.text
}
set {
emailElement.setText(newValue)
}
}

init(
Expand Down Expand Up @@ -117,6 +128,9 @@ final class InstantDebitsPaymentMethodElement: ContainerElement {
animated: true
)
}
if let email = linkedBank.email {
self.email = email
}
self.delegate?.didUpdate(element: self)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ extension PaymentMethodFormViewController {
case .completed(let completedResult):
if case .financialConnections(let linkedBank) = completedResult {
usBankAccountFormElement.linkedBank = linkedBank
} else if case .instantDebits(let linkedBank) = completedResult {
self.instantDebitsFormElement?.setLinkedBank(linkedBank)
} else {
self.delegate?.updateErrorLabel(for: genericError)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ class PaymentSheetViewController: UIViewController, PaymentSheetViewControllerPr
callToAction = overridePrimaryButtonState.ctaType
buyButtonStatus = overridePrimaryButtonState.enabled ? .enabled : .disabled
} else {
print("**** buyButtonStatus: \(addPaymentMethodViewController.paymentOption == nil ? "disabled" : "enabled")")
buyButtonStatus = addPaymentMethodViewController.paymentOption == nil ? .disabled : .enabled
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,22 @@ import Foundation
let type: IDNumberType?
public let label: String
public let defaultValue: String?
public var isEditable: Bool

/**
- Parameters:
- type: The type of ID number that should be validated in this input field. If the ID type is unknown, passing `nil` will produce a configuration with no restrictions on the input.
- label: The label of the field
*/
public init(type: IDNumberType?, label: String, defaultValue: String?) {
public init(
type: IDNumberType?,
label: String,
isEditable: Bool = true,
defaultValue: String?
) {
self.type = type
self.label = label
self.isEditable = isEditable
self.defaultValue = defaultValue
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import UIKit
func maxLength(for text: String) -> Int {
return 6
}
var isEditable: Bool = true
let defaultValue: String?
func subLabel(text: String) -> String? {
return BSBNumberProvider.shared.bsbName(for: text)
Expand Down Expand Up @@ -57,6 +58,7 @@ import UIKit
let label = String.Localized.accountNumber
let disallowedCharacters: CharacterSet = .stp_invertedAsciiDigit
let numberOfDigitsRequired = 9
var isEditable: Bool = true

func maxLength(for text: String) -> Int {
return numberOfDigitsRequired
Expand Down Expand Up @@ -85,6 +87,7 @@ import UIKit

let label = STPLocalizedString("Sort code", "Placeholder for Bacs sort code (a bank routing number used in the UK and Ireland)")
let disallowedCharacters: CharacterSet = .stp_invertedAsciiDigit
var isEditable: Bool = true
func maxLength(for text: String) -> Int {
return 6
}
Expand Down Expand Up @@ -120,6 +123,7 @@ import UIKit
let label = String.Localized.accountNumber
let disallowedCharacters: CharacterSet = .stp_invertedAsciiDigit
let numberOfDigitsRequired = 8
var isEditable: Bool = true

func maxLength(for text: String) -> Int {
return numberOfDigitsRequired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import UIKit
case line1Autocompletable(didTapAutocomplete: () -> Void)
}
let lineType: LineType
var isEditable: Bool
var label: String {
switch lineType {
case .line1, .line1Autocompletable:
Expand Down Expand Up @@ -69,24 +70,56 @@ import UIKit
}
return nil
}

init(lineType: LineType, isEditable: Bool = true, defaultValue: String?) {
self.lineType = lineType
self.isEditable = isEditable
self.defaultValue = defaultValue
}
}

public static func makeLine1(defaultValue: String?, theme: ElementsAppearance) -> TextFieldElement {
return TextFieldElement(
configuration: LineConfiguration(lineType: .line1, defaultValue: defaultValue), theme: theme
public static func makeLine1(
defaultValue: String?,
isEditable: Bool = true,
theme: ElementsAppearance
) -> TextFieldElement {
TextFieldElement(
configuration: LineConfiguration(
lineType: .line1,
isEditable: isEditable,
defaultValue: defaultValue
),
theme: theme
)
}

static func makeLine2(defaultValue: String?, theme: ElementsAppearance) -> TextFieldElement {
let line2 = TextFieldElement(
configuration: LineConfiguration(lineType: .line2, defaultValue: defaultValue), theme: theme
static func makeLine2(
defaultValue: String?,
isEditable: Bool = true,
theme: ElementsAppearance
) -> TextFieldElement {
TextFieldElement(
configuration: LineConfiguration(
lineType: .line2,
isEditable: isEditable,
defaultValue: defaultValue
),
theme: theme
)
return line2
}

public static func makeAutoCompleteLine(defaultValue: String?, theme: ElementsAppearance) -> TextFieldElement {
return TextFieldElement(
configuration: LineConfiguration(lineType: .autoComplete, defaultValue: defaultValue), theme: theme
public static func makeAutoCompleteLine(
defaultValue: String?,
isEditable: Bool = true,
theme: ElementsAppearance
) -> TextFieldElement {
TextFieldElement(
configuration: LineConfiguration(
lineType: .autoComplete,
isEditable: isEditable,
defaultValue: defaultValue
),
theme: theme
)
}

Expand All @@ -96,6 +129,7 @@ import UIKit
let label: String
let defaultValue: String?
let isOptional: Bool
var isEditable: Bool = true

func keyboardProperties(for text: String) -> TextFieldElement.KeyboardProperties {
return .init(type: .default, textContentType: .addressCity, autocapitalization: .words)
Expand All @@ -108,6 +142,7 @@ import UIKit
let label: String
let defaultValue: String?
let isOptional: Bool
var isEditable: Bool = true

func keyboardProperties(for text: String) -> TextFieldElement.KeyboardProperties {
return .init(type: .default, textContentType: .addressState, autocapitalization: .words)
Expand All @@ -121,6 +156,7 @@ import UIKit
let label: String
let defaultValue: String?
let isOptional: Bool
var isEditable: Bool = true
public var disallowedCharacters: CharacterSet {
return countryCode == "US" ? .decimalDigits.inverted : .newlines
}
Expand Down
Loading
Loading