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

Added identifiers ui elements #2014

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
51 changes: 51 additions & 0 deletions AdyenComponents/PayTo/PayToComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(LocalizationKey(key: "Email"), configuration.localizationParameters)
item.placeholder = localizedString(LocalizationKey(key: "Email"), 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,
Expand Down Expand Up @@ -233,13 +276,21 @@ public final class PayToComponent: PaymentComponent,
// MARK: - Private

private func appendItemsTo(formVC: FormViewController) {
dynamicContent(formVC)
staticContent(formVC)
}

private func staticContent(_ formVC: FormViewController) {
formVC.append(firstNameInputItem)
formVC.append(lastNameInputItem)
}

private func dynamicContent(_ formVC: FormViewController) {
// TODO: Add business logic to show/hide these
formVC.append(emailInputItem)
formVC.append(abnInputItem)
formVC.append(organizationIDInputItem)
}
}

@_spi(AdyenInternal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

}
Loading