Skip to content

Patch/nativescript #8

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
64 changes: 64 additions & 0 deletions RaveSDK/Classes/NativeScript/NSRave.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import UIKit

func jsonToString(_ jsonData: [String:Any]) -> String {
do {
let data = try JSONSerialization.data(withJSONObject: jsonData);
guard let str = String(data: data, encoding: String.Encoding.utf8) else { return "" };
return str;
} catch _ {
return "";
}
}

@objcMembers
public class NSRave: UIViewController, RavePayProtocol {
public var publicKey:String?
public var encryptionKey:String?
public var isStaging:Bool = true
public var email:String?
public var firstName:String?
public var lastName:String?
public var phoneNumber:String?
public var transcationRef:String?
public var country:String = "NG"
public var currencyCode:String = "NGN"
public var narration:String?
public var amount:String?
public var delegate: NSRaveDelegate?

public func tranasctionSuccessful(flwRef: String?, responseData: [String : Any]?) {
let data = jsonToString(responseData ?? ["": ""])
self.delegate?.onSuccess(flwRef ?? "", data)
}

public func tranasctionFailed(flwRef: String?, responseData: [String : Any]?) {
let data = jsonToString(responseData ?? ["": ""])
self.delegate?.onError(flwRef ?? "", data)
}

public func initRave(view: UIViewController) -> NSRave {

let config = RaveConfig.sharedConfig()
config.country = self.country
config.currencyCode = self.currencyCode
config.email = self.email
config.isStaging = self.isStaging
config.phoneNumber = self.phoneNumber
config.transcationRef = self.transcationRef
config.firstName = self.firstName
config.lastName = self.lastName
config.meta = [["metaname":"sdk", "metavalue":"ios"]]

config.publicKey = self.publicKey
config.encryptionKey = self.encryptionKey

let controller = NewRavePayViewController()
let nav = UINavigationController(rootViewController: controller)
controller.amount = self.amount
controller.delegate = self

view.present(nav, animated: true)

return self
}
}
4 changes: 4 additions & 0 deletions RaveSDK/Classes/NativeScript/NSRaveDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@objc public protocol NSRaveDelegate {
func onSuccess(_ data: Any, _ response: Any)
func onError(_ data: Any, _ response: Any)
}
4 changes: 2 additions & 2 deletions RaveSDK/Classes/Utils/LoadingHUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Lottie

class LoadingHUD: UIView {
//let appDelegate = UIApplication.shared.delegate as? AppDelegate
var animation:AnimationView!
var animation: AnimationView!

var bgColor: UIColor? = .clear
var applyBlur = true
Expand Down Expand Up @@ -58,7 +58,7 @@ class LoadingHUD: UIView {
}


animation = AnimationView(name: animationFile, bundle: Bundle.getResourcesBundle() ?? Bundle.main)
animation = AnimationView(name: animationFile, bundle: Bundle.getResourcesBundle() ?? Bundle.main)
animation.loopMode = .loop
animation.translatesAutoresizingMaskIntoConstraints = false
addSubview(animation)
Expand Down