Updated 30 October 2020
Steps 1:- Add the ‘NISdk’ pod to the podfile of your project.
1 2 3 4 5 |
target 'App' do use_frameworks! pod 'NISdk' end |
After adding the NISdk run pod install.
Steps 2:- The next step is to create an order, to accept payment from the app. you have to create an order and send it to the merchant server.
you can check the merchant server sample code from here.
Now you have to create a view controller for creating order in which you hit your serve API.
Create a view controller example “CreateOrderViewController” and now import the NISdk in your controller.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
import Foundation import UIKit import PassKit import SwiftyJSON import NISdk class CreateOrderViewController: UIViewController { let amount: Double let paymentDelegate: CardPaymentDelegate? let paymentMethod: PaymentMethod? let purchasedItems: [Product] var currency:String = "" var countryCode: String = "" var paymentRequest: PKPaymentRequest? var action: String = "" var transactioId: String = "" var transactioClosure:((String)->Void)? init(amount: Double, and paymentDelegate: CardPaymentDelegate, using paymentMethod: PaymentMethod = .Card, with purchasedItems: [Product],currency:String,countryCode:String,action: String) { self.paymentDelegate = paymentDelegate self.amount = amount self.paymentMethod = paymentMethod self.purchasedItems = purchasedItems self.currency = currency self.countryCode = countryCode self.action = action super.init(nibName: nil, bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) not implemented") } override func viewDidLoad() { super.viewDidLoad() self.createOrder() } func createOrder() { self.view.isUserInteractionEnabled = false var requstParams = [String:Any]() let amount = ["currencyCode":currency,"value":"\(Int(amount))"] requstParams["postData"] = ["action": action,"amount":amount] print(requstParams) NetworkManager.sharedInstance.callingHttpRequest(params:requstParams, method: .post, apiname: createorderApiName, currentView: self){success,responseObject in if success == 1{ self.view.isUserInteractionEnabled = true guard let dict = responseObject as? NSDictionary else { return } guard let myData = dict["response"] else {return} let payment = JSON(myData) if let pay = payment["_embedded"]["payment"].array{ self.transactioId = pay.first?["orderReference"].stringValue ?? "" } do { let orderResponse: OrderResponse = try JSONDecoder().decode(OrderResponse.self, from: ((json(from: myData)?.data(using: .utf8))!)) let sharedSDKInstance = NISdk.sharedInstance DispatchQueue.main.async { self.dismiss(animated: false, completion: { [weak self] in sharedSDKInstance.showCardPaymentViewWith(cardPaymentDelegate: (self?.cardPaymentDelegate!)!, overParent: self?.cardPaymentDelegate as! UIViewController, for: orderResponse) self?.transactioClosure?(self?.transactioId ?? "") }) } } catch let error { print(error) } }else if success == 2{ NetworkManager.sharedInstance.dismissLoader() self.createOrder() } } } } |
Step 3:- Now you have to initialize and present your CreateOrderViewController.
After initializing you have to call createOrder method in order to hit the server API. After getting the success response you have to show a card view by passing the required param.
Step 4:- This is the last step for CardPaymentdelegate method to receive a card payment event.
In order to integrate the N-Genius payment gateway, please follows the above steps and if you have any queries or suggestion then you can comment on the comment section.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.