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

chore: Added 2-step address lookup #1407

Merged
merged 39 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e6b7e0f
chore: Added 2-step address lookup
goergisn Oct 6, 2023
1529059
Adding documentation
goergisn Oct 6, 2023
8d0d1c3
Refactoring/cleaning up
goergisn Oct 6, 2023
618aef4
Merge branch 'list-item-loading' into advanced-address-lookup
goergisn Oct 6, 2023
08b44eb
Merge branch 'list-item-loading' into advanced-address-lookup
goergisn Oct 9, 2023
a18f2ae
Refactoring
goergisn Oct 11, 2023
fbbba81
Removing Demo files from spell checking
goergisn Oct 11, 2023
d0b7e45
Fixing tests
goergisn Oct 12, 2023
7edb352
Better documentation
goergisn Oct 12, 2023
ecb5e0e
Importing UIKit
goergisn Oct 12, 2023
b957c62
Fixed project config
goergisn Oct 12, 2023
bac832c
Update AddressLookupViewControllerTests.swift
goergisn Oct 12, 2023
649d7c7
Added type annotation to reduce warnings
goergisn Oct 13, 2023
caa0c2a
Refactoring for troubleshooting
goergisn Oct 13, 2023
489c19e
Update spell-check-excluded-files-list
goergisn Oct 13, 2023
7ec65db
adding mapkit to allow list
goergisn Oct 13, 2023
0aecba8
Update CardComponentSettingsView.swift
goergisn Oct 13, 2023
8c2d45e
Update AddressLookupViewControllerTests.swift
goergisn Oct 13, 2023
a649f0f
Helping the compiler out
goergisn Oct 13, 2023
bf43aca
temporarily deactivating one test
goergisn Oct 13, 2023
71dbc1b
Update AddressLookupViewControllerTests.swift
goergisn Oct 13, 2023
53ff564
What is going on
goergisn Oct 13, 2023
90204b4
Small steps
goergisn Oct 13, 2023
7c03326
Update AddressLookupViewControllerTests.swift
goergisn Oct 13, 2023
dd80180
Is it the selection handler access
goergisn Oct 13, 2023
7a53fac
Update AddressLookupViewControllerTests.swift
goergisn Oct 13, 2023
6444456
Update AddressLookupViewControllerTests.swift
goergisn Oct 13, 2023
652333a
Update ListItem.swift
goergisn Oct 13, 2023
ef26253
Merge branch 'list-item-loading' into advanced-address-lookup
goergisn Oct 13, 2023
9877f80
Merge conflicts
goergisn Oct 13, 2023
18ab031
Merge branch 'list-item-loading' into advanced-address-lookup
goergisn Oct 16, 2023
cda066d
Merge branch 'list-item-loading' into advanced-address-lookup
goergisn Oct 16, 2023
334d2b9
Merge branch 'develop' into advanced-address-lookup
goergisn Oct 17, 2023
1ff5d07
Adding documentation
goergisn Oct 19, 2023
c38ed10
Small renaming
goergisn Oct 24, 2023
1f66e87
Update AddressLookupViewControllerTests.swift
goergisn Oct 24, 2023
416de22
Merge branch 'develop' into advanced-address-lookup
goergisn Oct 30, 2023
e7f924f
Merge branch 'develop' into advanced-address-lookup
goergisn Oct 31, 2023
d577a19
Merge branch 'develop' into advanced-address-lookup
goergisn Nov 1, 2023
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
24 changes: 18 additions & 6 deletions Adyen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,12 @@
81896E852A4DB5F300C532CA /* SearchViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81896E842A4DB5F300C532CA /* SearchViewControllerTests.swift */; };
8191838E2A53062F008EB61A /* FormAddressItem+Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8191838D2A53062F008EB61A /* FormAddressItem+Configuration.swift */; };
81A2E3BE2A5C453200CF5F9C /* LinkTextViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A2E3BD2A5C453200CF5F9C /* LinkTextViewTests.swift */; };
81A48DBB2A5709F600242341 /* AddressLookupProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A48DBA2A5709F600242341 /* AddressLookupProvider.swift */; };
81A48DBC2A5709F600242341 /* AddressLookupProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A48DBA2A5709F600242341 /* AddressLookupProvider.swift */; };
81A48DBB2A5709F600242341 /* DemoAddressLookupProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A48DBA2A5709F600242341 /* DemoAddressLookupProvider.swift */; };
81A48DBC2A5709F600242341 /* DemoAddressLookupProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A48DBA2A5709F600242341 /* DemoAddressLookupProvider.swift */; };
81A48DC62A5800EA00242341 /* AddressLookupViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A48DC32A58004A00242341 /* AddressLookupViewControllerTests.swift */; };
81AA3B342ACD9CE800F5719D /* AddressLookupProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81AA3B332ACD9CE800F5719D /* AddressLookupProvider.swift */; };
81AA3B362AD02EAE00F5719D /* AddressLookupSearchViewController+ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81AA3B352AD02EAE00F5719D /* AddressLookupSearchViewController+ViewModel.swift */; };
81AA3B382AD040D800F5719D /* MapkitAddressLookupProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81AA3B372AD040D800F5719D /* MapkitAddressLookupProvider.swift */; };
81B001B12A543CFD0015BFA3 /* SearchViewController+ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81B001B02A543CFD0015BFA3 /* SearchViewController+ViewModel.swift */; };
81B001B62A5470950015BFA3 /* AddressLookupViewController+ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81B001B52A5470950015BFA3 /* AddressLookupViewController+ViewModel.swift */; };
81B001B72A5470EA0015BFA3 /* AddressLookupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81B001B22A5468220015BFA3 /* AddressLookupViewController.swift */; };
Expand Down Expand Up @@ -1338,8 +1341,11 @@
8191838D2A53062F008EB61A /* FormAddressItem+Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FormAddressItem+Configuration.swift"; sourceTree = "<group>"; };
81A2E3BD2A5C453200CF5F9C /* LinkTextViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinkTextViewTests.swift; sourceTree = "<group>"; };
81A2E3BF2A5C453F00CF5F9C /* LinkTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LinkTextView.swift; sourceTree = "<group>"; };
81A48DBA2A5709F600242341 /* AddressLookupProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressLookupProvider.swift; sourceTree = "<group>"; };
81A48DBA2A5709F600242341 /* DemoAddressLookupProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoAddressLookupProvider.swift; sourceTree = "<group>"; };
81A48DC32A58004A00242341 /* AddressLookupViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressLookupViewControllerTests.swift; sourceTree = "<group>"; };
81AA3B332ACD9CE800F5719D /* AddressLookupProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressLookupProvider.swift; sourceTree = "<group>"; };
81AA3B352AD02EAE00F5719D /* AddressLookupSearchViewController+ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AddressLookupSearchViewController+ViewModel.swift"; sourceTree = "<group>"; };
81AA3B372AD040D800F5719D /* MapkitAddressLookupProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapkitAddressLookupProvider.swift; sourceTree = "<group>"; };
81B001B02A543CFD0015BFA3 /* SearchViewController+ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SearchViewController+ViewModel.swift"; sourceTree = "<group>"; };
81B001B22A5468220015BFA3 /* AddressLookupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressLookupViewController.swift; sourceTree = "<group>"; };
81B001B52A5470950015BFA3 /* AddressLookupViewController+ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AddressLookupViewController+ViewModel.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2310,7 +2316,8 @@
isa = PBXGroup;
children = (
00A25E5C2A404303001B32B6 /* ComponentCreationError.swift */,
81A48DBA2A5709F600242341 /* AddressLookupProvider.swift */,
81A48DBA2A5709F600242341 /* DemoAddressLookupProvider.swift */,
81AA3B372AD040D800F5719D /* MapkitAddressLookupProvider.swift */,
00ED81BB29EEC48700A6B52C /* DropIn */,
00ED81BA29EEC47C00A6B52C /* Components */,
004BA68229D463C200A8C69B /* Protocols */,
Expand Down Expand Up @@ -2618,6 +2625,7 @@
children = (
81B001B22A5468220015BFA3 /* AddressLookupViewController.swift */,
81B001B52A5470950015BFA3 /* AddressLookupViewController+ViewModel.swift */,
81AA3B332ACD9CE800F5719D /* AddressLookupProvider.swift */,
81BBB3482A66DD5800AF1F9E /* AddressLookupStyle.swift */,
81B001BD2A55B5D00015BFA3 /* Search */,
81B001BE2A55B5D60015BFA3 /* Form */,
Expand All @@ -2629,6 +2637,7 @@
isa = PBXGroup;
children = (
81B001BB2A55B4040015BFA3 /* AddressLookupSearchViewController.swift */,
81AA3B352AD02EAE00F5719D /* AddressLookupSearchViewController+ViewModel.swift */,
81BBB3462A66DAA600AF1F9E /* AddressLookupSearchViewController+Style.swift */,
81C4005F2A3A0AF3007EC51C /* AddressLookupSearchViewController+EmptyView.swift */,
);
Expand Down Expand Up @@ -6265,6 +6274,7 @@
F919DF8F24E682250027976E /* ClientKeyRequest.swift in Sources */,
813EF9EE2A5FE8D900C65D15 /* FormPickerSearchViewController+Style.swift in Sources */,
81BA083F2A4AD96900308160 /* FormValidatableValueItem.swift in Sources */,
81AA3B362AD02EAE00F5719D /* AddressLookupSearchViewController+ViewModel.swift in Sources */,
F9639B2424DC38460073F38A /* PresentationDelegate.swift in Sources */,
E2028F5C2227F1930007FF8B /* Details.swift in Sources */,
5A988BF6265675ED0007F4C0 /* BoletoPaymentMethod.swift in Sources */,
Expand Down Expand Up @@ -6408,6 +6418,7 @@
F92980CE27CF650F000CA5CA /* ActionComponent.swift in Sources */,
F90E95F62728106D007E382B /* DiffableListDataSource.swift in Sources */,
E909342822969AFF00C9F04B /* PaymentComponentData.swift in Sources */,
81AA3B382AD040D800F5719D /* MapkitAddressLookupProvider.swift in Sources */,
F99D454A262716EF00880D72 /* FormErrorItemStyle.swift in Sources */,
E21895E422A7CC4D001B6EE0 /* FormSplitItem.swift in Sources */,
E7D5311424462D87000046B4 /* FormButtonItemView.swift in Sources */,
Expand Down Expand Up @@ -6455,6 +6466,7 @@
0035016C2976B14A00632D8C /* UIImageViewHelpers.swift in Sources */,
00EA4ED4280412140053D938 /* DefaultAddressViewModelBuilder.swift in Sources */,
E7D5311A2446F525000046B4 /* FormSeparatorItem.swift in Sources */,
81AA3B342ACD9CE800F5719D /* AddressLookupProvider.swift in Sources */,
E71E8F3E257921D10054B03D /* StoredBLIKPaymentMethod.swift in Sources */,
C982FFDC2694792F00AED849 /* AffirmPaymentMethod.swift in Sources */,
F9B798C923AB697100A2103C /* FormComponentStyle.swift in Sources */,
Expand Down Expand Up @@ -6748,7 +6760,7 @@
F9CFB05D283541DC002F3B72 /* UIView+Helpers.swift in Sources */,
F9A53C442549887F009000A7 /* DefaultAPIClient.swift in Sources */,
E24FED0D2270915A00A65122 /* CodingHelpers.swift in Sources */,
81A48DBB2A5709F600242341 /* AddressLookupProvider.swift in Sources */,
81A48DBB2A5709F600242341 /* DemoAddressLookupProvider.swift in Sources */,
C9454C37276A340B0086C218 /* BACSDirectDebitPresentationDelegate.swift in Sources */,
004BA67B29D427F300A8C69B /* DropInExample.swift in Sources */,
A09ADA112807142600BF6802 /* SessionRequest.swift in Sources */,
Expand Down Expand Up @@ -7008,7 +7020,7 @@
F99E73CB2624847100EA5B78 /* BalanceCheckRequest.swift in Sources */,
F95B6D982527454E002C9062 /* AppDelegate.swift in Sources */,
F9A53C4B2549887F009000A7 /* Environment.swift in Sources */,
81A48DBC2A5709F600242341 /* AddressLookupProvider.swift in Sources */,
81A48DBC2A5709F600242341 /* DemoAddressLookupProvider.swift in Sources */,
F9A53C512549887F009000A7 /* PaymentsRequest.swift in Sources */,
00ED81B029DD749D00A6B52C /* DropInExample.swift in Sources */,
F9CFB05E283541DC002F3B72 /* UIView+Helpers.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// Copyright (c) 2023 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//

import Foundation

public struct LookupAddressModel {

public let identifier: String
public let postalAddress: PostalAddress

// TODO: Allow a way for the merchant to specify their own way of formatting the address

public init(
identifier: String,
postalAddress: PostalAddress
) {
self.identifier = identifier
self.postalAddress = postalAddress
}
}

public protocol AddressLookupProvider: AnyObject {

func lookUp(
searchTerm: String,
resultHandler: @escaping (_ result: [LookupAddressModel]) -> Void
)

func complete(
incompleteAddress: LookupAddressModel,
resultHandler: @escaping (_ result: Result<PostalAddress, Error>) -> Void
)
}

extension AddressLookupProvider {

// Default implementation
public func complete(
incompleteAddress: LookupAddressModel,
resultHandler: @escaping (_ result: Result<PostalAddress, Error>) -> Void
) {
resultHandler(.success(incompleteAddress.postalAddress))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import UIKit

public extension AddressLookupViewController {

typealias LookupProvider = (_ searchTerm: String, _ resultProvider: @escaping ([PostalAddress]) -> Void) -> Void

/// Defining the currently active screen
internal enum InterfaceState: Equatable {
case form(prefillAddress: PostalAddress?)
Expand All @@ -24,7 +22,7 @@ public extension AddressLookupViewController {
internal let supportedCountryCodes: [String]?
internal let initialCountry: String

private let lookupProvider: LookupProvider
internal let lookupProvider: AddressLookupProvider
private let completionHandler: (PostalAddress?) -> Void

@AdyenObservable(nil)
Expand Down Expand Up @@ -58,7 +56,7 @@ public extension AddressLookupViewController {
supportedCountryCodes: [String]?,
initialCountry: String,
prefillAddress: PostalAddress? = nil,
lookupProvider: @escaping LookupProvider,
lookupProvider: AddressLookupProvider,
completionHandler: @escaping (PostalAddress?) -> Void
) {
self.style = style
Expand All @@ -78,6 +76,11 @@ public extension AddressLookupViewController {

extension AddressLookupViewController.ViewModel {

internal func handleShowForm(with address: PostalAddress?) {
interfaceState = .form(prefillAddress: address)
shouldDismissOnSearchDismissal = false
}

private func setInitialInterfaceState() {
shouldDismissOnSearchDismissal = (prefillAddress == nil)

Expand Down Expand Up @@ -105,10 +108,6 @@ extension AddressLookupViewController.ViewModel {
}
}

internal func lookUp(searchTerm: String, resultHandler: @escaping ([ListItem]) -> Void) {
lookupProvider(searchTerm) { resultHandler($0.compactMap(listItem(for:))) }
}

internal func handleAddressInputFormCompletion(validAddress: PostalAddress?) {
completionHandler(validAddress)
}
Expand All @@ -117,27 +116,3 @@ extension AddressLookupViewController.ViewModel {
completionHandler(nil)
}
}

// MARK: - Convenience

private extension AddressLookupViewController.ViewModel {

func handleShowForm(with address: PostalAddress?) {
interfaceState = .form(prefillAddress: address)
shouldDismissOnSearchDismissal = false
}

func listItem(for address: PostalAddress) -> ListItem? {
guard !address.isEmpty else { return nil }

let formattedStreet = address.formattedStreet
let formattedLocation = address.formattedLocation(using: localizationParameters)

let title = !formattedStreet.isEmpty ? formattedStreet : formattedLocation
let subtitle = !formattedStreet.isEmpty ? formattedLocation : nil

return .init(title: title, subtitle: subtitle) {
self.handleShowForm(with: address)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ private extension AddressLookupViewController {
private func buildSearchViewController() -> SearchViewController {

AddressLookupSearchViewController(
style: viewModel.style.search,
localizationParameters: viewModel.localizationParameters,
delegate: self
viewModel: viewModel.addressSearchViewModel { [weak self] viewController in
self?.presentViewController(viewController, animated: true)
}
)
}

Expand All @@ -54,23 +54,6 @@ private extension AddressLookupViewController {
}
}

// MARK: - Delegate Conformances

extension AddressLookupViewController: AddressLookupSearchDelegate {

internal func addressLookupSearchSwitchToManualEntry() {
viewModel.handleSwitchToManualEntryTapped()
}

internal func addressLookupSearchLookUp(searchTerm: String, resultHandler: @escaping ([ListItem]) -> Void) {
viewModel.lookUp(searchTerm: searchTerm, resultHandler: resultHandler)
}

internal func addressLookupSearchCancel() {
viewModel.handleDismissSearchTapped()
}
}

// MARK: - Navigation

private extension AddressLookupViewController {
Expand Down Expand Up @@ -112,4 +95,19 @@ private extension AddressLookupViewController.ViewModel {
completionHandler: handleAddressInputFormCompletion(validAddress:)
)
}

func addressSearchViewModel(
goergisn marked this conversation as resolved.
Show resolved Hide resolved
presentationHandler: @escaping (UIViewController) -> Void
) -> AddressLookupSearchViewController.ViewModel {

.init(
localizationParameters: localizationParameters,
style: style.search,
lookupProvider: lookupProvider,
presentationHandler: presentationHandler,
showFormHandler: handleShowForm(with:),
switchToManualEntryHandler: handleSwitchToManualEntryTapped,
cancellationHandler: handleDismissSearchTapped
)
}
}
Loading
Loading