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 all 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
154 changes: 76 additions & 78 deletions example/ios/AdyenExampleTests/ApplePayConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,65 @@

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")

func testNewDictionary() throws {
let sut = ApplepayConfigurationParser(configuration: NSDictionary())
XCTAssertNotNil(sut)
}

func testEmptyDictionary() throws {
let sut = ApplepayConfigurationParser(configuration: [:])
XCTAssertNotNil(sut)
}

func testEmptySubDictionary() throws {
let sut = ApplepayConfigurationParser(configuration: ["applepay":[:]])
let sut = ApplepayConfigurationParser(configuration: ["applepay": [:]])
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()
}

self.wait(for: [expectation], timeout: 1)
}

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()
}

self.wait(for: [expectation], timeout: 1)
}

func testThrowOnNoMerchantNameMerchantID() throws {
let sut = ApplepayConfigurationParser(configuration: [
"applepay":
[
"merchantID": "someID"
]
])

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()
}

self.wait(for: [expectation], timeout: 1)
}

func testMinimalValidDictionaryValues() throws {
let sut = ApplepayConfigurationParser(configuration: [
"applepay":
Expand All @@ -72,23 +73,23 @@ 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 {
let sut = ApplepayConfigurationParser(configuration: [
"applepay":
Expand All @@ -114,16 +115,16 @@ 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 {
let sut = ApplepayConfigurationParser(configuration: ["applepay":
[
Expand All @@ -132,14 +133,14 @@ 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()
}

self.wait(for: [expectation], timeout: 1)
}

func testAllowOnboardingBoolValue() throws {
let sut = ApplepayConfigurationParser(configuration: [
"applepay":
Expand All @@ -149,10 +150,9 @@ final class ApplePayConfigurationTests: XCTestCase {
"allowOnboarding": true
]
])
let config = try sut.buildConfiguration(amount: mockAmount)
XCTAssertTrue(config.allowOnboarding)
XCTAssertTrue(sut.allowOnboarding)
}

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

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

func testBillingAddress() throws {
let sut = ApplepayConfigurationParser(configuration: [
"applepay":
Expand All @@ -203,8 +201,8 @@ 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 All @@ -220,7 +218,7 @@ final class ApplePayConfigurationTests: XCTestCase {
XCTAssertEqual(contact.postalAddress?.country, "Country")
XCTAssertEqual(contact.postalAddress?.isoCountryCode, "US")
}

func testBillingAddressWIthNoPhoneticNameAndNoAddress() throws {
let sut = ApplepayConfigurationParser(configuration: [
"applepay":
Expand All @@ -230,12 +228,12 @@ final class ApplePayConfigurationTests: XCTestCase {
"billingContact": [
"phoneNumber": "123-456-7890",
"givenName": "John",
"familyName": "Doe",
"familyName": "Doe"
]
]
])
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 @@ -244,7 +242,7 @@ final class ApplePayConfigurationTests: XCTestCase {
XCTAssertNil(contact.postalAddress)
XCTAssertNil(contact.emailAddress)
}

func testBillingAddressWIthNoName() throws {
let sut = ApplepayConfigurationParser(configuration: [
"applepay":
Expand All @@ -254,20 +252,20 @@ final class ApplePayConfigurationTests: XCTestCase {
"billingContact": [
"emailAddress": "[email protected]",
"phoneticGivenName": "John",
"phoneticFamilyName": "Doe",
"phoneticFamilyName": "Doe"
]
]
])
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)
XCTAssertNil(contact.name?.familyName)
XCTAssertEqual(contact.name?.phoneticRepresentation?.givenName, "John")
XCTAssertEqual(contact.name?.phoneticRepresentation?.familyName, "Doe")
}

func testRequiredBillingFiledsWithEmptyArray() throws {
let sut = ApplepayConfigurationParser(configuration: [
"applepay":
Expand All @@ -277,10 +275,10 @@ 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 {
let sut = ApplepayConfigurationParser(configuration: [
"applepay":
Expand All @@ -290,13 +288,13 @@ 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 {
let sut = ApplepayConfigurationParser(configuration: [
"applepay":
Expand All @@ -306,16 +304,16 @@ 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';

// 'postalAddress' | 'name' | 'phoneticName' | 'phone' | 'email';
func testPKContactField() throws {
XCTAssertNotEqual(PKContactField.init(rawValue: "phoneNumber"), PKContactField.phoneNumber)
XCTAssertEqual(PKContactField.init(rawValue: "phone"), PKContactField.phoneNumber)
Expand All @@ -326,5 +324,5 @@ final class ApplePayConfigurationTests: XCTestCase {
XCTAssertEqual(PKContactField.init(rawValue: "phoneticName"), PKContactField.phoneticName)
XCTAssertEqual(PKContactField.init(rawValue: "name"), PKContactField.name)
}

}
Loading