Skip to content

Commit 420147f

Browse files
authored
fix: Prefil phone number doesn't change countryCode (#1431)
# Open PR ## Changes <fixed> * Fixed a problem where, when the phoneNumber in shopperInformation doesn't change countryCode. </fixed>
2 parents 1ac7da5 + 47cd4ed commit 420147f

20 files changed

+118
-44
lines changed

Adyen/Core/Components/AbstractPersonalInformationComponent/AbstractPersonalInformationComponent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ open class AbstractPersonalInformationComponent: PaymentComponent, PresentableCo
172172
internal lazy var phoneItemInjector: PhoneFormItemInjector? = {
173173
guard fields.contains(.phone) else { return nil }
174174
let identifier = ViewIdentifierBuilder.build(scopeInstance: self, postfix: "phoneNumberItem")
175-
let injector = PhoneFormItemInjector(value: configuration.shopperInformation?.telephoneNumber,
175+
let injector = PhoneFormItemInjector(value: configuration.shopperInformation?.phoneNumber,
176176
identifier: identifier,
177177
phoneExtensions: selectableValues,
178178
style: configuration.style.textField)

Adyen/Core/Components/AbstractPersonalInformationComponent/PhoneFormItemInjector.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ internal final class PhoneFormItemInjector: FormItemInjector, Localizable {
1414

1515
internal let phoneExtensions: [PhoneExtensionPickerItem]
1616

17-
internal var value: String?
17+
internal var value: PhoneNumber?
1818

1919
internal var identifier: String
2020

2121
internal lazy var item: FormPhoneNumberItem = {
22-
let item = FormPhoneNumberItem(selectableValues: phoneExtensions,
22+
let item = FormPhoneNumberItem(phoneNumber: value,
23+
selectableValues: phoneExtensions,
2324
style: style,
2425
localizationParameters: localizationParameters)
25-
item.value = value ?? ""
2626
item.identifier = identifier
2727
return item
2828
}()
2929

30-
internal init(value: String?,
30+
internal init(value: PhoneNumber?,
3131
identifier: String,
3232
phoneExtensions: [PhoneExtensionPickerItem],
3333
style: FormTextItemStyle) {

Adyen/Model/PrefilledShopperInformation.swift

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66

77
import Foundation
88

9+
/// The telephone number in E.123 international notation.
10+
public struct PhoneNumber {
11+
12+
/// The phone number excluding calling code
13+
public let value: String
14+
15+
/// The country calling code in E.123 international notation (ex. +22).
16+
public let callingCode: String?
17+
18+
public init(value: String, callingCode: String?) {
19+
self.value = value
20+
self.callingCode = callingCode
21+
}
22+
}
23+
924
/// A structure that contains information about the shopper
1025
public struct PrefilledShopperInformation: ShopperInformation {
1126

@@ -14,9 +29,19 @@ public struct PrefilledShopperInformation: ShopperInformation {
1429

1530
/// The email address.
1631
public var emailAddress: String?
17-
32+
33+
/// The telephone number.
34+
1835
/// The telephone number.
36+
@available(*, deprecated, message:
37+
"""
38+
This property is no longer supported.
39+
Please use phone Number instead.
40+
""")
1941
public var telephoneNumber: String?
42+
43+
/// The phone number.
44+
public var phoneNumber: PhoneNumber?
2045

2146
/// The billing address information.
2247
public var billingAddress: PostalAddress?
@@ -39,6 +64,17 @@ public struct PrefilledShopperInformation: ShopperInformation {
3964
/// - deliveryAddress: The delivery address of the shopper, optional.
4065
/// - socialSecurityNumber: The social security number of the shopper, optional.
4166
/// - card: Shopper's card basic information, optional.
67+
@available(*, deprecated, message:
68+
"""
69+
This init is no longer supported.
70+
Please use init(shopperName: ShopperName? = nil,
71+
emailAddress: String? = nil,
72+
phoneNumber: PhoneNumber? = nil,
73+
billingAddress: PostalAddress? = nil,
74+
deliveryAddress: PostalAddress? = nil,
75+
socialSecurityNumber: String? = nil,
76+
card: CardInformation? = nil) instead.
77+
""")
4278
public init(shopperName: ShopperName? = nil,
4379
emailAddress: String? = nil,
4480
telephoneNumber: String? = nil,
@@ -54,6 +90,31 @@ public struct PrefilledShopperInformation: ShopperInformation {
5490
self.socialSecurityNumber = socialSecurityNumber
5591
self.card = card
5692
}
93+
94+
/// Initializes the ShopperInfo struct
95+
/// - Parameters:
96+
/// - shopperName: The name of the shopper, optional.
97+
/// - emailAddress: The email of the shopper, optional.
98+
/// - phoneNumber: The phone number of the shopper, optional.
99+
/// - billingAddress: The billing address of the shopper, optional.
100+
/// - deliveryAddress: The delivery address of the shopper, optional.
101+
/// - socialSecurityNumber: The social security number of the shopper, optional.
102+
/// - card: Shopper's card basic information, optional.
103+
public init(shopperName: ShopperName? = nil,
104+
emailAddress: String? = nil,
105+
phoneNumber: PhoneNumber? = nil,
106+
billingAddress: PostalAddress? = nil,
107+
deliveryAddress: PostalAddress? = nil,
108+
socialSecurityNumber: String? = nil,
109+
card: CardInformation? = nil) {
110+
self.shopperName = shopperName
111+
self.emailAddress = emailAddress
112+
self.phoneNumber = phoneNumber
113+
self.billingAddress = billingAddress
114+
self.deliveryAddress = deliveryAddress
115+
self.socialSecurityNumber = socialSecurityNumber
116+
self.card = card
117+
}
57118
}
58119

59120
extension PrefilledShopperInformation {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ public final class FormPhoneNumberItem: FormTextItem {
2727
/// - Parameter selectableValues: The list of values to select from.
2828
/// - Parameter style: The `FormTextItemStyle` UI style.
2929
/// - Parameter localizationParameters: Parameters for custom localization, leave it nil to use the default parameters.
30-
public init(selectableValues: [PhoneExtensionPickerItem],
30+
public init(phoneNumber: PhoneNumber?,
31+
selectableValues: [PhoneExtensionPickerItem],
3132
style: FormTextItemStyle,
3233
localizationParameters: LocalizationParameters? = nil) {
33-
phonePrefixItem = FormPhoneExtensionPickerItem(selectableValues: selectableValues, style: style)
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)
3438
super.init(style: style)
3539
phonePrefixItem.identifier = ViewIdentifierBuilder.build(scopeInstance: self, postfix: "phoneExtensionPickerItem")
40+
value = phoneNumber?.value ?? ""
3641

3742
title = localizedString(.phoneNumberTitle, localizationParameters)
3843
placeholder = localizedString(.phoneNumberPlaceholder, localizationParameters)

Adyen/UI/Form/Items/Value Pickers/Phone Extension Picker/FormPhoneExtensionPickerItem.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ public typealias PhoneExtensionPickerItem = BasePickerElement<PhoneExtension>
2020
/// Describes a picker item.
2121
@_spi(AdyenInternal)
2222
public final class FormPhoneExtensionPickerItem: BaseFormPickerItem<PhoneExtension> {
23-
23+
2424
/// Initializes the picker item.
2525
///
2626
/// - Parameter selectableValues: The list of values to select from.
2727
/// - Parameter style: The `FormPhoneExtensionPickerItem` UI style.
28-
internal init(selectableValues: [PhoneExtensionPickerItem], style: FormTextItemStyle) {
28+
internal override init(preselectedValue: PhoneExtensionPickerItem,
29+
selectableValues: [PhoneExtensionPickerItem],
30+
style: FormTextItemStyle) {
2931
assert(selectableValues.count > 0)
30-
let preselectedValue = selectableValues.first(where: { $0.identifier == Locale.current.regionCode }) ?? selectableValues[0]
3132
super.init(preselectedValue: preselectedValue, selectableValues: selectableValues, style: style)
3233
}
3334

AdyenComponents/Affirm/AffirmComponent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public final class AffirmComponent: AbstractPersonalInformationComponent {
101101
guard let firstName = firstNameItem?.value,
102102
let lastName = lastNameItem?.value,
103103
let emailAddress = emailItem?.value,
104-
let telephoneNumber = phoneItem?.value,
104+
let telephoneNumber = phoneItem?.phoneNumber,
105105
let billingAddress = addressItem?.value,
106106
let deliveryAddress = deliveryAddressItem?.value else {
107107
throw UnknownError(errorDescription: "There seems to be an error in the BasicPersonalInfoFormComponent configuration.")

AdyenComponents/Atome/AtomeComponent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public final class AtomeComponent: AbstractPersonalInformationComponent {
6969
override public func createPaymentDetails() throws -> PaymentMethodDetails {
7070
guard let firstName = firstNameItem?.value,
7171
let lastName = lastNameItem?.value,
72-
let telephoneNumber = phoneItem?.value,
72+
let telephoneNumber = phoneItem?.phoneNumber,
7373
let billingAddress = addressItem?.value else {
7474
throw UnknownError(errorDescription: "There seems to be an error in the BasicPersonalInfoFormComponent configuration")
7575
}

MIGRATION.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
# Migration Notes
22

3-
## 5.0.0
3+
## Upcoming release
4+
- `telephoneNumber` property of `PrefilledShopperInformation` has been deprecated. Use to `phoneNumber` property if needed.
5+
6+
7+
## 5.3.0
8+
- The `didComplete` method signature of `AdyenSessionDelegate` has changed. You must replace `didComplete(with resultCode: SessionPaymentResultCode, component: Component, session: AdyenSession)` with `didComplete(with result: AdyenSessionResult, component: Component, session: AdyenSession)`. Use the `resultCode` inside of the `AdyenSessionResult` if needed.
9+
10+
11+
## 5.2.0
12+
- `amountToPay` property of `PaymentComponentData` has been deprecated. Use to `amount` property if needed.
413

14+
15+
## 5.0.0
516
- `AffirmComponent.style`, `AffirmComponent.shopperInformation` and `AffirmComponent.localizationParameters` moved into new `configuration` property `AffirmComponent.Configuration`;
617
- `DokuComponent.style`, `DokuComponent.shopperInformation` and `DokuComponent.localizationParameters` moved into new `configuration` property `DokuComponent.Configuration`;
718
- `MBWayComponent.style`, `MBWayComponent.shopperInformation` and `MBWayComponent.localizationParameters` moved into new `configuration` property `MBWayComponent.Configuration`;
@@ -38,9 +49,3 @@
3849
- `AnalyticsConfiguration` is the object that defines the behavior of analytics within the SDK. Merchants can enable/disable analytics.
3950
- `CardComponentDelegate.didChangeBIN(:component:)` provides the 8 digit bin in case the PAN is greater than 16 digits.
4051
- `CardComponentDelegate.didSubmit(lastFour:finalBIN:component)` now has a new parameter `finalBIN` that provides the final BIN after shopper submits the card details.
41-
42-
## 5.2.0
43-
- `amountToPay` property of `PaymentComponentData` has been deprecated. Use to `amount` property if needed.
44-
45-
## 5.3.0
46-
- The `didComplete` method signature of `AdyenSessionDelegate` has changed. You must replace `didComplete(with resultCode: SessionPaymentResultCode, component: Component, session: AdyenSession)` with `didComplete(with result: AdyenSessionResult, component: Component, session: AdyenSession)`. Use the `resultCode` inside of the `AdyenSessionResult` if needed.

Tests/Card Tests/Items/CardNumberItem/FormItemViewBuilderTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class FormItemViewBuilderTests: XCTestCase {
1212
func testFormPhoneExtensionPickerItemView() {
1313
let selectableValues = [PhoneExtensionPickerItem(identifier: "test_id",
1414
element: .init(value: "test title", countryCode: "test extension"))]
15-
let item = FormPhoneExtensionPickerItem(selectableValues: selectableValues, style: FormTextItemStyle())
15+
let item = FormPhoneExtensionPickerItem(preselectedValue: selectableValues[0], selectableValues: selectableValues, style: FormTextItemStyle())
1616
let view = item.build(with: FormItemViewBuilder())
1717

1818
XCTAssertNotNil(view as? FormPhoneExtensionPickerItemView)
@@ -42,7 +42,7 @@ class FormItemViewBuilderTests: XCTestCase {
4242

4343
func testFormPhoneNumberItemView() {
4444
let selectableValues = [PhoneExtensionPickerItem(identifier: "test_id", element: .init(value: "test title", countryCode: "test extension"))]
45-
let item = FormPhoneNumberItem(selectableValues: selectableValues, style: FormTextItemStyle())
45+
let item = FormPhoneNumberItem(phoneNumber: nil, selectableValues: selectableValues, style: FormTextItemStyle())
4646
let view = item.build(with: FormItemViewBuilder())
4747

4848
XCTAssertNotNil(view as? FormPhoneNumberItemView)

Tests/Components Tests/Affirm/AffirmComponentTests.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class AffirmComponentTests: XCTestCase {
124124
let details = data.paymentMethod as! AffirmDetails
125125
XCTAssertEqual(details.shopperName?.firstName, "Katrina")
126126
XCTAssertEqual(details.shopperName?.lastName, "Del Mar")
127-
XCTAssertEqual(details.telephoneNumber, "2025550146")
127+
XCTAssertEqual(details.telephoneNumber, "+12025550146")
128128
XCTAssertEqual(details.emailAddress, "[email protected]")
129129
XCTAssertEqual(details.billingAddress, expectedBillingAddress)
130130
XCTAssertEqual(details.deliveryAddress, expectedDeliveryAddress)
@@ -145,7 +145,7 @@ class AffirmComponentTests: XCTestCase {
145145

146146
let phoneNumberView: FormPhoneNumberItemView = try XCTUnwrap(view.findView(by: AffirmViewIdentifier.phone))
147147
populate(textItemView: phoneNumberView, with: "2025550146")
148-
148+
149149
let emailView: FormTextInputItemView = try XCTUnwrap(view.findView(by: AffirmViewIdentifier.email))
150150
populate(textItemView: emailView, with: "[email protected]")
151151

@@ -197,7 +197,7 @@ class AffirmComponentTests: XCTestCase {
197197
XCTAssertEqual(expectedLastName, lastName)
198198

199199
let phoneNumberView: FormPhoneNumberItemView = try XCTUnwrap(view.findView(by: AffirmViewIdentifier.phone))
200-
let expectedPhoneNumber = try XCTUnwrap(shopperInformation.telephoneNumber)
200+
let expectedPhoneNumber = try XCTUnwrap(shopperInformation.phoneNumber?.value)
201201
let phoneNumber = phoneNumberView.item.value
202202
XCTAssertEqual(expectedPhoneNumber, phoneNumber)
203203

@@ -227,7 +227,8 @@ class AffirmComponentTests: XCTestCase {
227227
let prefillSut = AffirmComponent(paymentMethod: paymentMethod,
228228
context: context,
229229
configuration: config)
230-
230+
prefillSut.phoneItem?.value = "+1223434545"
231+
231232
setupRootViewController(prefillSut.viewController)
232233

233234
// Then
@@ -244,7 +245,7 @@ class AffirmComponentTests: XCTestCase {
244245
XCTAssertEqual(expectedLastName, lastName)
245246

246247
let phoneNumberView: FormPhoneNumberItemView = try XCTUnwrap(view.findView(by: AffirmViewIdentifier.phone))
247-
let expectedPhoneNumber = try XCTUnwrap(shopperInformation.telephoneNumber)
248+
let expectedPhoneNumber = prefillSut.phoneItem?.value
248249
let phoneNumber = phoneNumberView.item.value
249250
XCTAssertEqual(expectedPhoneNumber, phoneNumber)
250251

@@ -338,7 +339,7 @@ class AffirmComponentTests: XCTestCase {
338339
let deliveryAddress = PostalAddressMocks.losAngelesPostalAddress
339340
let shopperInformation = PrefilledShopperInformation(shopperName: ShopperName(firstName: "Katrina", lastName: "Del Mar"),
340341
emailAddress: "[email protected]",
341-
telephoneNumber: "1234567890",
342+
phoneNumber: PhoneNumber(value: "1234567", callingCode: "+1"),
342343
billingAddress: billingAddress,
343344
deliveryAddress: deliveryAddress,
344345
socialSecurityNumber: "78542134370")
@@ -349,7 +350,7 @@ class AffirmComponentTests: XCTestCase {
349350
let billingAddress = PostalAddressMocks.newYorkPostalAddress
350351
let shopperInformation = PrefilledShopperInformation(shopperName: ShopperName(firstName: "Katrina", lastName: "Del Mar"),
351352
emailAddress: "[email protected]",
352-
telephoneNumber: "1234567890",
353+
phoneNumber: nil,
353354
billingAddress: billingAddress,
354355
deliveryAddress: nil,
355356
socialSecurityNumber: "78542134370")

0 commit comments

Comments
 (0)