diff --git a/AdyenComponents/PayTo/PayToComponent.swift b/AdyenComponents/PayTo/PayToComponent.swift index 79d48d0926..874205d8e4 100644 --- a/AdyenComponents/PayTo/PayToComponent.swift +++ b/AdyenComponents/PayTo/PayToComponent.swift @@ -19,6 +19,9 @@ public final class PayToComponent: PaymentComponent, static let identifierPickerItem = "identifierPicker" static let firstNameInputItem = "firstNameTextfield" static let lastNameInputItem = "lastNameTextfield" + static let emailInputItem = "emailTextfield" + static let abnInputItem = "abnTextfield" + static let organizationIDInputItem = "organizationIDTextfield" } private enum AccountIdentifiers: String, CustomStringConvertible, CaseIterable { @@ -131,6 +134,7 @@ public final class PayToComponent: PaymentComponent, scopeInstance: self, postfix: ViewIdentifier.phoneNumberItem ) + // TODO: Add translation item.title = localizedString(LocalizationKey(key: "Phone"), configuration.localizationParameters) item.placeholder = localizedString(LocalizationKey(key: "Mobile number"), configuration.localizationParameters) return item @@ -198,6 +202,45 @@ public final class PayToComponent: PaymentComponent, return item }() + /// The account holder email text input item. + internal lazy var emailInputItem: FormTextInputItem = { + let item = FormTextInputItem(style: configuration.style.textField) + // TODO: Add translation + item.title = localizedString(.emailItemTitle, configuration.localizationParameters) + item.placeholder = localizedString(.emailItemPlaceHolder, configuration.localizationParameters) + item.identifier = ViewIdentifierBuilder.build( + scopeInstance: self, + postfix: ViewIdentifier.emailInputItem + ) + return item + }() + + /// The account holder abn text input item. + internal lazy var abnInputItem: FormTextInputItem = { + let item = FormTextInputItem(style: configuration.style.textField) + // TODO: Add translation + item.title = localizedString(LocalizationKey(key: "ABN"), configuration.localizationParameters) + item.placeholder = localizedString(LocalizationKey(key: "ABN"), configuration.localizationParameters) + item.identifier = ViewIdentifierBuilder.build( + scopeInstance: self, + postfix: ViewIdentifier.abnInputItem + ) + return item + }() + + /// The account holder organization ID text input item. + internal lazy var organizationIDInputItem: FormTextInputItem = { + let item = FormTextInputItem(style: configuration.style.textField) + // TODO: Add translation + item.title = localizedString(LocalizationKey(key: "Organization ID"), configuration.localizationParameters) + item.placeholder = localizedString(LocalizationKey(key: "Organization ID"), configuration.localizationParameters) + item.identifier = ViewIdentifierBuilder.build( + scopeInstance: self, + postfix: ViewIdentifier.organizationIDInputItem + ) + return item + }() + private lazy var formViewController: FormViewController = { let formViewController = FormViewController( scrollEnabled: configuration.showsSubmitButton, @@ -220,7 +263,7 @@ public final class PayToComponent: PaymentComponent, formViewController.append(phoneNumberItem) - appendItemsTo(formVC: formViewController) + appendItems(to: formViewController) if configuration.showsSubmitButton { formViewController.append(FormSpacerItem(numberOfSpaces: 2)) @@ -232,13 +275,21 @@ public final class PayToComponent: PaymentComponent, // MARK: - Private - private func appendItemsTo(formVC: FormViewController) { - staticContent(formVC) + private func appendItems(to formViewController: FormViewController) { + addDynamicContent(to: formViewController) + addStaticContent(to: formViewController) + } + + private func addStaticContent(to formViewController: FormViewController) { + formViewController.append(firstNameInputItem) + formViewController.append(lastNameInputItem) } - private func staticContent(_ formVC: FormViewController) { - formVC.append(firstNameInputItem) - formVC.append(lastNameInputItem) + private func addDynamicContent(to formViewController: FormViewController) { + // TODO: Add business logic to show/hide these + formViewController.append(emailInputItem) + formViewController.append(abnInputItem) + formViewController.append(organizationIDInputItem) } } diff --git a/Tests/IntegrationTests/Components Tests/PayTo/PayToComponentTests.swift b/Tests/IntegrationTests/Components Tests/PayTo/PayToComponentTests.swift index a25bd6a09b..5e68be122f 100644 --- a/Tests/IntegrationTests/Components Tests/PayTo/PayToComponentTests.swift +++ b/Tests/IntegrationTests/Components Tests/PayTo/PayToComponentTests.swift @@ -141,4 +141,52 @@ class PayToComponentTests: XCTestCase { XCTAssertNotNil(lastNameInputItem, "last name input field should exist") } + func test_email_textfield_exists() throws { + // Given + let sut = try PayToComponent( + paymentMethod: AdyenCoder.decode(payto), + context: Dummy.context + ) + + sut.viewController.loadViewIfNeeded() + + // Check by accessibility identifier + let emailInputItem: FormTextInputItemView = try XCTUnwrap(sut.viewController.view.findView(with: "AdyenComponents.PayToComponent.emailTextfield")) + + // Then + XCTAssertNotNil(emailInputItem, "email input field should exist") + } + + func test_abn_textfield_exists() throws { + // Given + let sut = try PayToComponent( + paymentMethod: AdyenCoder.decode(payto), + context: Dummy.context + ) + + sut.viewController.loadViewIfNeeded() + + // Check by accessibility identifier + let abnInputItem: FormTextInputItemView = try XCTUnwrap(sut.viewController.view.findView(with: "AdyenComponents.PayToComponent.abnTextfield")) + + // Then + XCTAssertNotNil(abnInputItem, "abn input field should exist") + } + + func test_organizationID_textfield_exists() throws { + // Given + let sut = try PayToComponent( + paymentMethod: AdyenCoder.decode(payto), + context: Dummy.context + ) + + sut.viewController.loadViewIfNeeded() + + // Check by accessibility identifier + let organizationIDInputItem: FormTextInputItemView = try XCTUnwrap(sut.viewController.view.findView(with: "AdyenComponents.PayToComponent.organizationIDTextfield")) + + // Then + XCTAssertNotNil(organizationIDInputItem, "organizationID input field should exist") + } + }