diff --git a/gr4vy-iOS/Gr4vyUtility.swift b/gr4vy-iOS/Gr4vyUtility.swift index 29371f3..5f949e9 100644 --- a/gr4vy-iOS/Gr4vyUtility.swift +++ b/gr4vy-iOS/Gr4vyUtility.swift @@ -168,6 +168,7 @@ struct Gr4vyUtility { guard let data = payload["data"] as? [String: Any], let countryCode = data["countryCode"] as? String, let currencyCode = data["currencyCode"] as? String, + let supportedNetworks = data["supportedNetworks"] as? [String], let total = data["total"] as? [String: Any], let value = merchantName ?? total["label"] as? String, let amount = total["amount"] as? String else { @@ -176,25 +177,25 @@ struct Gr4vyUtility { let paymentItem = PKPaymentSummaryItem.init(label: value, amount: NSDecimalNumber(string: amount)) - let paymentNetworks = [ - PKPaymentNetwork.amex, - PKPaymentNetwork.cartesBancaires, - PKPaymentNetwork.discover, - PKPaymentNetwork.eftpos, - PKPaymentNetwork.electron, - PKPaymentNetwork.elo, - PKPaymentNetwork.interac, - PKPaymentNetwork.JCB, - PKPaymentNetwork.mada, - PKPaymentNetwork.maestro, - PKPaymentNetwork.masterCard, - PKPaymentNetwork.privateLabel, - PKPaymentNetwork.visa, - PKPaymentNetwork.vPay + let networksMap: [String: PKPaymentNetwork] = [ + "amex": .amex, + "cartesbancaires": .cartesBancaires, + "discover": .discover, + "eftpos": .eftpos, + "electron": .electron, + "elo": .elo, + "interac": .interac, + "jcb": .JCB, + "mada": .mada, + "maestro": .maestro, + "mastercard": .masterCard, + "privatelabel": .privateLabel, + "visa": .visa, + "vpay": .vPay ] - guard deviceSupportsApplePay(paymentNetworks: paymentNetworks) else { - return nil + let paymentNetworks = supportedNetworks.compactMap { network in + networksMap[network.lowercased()] } let request = PKPaymentRequest() diff --git a/gr4vy-iOSTests/gr4vy_iOSTests.swift b/gr4vy-iOSTests/gr4vy_iOSTests.swift index 59b5ee9..4b03d82 100644 --- a/gr4vy-iOSTests/gr4vy_iOSTests.swift +++ b/gr4vy-iOSTests/gr4vy_iOSTests.swift @@ -748,7 +748,7 @@ class gr4vy_iOSTests: XCTestCase { } func testHandleAppleStartSucceeds() { - var payload: [String: Any] = ["data": ["countryCode": "countryCode", "currencyCode": "currencyCode", "total": ["label": "label", "amount": "123"]]] + var payload: [String: Any] = ["data": ["supportedNetworks": ["VISA", "MASTERCARD"], "countryCode": "countryCode", "currencyCode": "currencyCode", "total": ["label": "label", "amount": "123"]]] let merchantId: String = "merchantID" var sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil) @@ -756,18 +756,10 @@ class gr4vy_iOSTests: XCTestCase { sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test") XCTAssertNotNil(sut) - - payload = ["data": ["supportedNetworks": ["VISA", "MASTERCARD"], "countryCode": "countryCode", "currencyCode": "currencyCode", "total": ["label": "label", "amount": "123"]]] - - sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil) - XCTAssertNotNil(sut) - - sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test") - XCTAssertNotNil(sut) } func testHandleAppleStartFails() { - var payload: [String: Any] = ["data": ["countryCode": "countryCode", "currencyCode": "currencyCode", "total": ["label": "label", "amount": "123"]]] + var payload: [String: Any] = ["data": ["supportedNetworks": ["VISA", "MASTERCARD"], "countryCode": "countryCode", "currencyCode": "currencyCode", "total": ["label": "label", "amount": "123"]]] let merchantId: String = "merchantID" var sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil) @@ -776,6 +768,22 @@ class gr4vy_iOSTests: XCTestCase { sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test") XCTAssertNotNil(sut) + payload = ["data": ["supportedNetworks": [], "countryCode": "countryCode", "currencyCode": "currencyCode", "total": ["label": "label", "amount": "123"]]] + + sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil) + XCTAssertNotNil(sut) + + sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test") + XCTAssertNotNil(sut) + + payload = ["data": ["countryCode": "countryCode", "currencyCode": "currencyCode", "total": ["label": "label", "amount": "123"]]] + + sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil) + XCTAssertNil(sut) + + sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test") + XCTAssertNil(sut) + payload = ["data": ["currencyCode": "currencyCode", "total": ["label": "label", "amount": "123"]]] sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil) @@ -808,7 +816,7 @@ class gr4vy_iOSTests: XCTestCase { sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test") XCTAssertNil(sut) - payload = ["data": ["countryCode": "countryCode", "currencyCode": "currencyCode", "total": ["amount": "123"]]] + payload = ["data": ["supportedNetworks": [], "countryCode": "countryCode", "currencyCode": "currencyCode", "total": ["amount": "123"]]] sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil) XCTAssertNil(sut) diff --git a/gr4vy-ios.podspec b/gr4vy-ios.podspec index b5cb4c4..54aa1f2 100644 --- a/gr4vy-ios.podspec +++ b/gr4vy-ios.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'gr4vy-ios' - s.version = '2.4.4' + s.version = '2.5.0' s.license = 'MIT' s.summary = 'Quickly embed Gr4vy in your iOS app to store card details, authorize payments, and capture a transaction.' s.homepage = 'https://github.com/gr4vy/gr4vy-ios'