Skip to content

Commit 09cd403

Browse files
authored
Merge branch 'develop' into drop-in-tests
2 parents 4fb7039 + 4bbce20 commit 09cd403

File tree

30 files changed

+160
-110
lines changed

30 files changed

+160
-110
lines changed

.swiftlint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ line_length:
1919
ignores_function_declarations: true
2020
ignores_urls: true
2121
warning: 140
22+
23+
file_length:
24+
warning: 500

Adyen/Core/Components/AbstractPersonalInformationComponent/AbstractPersonalInformationComponent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ open class AbstractPersonalInformationComponent: PaymentComponent, PresentableCo
235235
lastNameItem?.value = $0.lastName
236236
}
237237
shopperInformation.emailAddress.map { emailItem?.value = $0 }
238-
shopperInformation.telephoneNumber.map { phoneItem?.value = $0 }
238+
shopperInformation.phoneNumber.map { phoneItem?.value = $0.value }
239239
shopperInformation.billingAddress.map { addressItem?.value = $0 }
240240
shopperInformation.deliveryAddress.map { deliveryAddressItem?.value = $0 }
241241
}

Adyen/Core/Core Protocols/Component.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2022 Adyen N.V.
2+
// Copyright (c) 2023 Adyen N.V.
33
//
44
// This file is open source and available under the MIT license. See the LICENSE file for more info.
55
//
@@ -65,9 +65,9 @@ public extension Component {
6565
}
6666

6767
private enum AssociatedKeys {
68-
internal static var isDropIn = "isDropInObject"
68+
internal static var isDropIn: Void?
6969

70-
internal static var environment = "environmentObject"
70+
internal static var environment: Void?
7171

72-
internal static var clientKey = "clientKeyObject"
72+
internal static var clientKey: Void?
7373
}

Adyen/Core/Core Protocols/PaymentAwareComponent.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2022 Adyen N.V.
2+
// Copyright (c) 2023 Adyen N.V.
33
//
44
// This file is open source and available under the MIT license. See the LICENSE file for more info.
55
//
@@ -37,7 +37,7 @@ extension PartialPaymentOrderAware {
3737

3838
private enum AssociatedKeys {
3939

40-
internal static var payment = "paymentObject"
40+
internal static var payment: Void?
4141

42-
internal static var order = "orderObject"
42+
internal static var order: Void?
4343
}

Adyen/Core/Models/CardType.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public enum CardType: RawRepresentable, Codable, Equatable, Hashable {
8383

8484
/// Korea Cyber Payment
8585
case kcp
86-
86+
8787
/// Korean local card
8888
case koreanLocalCard
8989

@@ -141,7 +141,7 @@ public enum CardType: RawRepresentable, Codable, Equatable, Hashable {
141141
/// Fallback option for any other scheme name
142142
case other(named: String)
143143

144-
// swiftlint:disable cyclomatic_complexity
144+
// swiftlint:disable cyclomatic_complexity function_body_length
145145
public init(rawValue: String) {
146146
switch rawValue {
147147
case "accel": self = .accel
@@ -292,7 +292,7 @@ public enum CardType: RawRepresentable, Codable, Equatable, Hashable {
292292
case let .other(name): return name.replacingOccurrences(of: "_", with: " ")
293293
}
294294
}
295-
// swiftlint:enable cyclomatic_complexity
295+
// swiftlint:enable cyclomatic_complexity function_body_length
296296
}
297297

298298
extension CardType {

Adyen/Core/Payment Methods/Abstract/PaymentMethodType.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public enum PaymentMethodType: RawRepresentable, Hashable, Codable {
6363
case other(String)
6464

6565
// swiftlint:disable cyclomatic_complexity function_body_length
66-
66+
6767
public init?(rawValue: String) {
6868
switch rawValue {
6969
case "card": self = .card
@@ -122,7 +122,7 @@ public enum PaymentMethodType: RawRepresentable, Hashable, Codable {
122122
default: self = .other(rawValue)
123123
}
124124
}
125-
125+
126126
public var rawValue: String {
127127
switch self {
128128
case .card: return "card"
@@ -180,6 +180,9 @@ public enum PaymentMethodType: RawRepresentable, Hashable, Codable {
180180
case let .other(value): return value
181181
}
182182
}
183+
}
184+
185+
extension PaymentMethodType {
183186

184187
/// The brand name of the card type
185188
///

Adyen/Helpers/UIViewAnimation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import UIKit
88

99
private enum AssociatedKeys {
10-
internal static var animations = "animations"
10+
internal static var animations: Void?
1111
}
1212

1313
@_spi(AdyenInternal)

Adyen/UI/Form/Items/Phone Number/FormPhoneNumberItem.swift

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2022 Adyen N.V.
2+
// Copyright (c) 2023 Adyen N.V.
33
//
44
// This file is open source and available under the MIT license. See the LICENSE file for more info.
55
//
@@ -31,11 +31,15 @@ public final class FormPhoneNumberItem: FormTextItem {
3131
selectableValues: [PhoneExtensionPickerItem],
3232
style: FormTextItemStyle,
3333
localizationParameters: LocalizationParameters? = nil) {
34-
// swiftlint:disable:next line_length
35-
let preselectedValue = selectableValues.first(where: { $0.element.value == phoneNumber?.callingCode }) ?? selectableValues.first(where: { $0.identifier == Locale.current.regionCode }) ?? selectableValues[0]
36-
37-
phonePrefixItem = FormPhoneExtensionPickerItem(preselectedValue: preselectedValue, selectableValues: selectableValues, style: style)
34+
35+
phonePrefixItem = FormPhoneExtensionPickerItem(
36+
preselectedValue: selectableValues.preselectedPhoneNumberPrefix(for: phoneNumber),
37+
selectableValues: selectableValues,
38+
style: style
39+
)
40+
3841
super.init(style: style)
42+
3943
phonePrefixItem.identifier = ViewIdentifierBuilder.build(scopeInstance: self, postfix: "phoneExtensionPickerItem")
4044
value = phoneNumber?.value ?? ""
4145

@@ -50,5 +54,25 @@ public final class FormPhoneNumberItem: FormTextItem {
5054
override public func build(with builder: FormItemViewBuilder) -> AnyFormItemView {
5155
builder.build(with: self)
5256
}
57+
}
58+
59+
private extension [PhoneExtensionPickerItem] {
5360

61+
func preselectedPhoneNumberPrefix(for phoneNumber: PhoneNumber?) -> PhoneExtensionPickerItem {
62+
63+
if let matchingCallingCode = first(where: { $0.element.value == phoneNumber?.callingCode }) {
64+
return matchingCallingCode
65+
}
66+
67+
if let matchingLocaleRegion = first(where: { $0.identifier == Locale.current.regionCode }) {
68+
return matchingLocaleRegion
69+
}
70+
71+
if let firstSelectableValue = first {
72+
return firstSelectableValue
73+
}
74+
75+
AdyenAssertion.assertionFailure(message: "Empty list of selectableValues provided")
76+
return .init(identifier: "", element: .init(value: "+1", countryCode: "US"))
77+
}
5478
}

Adyen/UI/List/ListItem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public class ListItem: FormItem {
9494

9595
private func setLoading(_ isLoading: Bool) {
9696
guard let loadingHandler else {
97-
assertionFailure("No loadingHandler provided")
97+
AdyenAssertion.assertionFailure(message: "No loadingHandler provided")
9898
return
9999
}
100100

Adyen/UI/View Controllers/AddressLookup/AddressLookupViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ private extension AddressLookupViewController {
7979
}
8080
}
8181

82-
internal extension AddressLookupViewController.ViewModel {
82+
extension AddressLookupViewController.ViewModel {
8383

84-
func buildAddressInputFormViewModel(
84+
internal func buildAddressInputFormViewModel(
8585
with prefillAddress: PostalAddress?
8686
) -> AddressInputFormViewController.ViewModel {
8787

@@ -96,7 +96,7 @@ internal extension AddressLookupViewController.ViewModel {
9696
)
9797
}
9898

99-
func buildAddressSearchViewModel(
99+
internal func buildAddressSearchViewModel(
100100
presentationHandler: @escaping (UIViewController) -> Void
101101
) -> AddressLookupSearchViewController.ViewModel {
102102

Adyen/Utilities/External/AllCountriesPhoneExtensions.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import Foundation
88

9-
// swiftlint:disable file_length
109
internal let allCountriesPhoneExtensions: [String: String] = [
1110

1211
"AF": "+93",
@@ -492,4 +491,3 @@ internal let allCountriesPhoneExtensions: [String: String] = [
492491
"VI": "+1 340"
493492

494493
]
495-
// swiftlint:enable file_length

Adyen/Utilities/Observable/AdyenObserver.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2022 Adyen N.V.
2+
// Copyright (c) 2023 Adyen N.V.
33
//
44
// This file is open source and available under the MIT license. See the LICENSE file for more info.
55
//
@@ -160,6 +160,6 @@ public extension AdyenObserver {
160160
private enum AssociatedKeys {
161161

162162
/// The observation manager associated with the object.
163-
public static var observationManager = "observationManager"
163+
public static var observationManager: Void?
164164

165165
}

AdyenCard/Components/Card/CardViewController.swift

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ internal class CardViewController: FormViewController {
198198

199199
updateBillingAddressOptionalStatus(brands: brands)
200200
}
201+
}
202+
203+
// MARK: - Private methods
204+
205+
extension CardViewController {
201206

202207
private func updateBillingAddressOptionalStatus(brands: [CardBrand]) {
203208
let isOptional = configuration.billingAddress.isOptional(for: brands.map(\.type))
@@ -270,33 +275,39 @@ internal class CardViewController: FormViewController {
270275
append(items.storeDetailsItem)
271276
append(FormSpacerItem())
272277
}
278+
279+
if let billingAddressItem = billingAddressItem(for: configuration.billingAddress.mode) {
280+
append(billingAddressItem)
281+
}
273282

274-
switch configuration.billingAddress.mode {
283+
append(FormSpacerItem())
284+
append(items.button)
285+
append(FormSpacerItem(numberOfSpaces: 2))
286+
}
287+
288+
private func billingAddressItem(for billingAddressMode: CardComponent.AddressFormType) -> FormItem? {
289+
switch billingAddressMode {
275290
case let .lookup(provider):
276291
let item = items.billingAddressPickerItem
277292
item.selectionHandler = { [weak cardDelegate, weak provider] in
278293
guard let provider else { return }
279294
cardDelegate?.didSelectAddressPicker(lookupProvider: provider)
280295
}
281-
append(item)
296+
return item
282297

283298
case .full:
284299
let item = items.billingAddressPickerItem
285300
item.selectionHandler = { [weak cardDelegate] in
286301
cardDelegate?.didSelectAddressPicker(lookupProvider: nil)
287302
}
288-
append(item)
303+
return item
289304

290305
case .postalCode:
291-
append(items.postalCodeItem)
306+
return items.postalCodeItem
292307

293308
case .none:
294-
break
309+
return nil
295310
}
296-
297-
append(FormSpacerItem())
298-
append(items.button)
299-
append(FormSpacerItem(numberOfSpaces: 2))
300311
}
301312

302313
private func prefill() {

AdyenDropIn/Utilities/ComponentManager.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ internal final class ComponentManager {
123123

124124
private func component(for paymentMethod: PaymentMethod) -> PaymentComponent? {
125125
guard isAllowed(paymentMethod) else {
126-
// swiftlint:disable:next line_length
127-
AdyenAssertion.assertionFailure(message: "For voucher payment methods like \(paymentMethod.name) it is required to add a suitable text for the key NSPhotoLibraryAddUsageDescription in the Application Info.plist, to enable the shopper to save the voucher to their photo library.")
126+
AdyenAssertion.assertionFailure(message: """
127+
For voucher payment methods like \(paymentMethod.name) it is required to add a suitable \
128+
text for the key NSPhotoLibraryAddUsageDescription in the Application Info.plist, to enable \
129+
the shopper to save the voucher to their photo library.
130+
""")
128131
return nil
129132
}
130133

AdyenWeChatPay/WeChatPayActionComponent/WeChatPayActionComponent.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2022 Adyen N.V.
2+
// Copyright (c) 2023 Adyen N.V.
33
//
44
// This file is open source and available under the MIT license. See the LICENSE file for more info.
55
//
@@ -69,8 +69,9 @@ import Foundation
6969

7070
private static func assertWeChatPayAppSchemeConfigured() {
7171
guard Bundle.main.adyen.isSchemeConfigured("weixin") else {
72-
// swiftlint:disable:next line_length
73-
return AdyenAssertion.assertionFailure(message: "weixin:// scheme must be added to Info.plist under LSApplicationQueriesSchemes key.")
72+
return AdyenAssertion.assertionFailure(message: """
73+
weixin:// scheme must be added to Info.plist under LSApplicationQueriesSchemes key.
74+
""")
7475
}
7576
}
7677

Demo/Common/Configuration/ConfigurationView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ private struct ListItemView<T: Hashable>: View {
232232
}.tag(viewModel.tag)
233233
}
234234

235-
fileprivate struct ViewModel<T: Hashable> {
235+
fileprivate struct ViewModel<Tag: Hashable> {
236236
let title: String
237237
let subtitle: String
238-
let tag: T
238+
let tag: Tag
239239
}
240240
}
241241

Demo/Common/IntegrationExamples/Components/InstantPaymentComponentAdvancedFlowExample.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Adyen
1010
import AdyenActions
1111
import AdyenComponents
1212

13-
internal final class InstantPaymentComponentAdvancedFlowExample: InitialDataAdvancedFlowProtocol {
13+
internal final class InstantPaymentComponentAdvancedFlow: InitialDataAdvancedFlowProtocol {
1414

1515
// MARK: - Properties
1616

@@ -127,7 +127,7 @@ internal final class InstantPaymentComponentAdvancedFlowExample: InitialDataAdva
127127

128128
}
129129

130-
extension InstantPaymentComponentAdvancedFlowExample: PaymentComponentDelegate {
130+
extension InstantPaymentComponentAdvancedFlow: PaymentComponentDelegate {
131131

132132
internal func didSubmit(_ data: PaymentComponentData, from component: PaymentComponent) {
133133
presenter?.showLoadingIndicator()
@@ -144,7 +144,7 @@ extension InstantPaymentComponentAdvancedFlowExample: PaymentComponentDelegate {
144144

145145
}
146146

147-
extension InstantPaymentComponentAdvancedFlowExample: ActionComponentDelegate {
147+
extension InstantPaymentComponentAdvancedFlow: ActionComponentDelegate {
148148

149149
internal func didFail(with error: Error, from component: ActionComponent) {
150150
finish(with: error)
@@ -167,14 +167,14 @@ extension InstantPaymentComponentAdvancedFlowExample: ActionComponentDelegate {
167167
}
168168
}
169169

170-
extension InstantPaymentComponentAdvancedFlowExample: PresentationDelegate {
170+
extension InstantPaymentComponentAdvancedFlow: PresentationDelegate {
171171
internal func present(component: PresentableComponent) {
172172
let componentViewController = viewController(for: component)
173173
presenter?.present(viewController: componentViewController, completion: nil)
174174
}
175175
}
176176

177-
private extension InstantPaymentComponentAdvancedFlowExample {
177+
private extension InstantPaymentComponentAdvancedFlow {
178178

179179
private func viewController(for component: PresentableComponent) -> UIViewController {
180180
guard component.requiresModalPresentation else {

Demo/Configuration.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ internal struct DemoAppSettings: Codable {
149149
}
150150
let defaultInstallmentOptions = InstallmentOptions(monthValues: [2, 3, 4], includesRevolving: true)
151151
let visaInstallmentOptions = InstallmentOptions(monthValues: [3, 4, 6], includesRevolving: false)
152-
return InstallmentConfiguration(cardBasedOptions: [.visa: visaInstallmentOptions],
153-
defaultOptions: defaultInstallmentOptions,
154-
showInstallmentAmount: cardSettings.showsInstallmentAmount)
152+
return InstallmentConfiguration(
153+
cardBasedOptions: [.visa: visaInstallmentOptions],
154+
defaultOptions: defaultInstallmentOptions,
155+
showInstallmentAmount: cardSettings.showsInstallmentAmount
156+
)
155157
}
156158

157159
internal static let defaultConfiguration = DemoAppSettings(

0 commit comments

Comments
 (0)