iOS SDK
IOS SDK for NeoX Payment Gateway
Use
import SwiftUI
import NeoPaySDK
struct Payment: View {
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
var method: String
@Binding var showingAlert:Bool
@Binding var alert:String
var amount: Int64
var body: some View {
let request = NeoRequest(
neo_MerchantCode: "HUYEN1",
neo_PaymentMethod: self.method,
neo_Amount: amount,
neo_MerchantTxnID:"T" + String(Int.random(in: 0..<9999)),
neo_OrderID: "DH" + String(Int(Date().timeIntervalSince1970)),
neo_OrderInfo:"123",
secureHash: "123456",
neo_ENV: .uat
)
let customHeader = NeoCustomHeader()
let customButton = NeoCustomButton(
// title: "Thanh toán",
// textColor: "#fff",
// background: "blue"
)
let params = NeoParams(request: request, backHandler: {
self.presentationMode.wrappedValue.dismiss()
}, customHeader: customHeader,customButton: customButton) { success, failure in
if let success = success {
print("success \(success)")
}
if let failure = failure {
print("failure \(failure)")
}
}
VStack{
NeoSDKView(params:params)
}.hiddenNavigationBarStyle()
}
}
import SwiftUI
import NeoPaySDK
struct Payment: View {
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
var method: String
@Binding var showingAlert:Bool
@Binding var alert:String
var amount: Int64
var body: some View {
let request = NeoRequest(
neo_MerchantCode: "HUYEN1",
neo_PaymentMethod: self.method,
neo_Amount: amount,
neo_MerchantTxnID:"T" + String(Int.random(in: 0..<9999)),
neo_OrderID: "DH" + String(Int(Date().timeIntervalSince1970)),
neo_OrderInfo:"123",
secureHash: "123456",
neo_ENV: .uat
)
let customHeader = NeoCustomHeader()
let customButton = NeoCustomButton(
// title: "Thanh toán",
// textColor: "#fff",
// background: "blue"
)
let params = NeoParams(request: request, backHandler: {
self.presentationMode.wrappedValue.dismiss()
}, customHeader: customHeader,customButton: customButton) { success, failure in
if let success = success {
print("success \(success)")
}
if let failure = failure {
print("failure \(failure)")
}
}
VStack{
NeoSDKView(params:params)
}.hiddenNavigationBarStyle()
}
}
// ViewController.m
#import "ViewController.h"
#import "DemoObjectiveC-Swift.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// NSLog(@"The code runs through here!");
// Do any additional setup after loading the view.
}
- (IBAction)buttonTapped:(id)sender {
NSInteger *amount = 10000;
NSTimeInterval timeInSeconds = [[NSDate date] timeIntervalSince1970];
NSString *timeInSecondsString = [NSString stringWithFormat:@"%d",timeInSeconds];
NSString *orderID = [@"DH" stringByAppendingString:timeInSecondsString];
NSLog(orderID);
[self displayNeoPaySDKWithAmount:amount orderID:orderID];
}
@end
displayNeoPaySDKWithAmount (function in SDKView file)
// SDKView
import Foundation
import NeoPaySDK
import SwiftUI
@objc extension ViewController {
func displayNeoPaySDK(amount:Int64 = 0,orderID:String){
let host = UIHostingController(rootView: SDKView(amount:amount,orderID: orderID))
host.modalPresentationStyle = .fullScreen
self.present(host, animated: true)
}
}
struct SDKView: View{
public init(amount :Int64 = 0,orderID:String) {
// print("Vo day may lan")
self.amount = amount
self.orderID = orderID
}
var amount:Int64 = 0
var orderID:String = ""
@Environment(\.dismiss) var dismiss
@State private var showingAlert = false
@State private var alert = ""
var body:some View {
let request = NeoRequest(
neo_MerchantCode: "HUYEN1",
neo_PaymentMethod: "",
neo_Amount: self.amount,
neo_MerchantTxnID:"T" + String(Int.random(in: 0..<9999)),
neo_OrderID: self.orderID ?? "DH" + String(Int(Date().timeIntervalSince1970)),
neo_OrderInfo:"123",
secureHash: "123456",
neo_ENV: .uat
)
let params = NeoParams(request: request, backHandler: {
self.dismiss()
}) { success, failure in
if let success = success {
print("success ne \(success)")
self.showingAlert = true
self.alert = "Thanh toán thành công"
// self.dismiss()
}
if let failure = failure {
print("failure ne \(failure)")
self.showingAlert = true
self.alert = "Thanh toán thất bại"
}
}
VStack{
if self.showingAlert == false && self.alert == ""{
NeoSDKView(params:params)
}
else{
Button(action: {
}) {
Text("")
}.alert(isPresented: $showingAlert) {
Alert(title: Text("Thông báo"), message: Text(alert), dismissButton: .destructive(Text("Đồng ý")) {
self.dismiss()
})
}
}
}
}
}
Methods
NeoSDKView (params:NeoParams)
NeoParams(request,backHandler,customHeader)
NeoRequest
NeoCustomHeader
NeoCustomButton
Callback
Callback data from onSuccess and onFailure
Last updated