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

Migrate iOS to v5 #326

Merged
merged 6 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
.VolumeIcon.icns

# Xcode
build/
[bB]uild/
*.pbxuser
!default.pbxuser
*.mode1v3
Expand All @@ -31,6 +31,7 @@ DerivedData
*.xcuserstate
project.xcworkspace
Pods/
*.xcode.env

# Android/IJ
.idea
Expand Down
2 changes: 1 addition & 1 deletion adyen-react-native.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Pod::Spec.new do |s|


s.dependency "React-Core"
s.dependency "Adyen", '4.11.1'
s.dependency "Adyen", '5.4.1'

end
17 changes: 9 additions & 8 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ def safeExtGet(prop, fallback) {
}

buildscript {
rootProject.ext.adyenReactNativeRedirectScheme = "adyenreactnative"
rootProject.ext.adyenReactNativeRedirectScheme = "adyenreactnative"
ext.kotlin_version = rootProject.ext.has('kotlin_version') ? rootProject.ext.get('kotlin_version') : '1.9.10'

repositories {
google()
jcenter()
}
repositories {
google()
jcenter()
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

apply plugin: 'com.android.library'
Expand Down
3 changes: 1 addition & 2 deletions docs/v2-MigrationGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

## Breacking changes

* Merchant's app theme must be decendent of `Theme.MaterialComponents` to operate with "instant" payment components (ex. Paypal, Klarna)
* Merchant's app theme must be decendent of `Theme.MaterialComponents` to operate with "instant" payment components (ex. Paypal, Klarna). Example:
```xml
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
```

Expand Down
88 changes: 43 additions & 45 deletions example/ios/AdyenExampleTests/ApplePayConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

import XCTest
import Adyen
import adyen_react_native
@testable import adyen_react_native
import PassKit

final class ApplePayConfigurationTests: XCTestCase {

let mockAmount = Amount(value: 1000, currencyCode: "USD", localeIdentifier: "en-US")

lazy var mockPayment = Payment(amount: mockAmount, countryCode: "US")
descorp marked this conversation as resolved.
Show resolved Hide resolved

func testNewDictionary() throws {
let sut = ApplepayConfigurationParser(configuration: NSDictionary())
XCTAssertNotNil(sut)
Expand All @@ -28,7 +29,7 @@ final class ApplePayConfigurationTests: XCTestCase {
XCTAssertNotNil(sut)

let expectation = self.expectation(description: "Expect throw")
XCTAssertThrowsError(try sut.buildConfiguration(amount: mockAmount)) { error in
XCTAssertThrowsError(try sut.buildConfiguration(payment: mockPayment)) { error in
XCTAssertEqual(error.localizedDescription, ApplepayConfigurationParser.ApplePayError.invalidMerchantID.localizedDescription)
expectation.fulfill()
}
Expand All @@ -39,7 +40,7 @@ final class ApplePayConfigurationTests: XCTestCase {
func testWrongSubDictionary() throws {
let sut = ApplepayConfigurationParser(configuration: ["applepay": "some value"])
let expectation = self.expectation(description: "Expect throw")
XCTAssertThrowsError(try sut.buildConfiguration(amount: mockAmount)) { error in
XCTAssertThrowsError(try sut.buildConfiguration(payment: mockPayment)) { error in
XCTAssertEqual(error.localizedDescription, ApplepayConfigurationParser.ApplePayError.invalidMerchantID.localizedDescription)
expectation.fulfill()
}
Expand All @@ -56,7 +57,7 @@ final class ApplePayConfigurationTests: XCTestCase {
])

let expectation = self.expectation(description: "Expect throw")
XCTAssertThrowsError(try sut.buildConfiguration(amount: mockAmount)) { error in
XCTAssertThrowsError(try sut.buildConfiguration(payment: mockPayment)) { error in
XCTAssertEqual(error.localizedDescription, ApplepayConfigurationParser.ApplePayError.invalidMerchantName.localizedDescription)
expectation.fulfill()
}
Expand All @@ -72,21 +73,21 @@ final class ApplePayConfigurationTests: XCTestCase {
"merchantName": "SomeName"
]
])
let config = try sut.buildConfiguration(amount: mockAmount)
XCTAssertNotNil(config.merchantIdentifier)
XCTAssertNotNil(config.summaryItems)
XCTAssertEqual(config.summaryItems.count, 1)
let paymentRequest = try sut.buildPaymentRequest(payment: mockPayment)
XCTAssertNotNil(paymentRequest.merchantIdentifier)
XCTAssertNotNil(paymentRequest.paymentSummaryItems)
XCTAssertEqual(paymentRequest.paymentSummaryItems.count, 1)
}

func testMinimalValidDictionaryValuesWithNoSubDirectory() throws {
let sut = ApplepayConfigurationParser(configuration: [
"merchantID": "merchant.com.adyen.test",
"merchantName": "SomeName"
])
let config = try sut.buildConfiguration(amount: mockAmount)
XCTAssertNotNil(config.merchantIdentifier)
XCTAssertNotNil(config.summaryItems)
XCTAssertEqual(config.summaryItems.count, 1)
let paymentRequest = try sut.buildPaymentRequest(payment: mockPayment)
XCTAssertNotNil(paymentRequest.merchantIdentifier)
XCTAssertNotNil(paymentRequest.paymentSummaryItems)
XCTAssertEqual(paymentRequest.paymentSummaryItems.count, 1)
}

func testCorrectSummaryItems() throws {
Expand Down Expand Up @@ -114,14 +115,14 @@ final class ApplePayConfigurationTests: XCTestCase {
]
]
])
let config = try sut.buildConfiguration(amount: mockAmount)
XCTAssertNotNil(config.merchantIdentifier)
XCTAssertNotNil(config.summaryItems)
XCTAssertEqual(config.summaryItems.count, 4)
XCTAssertEqual(config.summaryItems[0].amount, 70.20)
XCTAssertEqual(config.summaryItems[1].amount, 20)
XCTAssertEqual(config.summaryItems[2].amount, 10)
XCTAssertEqual(config.summaryItems[3].amount, 100.50)
let paymentRequest = try sut.buildPaymentRequest(payment: mockPayment)
XCTAssertNotNil(paymentRequest.merchantIdentifier)
XCTAssertNotNil(paymentRequest.paymentSummaryItems)
XCTAssertEqual(paymentRequest.paymentSummaryItems.count, 4)
XCTAssertEqual(paymentRequest.paymentSummaryItems[0].amount, 70.20)
XCTAssertEqual(paymentRequest.paymentSummaryItems[1].amount, 20)
XCTAssertEqual(paymentRequest.paymentSummaryItems[2].amount, 10)
XCTAssertEqual(paymentRequest.paymentSummaryItems[3].amount, 100.50)
}

func testInvalidSummaryItemsThrows() throws {
Expand All @@ -132,7 +133,7 @@ final class ApplePayConfigurationTests: XCTestCase {
]
])
let expectation = self.expectation(description: "Expect throw")
XCTAssertThrowsError(try sut.buildConfiguration(amount: mockAmount)) { error in
XCTAssertThrowsError(try sut.buildConfiguration(payment: mockPayment)) { error in
XCTAssertEqual(error.localizedDescription, ApplepayConfigurationParser.ApplePayError.invalidMerchantName.localizedDescription)
expectation.fulfill()
}
Expand All @@ -149,8 +150,7 @@ final class ApplePayConfigurationTests: XCTestCase {
"allowOnboarding": true
]
])
let config = try sut.buildConfiguration(amount: mockAmount)
XCTAssertTrue(config.allowOnboarding)
XCTAssertTrue(sut.allowOnboarding)
}

func testAllowOnboardingStringValue() throws {
Expand All @@ -162,8 +162,7 @@ final class ApplePayConfigurationTests: XCTestCase {
"allowOnboarding": "true"
]
])
let config = try sut.buildConfiguration(amount: mockAmount)
XCTAssertTrue(config.allowOnboarding)
XCTAssertTrue(sut.allowOnboarding)
}

func testAllowOnboardingNumericValue() throws {
Expand All @@ -175,8 +174,7 @@ final class ApplePayConfigurationTests: XCTestCase {
"allowOnboarding": 1
]
])
let config = try sut.buildConfiguration(amount: mockAmount)
XCTAssertTrue(config.allowOnboarding)
XCTAssertTrue(sut.allowOnboarding)
}

func testBillingAddress() throws {
Expand Down Expand Up @@ -204,7 +202,7 @@ final class ApplePayConfigurationTests: XCTestCase {
]
])

let contact = try XCTUnwrap(sut.buildConfiguration(amount: mockAmount).billingContact)
let contact = try XCTUnwrap(sut.billingContact)
XCTAssertEqual(contact.phoneNumber?.stringValue, "123-456-7890")
XCTAssertEqual(contact.emailAddress, "[email protected]")
XCTAssertEqual(contact.name?.givenName, "John")
Expand Down Expand Up @@ -235,7 +233,7 @@ final class ApplePayConfigurationTests: XCTestCase {
]
])

let contact = try XCTUnwrap(sut.buildConfiguration(amount: mockAmount).billingContact)
let contact = try XCTUnwrap(sut.billingContact)
XCTAssertEqual(contact.phoneNumber?.stringValue, "123-456-7890")
XCTAssertNil(contact.emailAddress)
XCTAssertEqual(contact.name?.givenName, "John")
Expand All @@ -259,7 +257,7 @@ final class ApplePayConfigurationTests: XCTestCase {
]
])

let contact = try XCTUnwrap(sut.buildConfiguration(amount: mockAmount).billingContact)
let contact = try XCTUnwrap(sut.billingContact)
XCTAssertNil(contact.phoneNumber)
XCTAssertEqual(contact.emailAddress, "[email protected]")
XCTAssertNil(contact.name?.givenName)
Expand All @@ -277,8 +275,8 @@ final class ApplePayConfigurationTests: XCTestCase {
"requiredBillingContactFields": []
]
])
let config = try sut.buildConfiguration(amount: mockAmount)
XCTAssertEqual(config.requiredBillingContactFields.count, 0)
let paymentRequest = try sut.buildPaymentRequest(payment: mockPayment)
XCTAssertEqual(paymentRequest.requiredBillingContactFields.count, 0)
}

func testRequiredBillingFileds() throws {
Expand All @@ -290,11 +288,11 @@ final class ApplePayConfigurationTests: XCTestCase {
"requiredBillingContactFields": ["emailAddress", "phoneNumber", "postalAddress"]
]
])
let config = try sut.buildConfiguration(amount: mockAmount)
XCTAssertEqual(config.requiredBillingContactFields.count, 3)
XCTAssertTrue(config.requiredBillingContactFields.contains(.phoneNumber))
XCTAssertTrue(config.requiredBillingContactFields.contains(.emailAddress))
XCTAssertTrue(config.requiredBillingContactFields.contains(.postalAddress))
let paymentRequest = try sut.buildPaymentRequest(payment: mockPayment)
XCTAssertEqual(paymentRequest.requiredBillingContactFields.count, 3)
XCTAssertTrue(paymentRequest.requiredBillingContactFields.contains(.phoneNumber))
XCTAssertTrue(paymentRequest.requiredBillingContactFields.contains(.emailAddress))
XCTAssertTrue(paymentRequest.requiredBillingContactFields.contains(.postalAddress))
}

func testRequiredShippingFileds() throws {
Expand All @@ -306,13 +304,13 @@ final class ApplePayConfigurationTests: XCTestCase {
"requiredShippingContactFields": ["email", "phone", "phoneticName", "name", "post"]
]
])
let config = try sut.buildConfiguration(amount: mockAmount)
XCTAssertEqual(config.requiredShippingContactFields.count, 5)
XCTAssertTrue(config.requiredShippingContactFields.contains(.phoneNumber))
XCTAssertTrue(config.requiredShippingContactFields.contains(.emailAddress))
XCTAssertTrue(config.requiredShippingContactFields.contains(.name))
XCTAssertTrue(config.requiredShippingContactFields.contains(.phoneticName))
XCTAssertTrue(config.requiredShippingContactFields.contains(.postalAddress))
let paymentRequest = try sut.buildPaymentRequest(payment: mockPayment)
XCTAssertEqual(paymentRequest.requiredShippingContactFields.count, 5)
XCTAssertTrue(paymentRequest.requiredShippingContactFields.contains(.phoneNumber))
XCTAssertTrue(paymentRequest.requiredShippingContactFields.contains(.emailAddress))
XCTAssertTrue(paymentRequest.requiredShippingContactFields.contains(.name))
XCTAssertTrue(paymentRequest.requiredShippingContactFields.contains(.phoneticName))
XCTAssertTrue(paymentRequest.requiredShippingContactFields.contains(.postalAddress))
}

// 'postalAddress' | 'name' | 'phoneticName' | 'phone' | 'email';
Expand Down
24 changes: 21 additions & 3 deletions example/ios/AdyenExampleTests/CardConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ final class CardConfigurationTests: XCTestCase {

func testFullAddressVisibility() throws {
let sut = CardConfigurationParser(configuration: ["card": ["addressVisibility": "full"]])
XCTAssertEqual(sut.configuration.billingAddressMode, .full)
XCTAssertEqual(sut.configuration.billingAddress.mode, .full)
}

func testPostalAddressVisibility() throws {
let sut = CardConfigurationParser(configuration: ["card": ["addressVisibility": "postal"]])
XCTAssertEqual(sut.configuration.billingAddressMode, .postalCode)
XCTAssertEqual(sut.configuration.billingAddress.mode, .postalCode)
}

func testHideKcpVisibility() throws {
Expand Down Expand Up @@ -85,7 +85,25 @@ final class CardConfigurationTests: XCTestCase {

func testBillingAddressCountryCodes() throws {
let sut = CardConfigurationParser(configuration: ["card": ["allowedAddressCountryCodes": ["GB", "US"]]])
XCTAssertEqual(sut.configuration.billingAddressCountryCodes?.count, 2)
XCTAssertEqual(sut.configuration.billingAddress.countryCodes?.count, 2)
}

}


extension CardComponent.AddressFormType: Equatable {

public static func == (lhs: Self, rhs: Self) -> Bool {
switch (lhs, rhs) {
case (.full, .full):
return true
case (.none, .none):
return true
case (.postalCode, .postalCode):
return true
default:
return false
}
}

}
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ target 'AdyenExample' do
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable the next line.
use_flipper!()
# use_flipper!()

post_install do |installer|
react_native_post_install(installer)
Expand Down
Loading
Loading