From 5e1e9203722c49657f0ae98f6270bfa8928fc80b Mon Sep 17 00:00:00 2001 From: AG Date: Sun, 26 May 2024 16:54:51 +0100 Subject: [PATCH] 2.2.0 --- .../CheckoutViewController.swift | 8 +++--- README.md | 17 ++++++------ gr4vy-iOS/Gr4vy.swift | 2 +- gr4vy-iOS/Gr4vyUtility.swift | 4 ++- gr4vy-iOSTests/gr4vy_iOSTests.swift | 26 +++++++++++++------ gr4vy-ios.podspec | 2 +- 6 files changed, 35 insertions(+), 24 deletions(-) diff --git a/Gr4vy UIKit Sample App/CheckoutViewController.swift b/Gr4vy UIKit Sample App/CheckoutViewController.swift index df80ff8..9721ffe 100644 --- a/Gr4vy UIKit Sample App/CheckoutViewController.swift +++ b/Gr4vy UIKit Sample App/CheckoutViewController.swift @@ -18,9 +18,8 @@ class CheckoutViewController: UIViewController { @IBAction func checkout(_ sender: Any) { - // TODO: Set your own token, buyerID and gr4vyID here + // TODO: Set your own token and gr4vyID here let token = "" - let buyerId = "" let gr4vyId = "" var categories = [String]() @@ -34,7 +33,6 @@ class CheckoutViewController: UIViewController { amount: 10873, currency: "USD", country: "US", - buyerId: buyerId, store: .false, cartItems: items, environment: .sandbox, @@ -82,8 +80,8 @@ class CheckoutViewController: UIViewController { case .transactionFailed(let transactionID, let status, let paymentMethodID): print("Handle transactionFailed here, ID: \(transactionID), Status: \(status), PaymentMethodID: \(paymentMethodID ?? "Unknown")") outcomeViewController.outcome = .failure(reason: "transactionFailed") - case .transactionCreated(let transactionID, let status, let paymentMethodID): - print("Handle transactionCreated here, ID: \(transactionID), Status: \(status), PaymentMethodID: \(paymentMethodID ?? "Unknown")") + case .transactionCreated(let transactionID, let status, let paymentMethodID, let approvalUrl): + print("Handle transactionCreated here, ID: \(transactionID), Status: \(status), PaymentMethodID: \(paymentMethodID ?? "Unknown"), approvalUrl: \(approvalUrl ?? "Unknown")") outcomeViewController.outcome = .success case .generalError(let error): print("Error: \(error.description)") diff --git a/README.md b/README.md index 5b4fea1..c5f0c6c 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ gr4vy-ios doesn't contain any external dependencies. use_frameworks! target 'YOUR_TARGET_NAME' do - pod 'gr4vy-ios', '2.1.1' + pod 'gr4vy-ios', '2.2.0' end ``` @@ -68,8 +68,8 @@ gr4vy?.launch( case .transactionFailed(let transactionID, let status, let paymentMethodID): print("Handle transactionFailed here, ID: \(transactionID), Status: \(status), PaymentMethodID: \(paymentMethodID ?? "Unknown")") return - case .transactionCreated(let transactionID, let status, let paymentMethodID): - print("Handle transactionCreated here, ID: \(transactionID), Status: \(status), PaymentMethodID: \(paymentMethodID ?? "Unknown")") + case .transactionCreated(let transactionID, let status, let paymentMethodID, let approvalUrl): + print("Handle transactionCreated here, ID: \(transactionID), Status: \(status), PaymentMethodID: \(paymentMethodID ?? "Unknown"), approvalUrl: \(approvalUrl ?? "Unknown")") return case .generalError(let error): print("Error: \(error.description)") @@ -92,8 +92,8 @@ let gr4vy = Gr4vy(gr4vyId: "[GR4VY_ID]", case .transactionFailed(let transactionID, let status, let paymentMethodID): print("Handle transactionFailed here, ID: \(transactionID), Status: \(status), PaymentMethodID: \(paymentMethodID ?? "Unknown")") return - case .transactionCreated(let transactionID, let status, let paymentMethodID): - print("Handle transactionCreated here, ID: \(transactionID), Status: \(status), PaymentMethodID: \(paymentMethodID ?? "Unknown")") + case .transactionCreated(let transactionID, let status, let paymentMethodID, let approvalUrl): + print("Handle transactionCreated here, ID: \(transactionID), Status: \(status), PaymentMethodID: \(paymentMethodID ?? "Unknown"), approvalUrl: \(approvalUrl ?? "Unknown")") return case .generalError(let error): print("Error: \(error.description)") @@ -156,8 +156,8 @@ onEvent: { event in case .transactionFailed(let transactionID, let status, let paymentMethodID): print("Handle transactionFailed here, ID: \(transactionID), Status: \(status), PaymentMethodID: \(paymentMethodID ?? "Unknown")") return - case .transactionCreated(let transactionID, let status, let paymentMethodID): - print("Handle transactionCreated here, ID: \(transactionID), Status: \(status), PaymentMethodID: \(paymentMethodID ?? "Unknown")") + case .transactionCreated(let transactionID, let status, let paymentMethodID, let approvalUrl): + print("Handle transactionCreated here, ID: \(transactionID), Status: \(status), PaymentMethodID: \(paymentMethodID ?? "Unknown"), approvalUrl: \(approvalUrl ?? "Unknown")") return case .generalError(let error): print("Error: \(error.description)") @@ -178,7 +178,8 @@ Returns a data about the transaction object when the transaction was successfull { "transactionID": "8724fd24-5489-4a5d-90fd-0604df7d3b83", "status": "pending", - "paymentMethodID": "17d57b9a-408d-49b8-9a97-9db382593003" + "paymentMethodID": "17d57b9a-408d-49b8-9a97-9db382593003", + "approvalUrl": "https://example.com" } ``` diff --git a/gr4vy-iOS/Gr4vy.swift b/gr4vy-iOS/Gr4vy.swift index c04df2f..2184b16 100644 --- a/gr4vy-iOS/Gr4vy.swift +++ b/gr4vy-iOS/Gr4vy.swift @@ -12,7 +12,7 @@ import SwiftUI import PassKit public enum Gr4vyEvent: Equatable { - case transactionCreated(transactionID: String, status: String, paymentMethodID: String?) + case transactionCreated(transactionID: String, status: String, paymentMethodID: String?, approvalUrl: String?) case transactionFailed(transactionID: String, status: String, paymentMethodID: String?) case cancelled case generalError(String) diff --git a/gr4vy-iOS/Gr4vyUtility.swift b/gr4vy-iOS/Gr4vyUtility.swift index fa891eb..7ce146c 100644 --- a/gr4vy-iOS/Gr4vyUtility.swift +++ b/gr4vy-iOS/Gr4vyUtility.swift @@ -102,7 +102,9 @@ struct Gr4vyUtility { guard let transactionID = data["id"] as? String else { return .generalError("Gr4vy Error: transaction success has failed, no transactionID and/or paymentMethodID found") } - return .transactionCreated(transactionID: transactionID, status: status, paymentMethodID: data["paymentMethodID"] as? String) + let paymentMethod = data["paymentMethod"] as? [String: Any] + let approvalUrl = paymentMethod?["approvalUrl"] as? String + return .transactionCreated(transactionID: transactionID, status: status, paymentMethodID: data["paymentMethodID"] as? String, approvalUrl: approvalUrl) // Failure statuses case "capture_declined", "authorization_failed": diff --git a/gr4vy-iOSTests/gr4vy_iOSTests.swift b/gr4vy-iOSTests/gr4vy_iOSTests.swift index 0ae2368..d30ad2b 100644 --- a/gr4vy-iOSTests/gr4vy_iOSTests.swift +++ b/gr4vy-iOSTests/gr4vy_iOSTests.swift @@ -566,42 +566,52 @@ class gr4vy_iOSTests: XCTestCase { payload = ["data": ["status": "capture_succeeded", "id": "123"]] sut = Gr4vyUtility.handleTransactionCreated(from: payload) - XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "capture_succeeded", paymentMethodID: nil), sut) + XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "capture_succeeded", paymentMethodID: nil, approvalUrl: nil), sut) payload = ["data": ["status": "capture_succeeded", "id": "123", "paymentMethodID": "ABC"]] sut = Gr4vyUtility.handleTransactionCreated(from: payload) - XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "capture_succeeded", paymentMethodID: "ABC"), sut) + XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "capture_succeeded", paymentMethodID: "ABC", approvalUrl: nil), sut) payload = ["data": ["status": "capture_pending", "id": "123"]] sut = Gr4vyUtility.handleTransactionCreated(from: payload) - XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "capture_pending", paymentMethodID: nil) , sut) + XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "capture_pending", paymentMethodID: nil, approvalUrl: nil) , sut) payload = ["data": ["status": "capture_pending", "id": "123", "paymentMethodID": "ABC"]] sut = Gr4vyUtility.handleTransactionCreated(from: payload) - XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "capture_pending", paymentMethodID: "ABC") , sut) + XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "capture_pending", paymentMethodID: "ABC", approvalUrl: nil) , sut) payload = ["data": ["status": "authorization_succeeded", "id": "123"]] sut = Gr4vyUtility.handleTransactionCreated(from: payload) - XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "authorization_succeeded", paymentMethodID: nil) , sut) + XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "authorization_succeeded", paymentMethodID: nil, approvalUrl: nil) , sut) payload = ["data": ["status": "authorization_succeeded", "id": "123", "paymentMethodID": "ABC"]] sut = Gr4vyUtility.handleTransactionCreated(from: payload) - XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "authorization_succeeded", paymentMethodID: "ABC") , sut) + XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "authorization_succeeded", paymentMethodID: "ABC", approvalUrl: nil) , sut) payload = ["data": ["status": "authorization_succeeded", "id": "123"]] sut = Gr4vyUtility.handleTransactionCreated(from: payload) - XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "authorization_succeeded", paymentMethodID: nil) , sut) + XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "authorization_succeeded", paymentMethodID: nil, approvalUrl: nil) , sut) payload = ["data": ["status": "authorization_pending", "id": "123", "paymentMethodID": "ABC"]] sut = Gr4vyUtility.handleTransactionCreated(from: payload) - XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "authorization_pending", paymentMethodID: "ABC") , sut) + XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "authorization_pending", paymentMethodID: "ABC", approvalUrl: nil) , sut) + + payload = ["data": ["status": "authorization_pending", "id": "123", "paymentMethodID": "ABC", "paymentMethod": ["approvalUrl": "123"]]] + + sut = Gr4vyUtility.handleTransactionCreated(from: payload) + XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "authorization_pending", paymentMethodID: "ABC", approvalUrl: "123"), sut) + + payload = ["data": ["status": "authorization_pending", "id": "123", "paymentMethodID": "ABC", "paymentMethod": []]] + + sut = Gr4vyUtility.handleTransactionCreated(from: payload) + XCTAssertEqual(Gr4vyEvent.transactionCreated(transactionID: "123", status: "authorization_pending", paymentMethodID: "ABC", approvalUrl: nil), sut) } func testHandleTransactionCreatedFails() { diff --git a/gr4vy-ios.podspec b/gr4vy-ios.podspec index 4f8b2d8..c4e458c 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.1.1' + s.version = '2.2.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'