Skip to content

Commit

Permalink
1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
emp-ivaylohadzhiev committed Feb 20, 2024
1 parent 740fbe5 commit 2555170
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4.1;
MARKETING_VERSION = 1.5.0;
PRODUCT_BUNDLE_IDENTIFIER = com.emerchantpay.inapppayments;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -629,7 +629,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4.1;
MARKETING_VERSION = 1.5.0;
PRODUCT_BUNDLE_IDENTIFIER = com.emerchantpay.inapppayments;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,29 @@ extension TransactionDetailsViewController: UITableViewDelegate {

// MARK: - GenesisDelegate
extension TransactionDetailsViewController: GenesisDelegate {
func genesisDidFinishLoading() {
// empty

func genesisDidFinishLoading(userInfo: [AnyHashable: Any]) {
let uniqueId = userInfo[GenesisInfoKeys.uniqueId] ?? "N/A"
print("Loading transaction: \(uniqueId)")
}

func genesisDidEndWithSuccess() {
presentAlertWithTitle("Success", andMessage: "Success transaction")
func genesisDidEndWithSuccess(userInfo: [AnyHashable: Any]) {
let uniqueId = userInfo[GenesisInfoKeys.uniqueId]!
presentAlertWithTitle("Success", andMessage: "Success transaction: \(uniqueId)")
}

func genesisDidEndWithFailure(errorCode: GenesisError) {
func genesisDidEndWithFailure(userInfo: [AnyHashable: Any], errorCode: GenesisError) {
let uniqueId = userInfo[GenesisInfoKeys.uniqueId] ?? "N/A"
let code = errorCode.code ?? "unknown"
let technical = errorCode.technicalMessage ?? "unknown"
let message = errorCode.message ?? "unknown"
let details = "code: \(code)\n technical: \(technical)\n message: \(message)"
let details = "code: \(code)\ntechnical: \(technical)\nmessage: \(message)\nuniqueId: \(uniqueId)"
presentAlertWithTitle("Failure", andMessage: details)
}

func genesisDidEndWithCancel() {
presentAlertWithTitle("Canceled")
func genesisDidEndWithCancel(userInfo: [AnyHashable: Any]) {
let uniqueId = userInfo[GenesisInfoKeys.uniqueId] ?? "N/A"
presentAlertWithTitle("Cancelled", andMessage: "Cancelled transaction: \(uniqueId)")
}

func genesisValidationError(error: GenesisValidationError) {
Expand Down
2 changes: 1 addition & 1 deletion GenesisSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "GenesisSwift"
s.version = "1.4.1"
s.version = "1.5.0"
s.summary = "iOS Genesis Payment Gateway"
s.description = "The iOS Genesis Payment Gateway Swift SDK."
s.homepage = "https://github.com/GenesisGateway/ios_sdk.git"
Expand Down
4 changes: 2 additions & 2 deletions GenesisSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.4.1;
MARKETING_VERSION = 1.5.0;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++14";
ONLY_ACTIVE_ARCH = NO;
Expand Down Expand Up @@ -707,7 +707,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.4.1;
MARKETING_VERSION = 1.5.0;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++14";
OTHER_LDFLAGS = "";
Expand Down
34 changes: 22 additions & 12 deletions GenesisSwift/Genesis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@

import UIKit

public enum GenesisInfoKeys {
public static let uniqueId = "uniqueId" // String
public static let status = "status" // String
public static let transactionId = "transactionId" // String
public static let timestamp = "timestamp" // Date
public static let amount = "amount" // Double
public static let currency = "currency" // String
public static let redirectUrl = "redirectUrl" // String
}

public protocol GenesisDelegate: AnyObject {
func genesisDidFinishLoading()
func genesisDidEndWithSuccess()
func genesisDidEndWithCancel()
func genesisDidEndWithFailure(errorCode: GenesisError)
func genesisDidFinishLoading(userInfo: [AnyHashable: Any])
func genesisDidEndWithSuccess(userInfo: [AnyHashable: Any])
func genesisDidEndWithCancel(userInfo: [AnyHashable: Any])
func genesisDidEndWithFailure(userInfo: [AnyHashable: Any], errorCode: GenesisError)
func genesisValidationError(error: GenesisValidationError)
}

Expand Down Expand Up @@ -104,28 +114,28 @@ public class Genesis: NSObject {

extension Genesis: GenesisWebViewDelegate {

func genesisWebViewDidFinishLoading() {
func genesisWebViewDidFinishLoading(_ userInfo: [AnyHashable: Any]) {
genesisVC.indicator.stopAnimating()
genesisVC.addView((genesisWebView?.webView)!)

delegate.genesisDidFinishLoading()
delegate.genesisDidFinishLoading(userInfo: userInfo)
}

func genesisWebViewDidEndWithSuccess() {
func genesisWebViewDidEndWithSuccess(_ userInfo: [AnyHashable: Any]) {
back(animated: animatedBack)

delegate.genesisDidEndWithSuccess()
delegate.genesisDidEndWithSuccess(userInfo: userInfo)
}

func genesisWebViewDidEndWithCancel() {
func genesisWebViewDidEndWithCancel(_ userInfo: [AnyHashable: Any]) {
back(animated: animatedBack)

delegate.genesisDidEndWithCancel()
delegate.genesisDidEndWithCancel(userInfo: userInfo)
}

func genesisWebViewDidEndWithFailure(errorCode: GenesisError) {
func genesisWebViewDidEndWithFailure(_ userInfo: [AnyHashable: Any], errorCode: GenesisError) {
back(animated: animatedBack)

delegate.genesisDidEndWithFailure(errorCode: errorCode)
delegate.genesisDidEndWithFailure(userInfo: userInfo, errorCode: errorCode)
}
}
2 changes: 1 addition & 1 deletion GenesisSwift/Network/Response/WPFResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class WPFResponse: Response {
case "timestamp":
timestamp = string.dateFromISO8601
case "amount":
amount = Double(string)!
amount = Double(string) ?? 0
case "currency":
currency = string
case "redirect_url":
Expand Down
78 changes: 61 additions & 17 deletions GenesisSwift/UI/GenesisWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import UIKit
import WebKit

protocol GenesisWebViewDelegate: AnyObject {
func genesisWebViewDidFinishLoading()
func genesisWebViewDidEndWithSuccess()
func genesisWebViewDidEndWithCancel()
func genesisWebViewDidEndWithFailure(errorCode: GenesisError)
func genesisWebViewDidFinishLoading(_ userInfo: [AnyHashable: Any])
func genesisWebViewDidEndWithSuccess(_ userInfo: [AnyHashable: Any])
func genesisWebViewDidEndWithCancel(_ userInfo: [AnyHashable: Any])
func genesisWebViewDidEndWithFailure(_ userInfo: [AnyHashable: Any], errorCode: GenesisError)
}

final class GenesisWebView: NSObject {

private let request: PaymentRequest
private let configuration: Configuration
private var uniqueId: String?
private var response: Response?

let webView: WKWebView

Expand All @@ -44,56 +44,100 @@ final class GenesisWebView: NSObject {
let genesisErrorCode = GenesisError(code: GenesisErrorCode.eDataParsing.rawValue,
technicalMessage: "",
message: "Data parsing error")
self.genesisWebViewDelegate?.genesisWebViewDidEndWithFailure(errorCode: genesisErrorCode)
self.genesisWebViewDelegate?.genesisWebViewDidEndWithFailure(self.userInfo, errorCode: genesisErrorCode)
return
}

self.response = response

if let errorCode = response.errorCode, errorCode.code != nil {
self.genesisWebViewDelegate?.genesisWebViewDidEndWithFailure(errorCode: errorCode)
self.genesisWebViewDelegate?.genesisWebViewDidEndWithFailure(self.userInfo, errorCode: errorCode)
} else {
uniqueId = response.uniqueId

if let url = URL(string: response.redirectUrl) {
DispatchQueue.main.async { [weak self] in
self?.webView.load(URLRequest(url: url))
}
} else {
self.genesisWebViewDelegate?.genesisWebViewDidEndWithFailure(self.userInfo,
errorCode: GenesisError(message: "Invalid URL"))
}
}
}, failureHandler: { [weak self] error in
self?.genesisWebViewDelegate?.genesisWebViewDidEndWithFailure(errorCode: error)
guard let self else { return }
self.genesisWebViewDelegate?.genesisWebViewDidEndWithFailure(self.userInfo, errorCode: error)
})
}
}

private extension GenesisWebView {

func getErrorFromReconcileAndCallFailure() {
let reconcileRequest = ReconcileRequest(configuration: configuration, parameters: ["uniqueId": uniqueId!])
guard let uniqueId = response?.uniqueId else {
self.genesisWebViewDelegate?.genesisWebViewDidEndWithFailure(userInfo, errorCode: GenesisError(message: "error"))
return
}

let reconcileRequest = ReconcileRequest(configuration: configuration, parameters: ["uniqueId": uniqueId])
reconcileRequest.execute(successHandler: { [weak self] response in
guard let self else { return }
let userInfo = self.userInfo
if let response = response as? ReconcileResponse, let errorCode = response.errorCode {
self?.genesisWebViewDelegate?.genesisWebViewDidEndWithFailure(errorCode: errorCode)
self.genesisWebViewDelegate?.genesisWebViewDidEndWithFailure(userInfo, errorCode: errorCode)
} else {
self?.genesisWebViewDelegate?.genesisWebViewDidEndWithFailure(errorCode: GenesisError(message: "error"))
self.genesisWebViewDelegate?.genesisWebViewDidEndWithFailure(userInfo, errorCode: GenesisError(message: "error"))
}
}, failureHandler: { [weak self] error in
self?.genesisWebViewDelegate?.genesisWebViewDidEndWithFailure(errorCode: error)
guard let self else { return }
self.genesisWebViewDelegate?.genesisWebViewDidEndWithFailure(self.userInfo, errorCode: error)
})
}

var userInfo: [AnyHashable: Any] {
var info: [AnyHashable: Any] = [:]

guard let response else { return info }

if !response.uniqueId.isEmpty {
info[GenesisInfoKeys.uniqueId] = response.uniqueId
}
info[GenesisInfoKeys.status] = response.status.rawValue

if let response = response as? WPFResponse {
if !response.transactionId.isEmpty {
info[GenesisInfoKeys.transactionId] = response.transactionId
}
if let timestamp = response.timestamp {
info[GenesisInfoKeys.timestamp] = timestamp
}
info[GenesisInfoKeys.amount] = response.amount
if !response.currency.isEmpty {
info[GenesisInfoKeys.currency] = response.currency
}
if !response.redirectUrl.isEmpty {
info[GenesisInfoKeys.redirectUrl] = response.redirectUrl
}
}

return info
}
}

// MARK: WKNavigationDelegate
extension GenesisWebView: WKNavigationDelegate {

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
genesisWebViewDelegate?.genesisWebViewDidFinishLoading()
genesisWebViewDelegate?.genesisWebViewDidFinishLoading(userInfo)
}

func webView(_ webView: WKWebView,
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if let absoluteString = navigationAction.request.url?.absoluteString.lowercased() {
if absoluteString.contains(request.returnSuccessUrl.lowercased()) {
genesisWebViewDelegate?.genesisWebViewDidEndWithSuccess()
genesisWebViewDelegate?.genesisWebViewDidEndWithSuccess(userInfo)
decisionHandler(.cancel)
} else if absoluteString.contains(request.returnCancelUrl.lowercased()) {
genesisWebViewDelegate?.genesisWebViewDidEndWithCancel()
genesisWebViewDelegate?.genesisWebViewDidEndWithCancel(userInfo)
decisionHandler(.cancel)
} else if absoluteString.contains(request.returnFailureUrl.lowercased()) {
decisionHandler(.cancel)
Expand Down
21 changes: 17 additions & 4 deletions GenesisSwiftTests/GenesisTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,31 @@ final class GenesisTest: XCTestCase {
// MARK: - GenesisDelegate
extension GenesisTest: GenesisDelegate {

func genesisDidFinishLoading() {
func genesisDidFinishLoading(userInfo: [AnyHashable: Any]) {
print("Loading transaction: \(userInfo[GenesisInfoKeys.uniqueId]!)")
}

func genesisDidEndWithSuccess() {
func genesisDidEndWithSuccess(userInfo: [AnyHashable: Any]) {
print("""
Transaction succeeded
uniqueId: \(userInfo[GenesisInfoKeys.uniqueId]!),
status: \(userInfo[GenesisInfoKeys.status]!),
transactionId: \(userInfo[GenesisInfoKeys.transactionId]!),
timestamp: \((userInfo[GenesisInfoKeys.timestamp] as? Date)!),
amount: \((userInfo[GenesisInfoKeys.timestamp] as? Double)!),
currency: \(userInfo[GenesisInfoKeys.currency]!)
""")
}

func genesisDidEndWithFailure(errorCode: GenesisError) {
func genesisDidEndWithCancel(userInfo: [AnyHashable: Any]) {
print("Transaction cancelled: \(userInfo[GenesisInfoKeys.uniqueId]!)")
}

func genesisDidEndWithCancel() {
func genesisDidEndWithFailure(userInfo: [AnyHashable: Any], errorCode: GenesisError) {
print("Transaction failed: \(userInfo[GenesisInfoKeys.uniqueId] ?? "N/A")")
}

func genesisValidationError(error: GenesisValidationError) {
print("Error: \(error.errorUserInfo)")
}
}
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

## Requirements

- iOS 9.0+
- Xcode 9.2
- iOS 12.0+
- Xcode 10.0+

## Installation

GenesisSwift requires Swift 4, so make sure you have [Xcode 9](https://developer.apple.com/xcode/downloads/).
GenesisSwift requires Swift 5, so make sure you have at least [Xcode 10](https://developer.apple.com/xcode/downloads/).

### CocoaPods

Expand Down Expand Up @@ -107,24 +107,36 @@ show(genesisViewController, sender: nil)
// MARK: - GenesisDelegate
extension YourViewController: GenesisDelegate {

func genesisDidFinishLoading() {
func genesisDidFinishLoading(userInfo: [AnyHashable: Any]) {
print("Loading transaction: \(userInfo[GenesisInfoKeys.uniqueId]!)")
...
}

func genesisDidEndWithSuccess() {
func genesisDidEndWithSuccess(userInfo: [AnyHashable: Any]) {
print("""
Transaction succeeded
uniqueId: \(userInfo[GenesisInfoKeys.uniqueId]!),
status: \(userInfo[GenesisInfoKeys.status]!),
transactionId: \(userInfo[GenesisInfoKeys.transactionId]!),
timestamp: \((userInfo[GenesisInfoKeys.timestamp] as? Date)!),
amount: \((userInfo[GenesisInfoKeys.timestamp] as? Double)!),
currency: \(userInfo[GenesisInfoKeys.currency]!)
""")
...
}

func genesisDidEndWithFailure(errorCode: GenesisErrorCode) {
func genesisDidEndWithCancel(userInfo: [AnyHashable: Any]) {
print("Transaction cancelled: \(userInfo[GenesisInfoKeys.uniqueId]!)")
...
}

func genesisDidEndWithCancel() {
func genesisDidEndWithFailure(userInfo: [AnyHashable: Any], errorCode: GenesisError) {
print("Transaction failed: \(userInfo[GenesisInfoKeys.uniqueId] ?? "N/A")")
...
}

func genesisValidationError(error: GenesisValidationError) {
print(error.errorUserInfo)
print("Parameter(s) validation error: \(error.errorUserInfo)")
...
}
}
Expand Down

0 comments on commit 2555170

Please sign in to comment.