diff --git a/RaveSDK/Classes/NativeScript/NSRave.swift b/RaveSDK/Classes/NativeScript/NSRave.swift new file mode 100644 index 0000000..f338f26 --- /dev/null +++ b/RaveSDK/Classes/NativeScript/NSRave.swift @@ -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 + } +} \ No newline at end of file diff --git a/RaveSDK/Classes/NativeScript/NSRaveDelegate.swift b/RaveSDK/Classes/NativeScript/NSRaveDelegate.swift new file mode 100644 index 0000000..06241b7 --- /dev/null +++ b/RaveSDK/Classes/NativeScript/NSRaveDelegate.swift @@ -0,0 +1,4 @@ +@objc public protocol NSRaveDelegate { + func onSuccess(_ data: Any, _ response: Any) + func onError(_ data: Any, _ response: Any) +} \ No newline at end of file diff --git a/RaveSDK/Classes/Utils/LoadingHUD.swift b/RaveSDK/Classes/Utils/LoadingHUD.swift index d65be5a..b46600b 100644 --- a/RaveSDK/Classes/Utils/LoadingHUD.swift +++ b/RaveSDK/Classes/Utils/LoadingHUD.swift @@ -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 @@ -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)