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

2.2.0 - approvalUrl #10

Merged
merged 1 commit into from
May 28, 2024
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
8 changes: 3 additions & 5 deletions Gr4vy UIKit Sample App/CheckoutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<TOKEN HERE>"
let buyerId = "<BUYER ID HERE>"
cbetta marked this conversation as resolved.
Show resolved Hide resolved
let gr4vyId = "<GR4VY ID HERE>"

var categories = [String]()
Expand All @@ -34,7 +33,6 @@ class CheckoutViewController: UIViewController {
amount: 10873,
currency: "USD",
country: "US",
buyerId: buyerId,
store: .false,
cartItems: items,
environment: .sandbox,
Expand Down Expand Up @@ -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)")
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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)")
Expand All @@ -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)")
Expand Down Expand Up @@ -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)")
Expand All @@ -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"
}
```

Expand Down
2 changes: 1 addition & 1 deletion gr4vy-iOS/Gr4vy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion gr4vy-iOS/Gr4vyUtility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
26 changes: 18 additions & 8 deletions gr4vy-iOSTests/gr4vy_iOSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion gr4vy-ios.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Loading