这是atom支付网关的一个问题,他们应该提供。h文件以及。文件,但在下载的文件中不可用。因此,我使用了另一种使用web视图的解决方案来集成atom支付网关。我已经为获取付款url创建了一个类。此方法使用网站中用于同一项目的web支付网关。
import Foundation
import Alamofire
import SwiftyXMLParser
class PaymentData {
var totalPrice:String
var taxId:String
var userName:String
var email:String
var mobile:String
var userId:String
var currentDateTimeString:String
init(totalPrice:String) {
let time = Date().timeIntervalSince1970
let taxId = "WVC"+String(time)
let userId = UserDefaults.standard.string(forKey: "UserId")
let name = UserDefaults.standard.string(forKey: "full_name")
let phone = UserDefaults.standard.string(forKey: "phone")
let email = UserDefaults.standard.string(forKey: "email")
self.totalPrice = totalPrice
self.taxId = taxId
self.userId = userId!
self.email = email!
self.mobile = phone!
self.userName = name!
self.currentDateTimeString = NSDate().getStringWith(format: "dd/MM/yyyy")!
}
func getVenderUrl()->String{
// Create vender url using user details
var vVenderURL:String = "https://payment.atomtech.in/paynetz/epi/fts?login=test&pass=test@123&ttype=NBFundTransfer&prodid=test&amt=" + "\(totalPrice)"+"&txncurr=INR&txnscamt=0&ru=https://www.test.in/payment-success&clientcode=lisas00940&txnid="+"\(taxId)"+"&date="+"\(currentDateTimeString)"+"&udf1="+"\(userName)"+"&udf2="+"\(email)"+"&udf3="+"\(mobile)"+"&udf4=Bangalore&custacc="+"\(userId)"+"";
vVenderURL = vVenderURL.replacingOccurrences(of: " ", with: "%20")
print(vVenderURL)
return vVenderURL
}
func getRedirectUrl(callBack:@escaping (URL)->Void){
// get url to load in webview
var xmlURL:String = ""
var xmlttype:String = ""
var xmltoken:String = ""
var xmltempTxnId:String = ""
var xmltxnStage:String = ""
let headers: HTTPHeaders = [
"Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
"Accept": "application/json"
]
// Call api for get payment url to load in webview
Alamofire.request(getVenderUrl(), method: .get, parameters: nil, encoding: URLEncoding.default, headers: headers)
.responseString { response in
var statusCode = response.response?.statusCode
switch response.result {
case .success:
// parsing xml data recieved from response, and extracting element required for generating the payment url
if let string = response.result.value {
print("XML: \(string)")
let xml = try! XML.parse(string)
print(xml["MMP","MERCHANT","RESPONSE"])
xmlURL = xml["MMP","MERCHANT","RESPONSE","url"].text!
let params = xml["MMP","MERCHANT","RESPONSE","param"]
for param in params {
if (param[0].attributes["name"]) == "ttype" {
xmlttype = param.text!
}
if (param[0].attributes["name"]) == "tempTxnId" {
xmltempTxnId = param.text!
}
if (param[0].attributes["name"]) == "token" {
xmltoken = param.text!
}
if (param[0].attributes["name"]) == "txnStage" {
xmltxnStage = param.text!
}
}
// creating payment url from extracted data
var Atom2Request:String = "\(xmlURL)" + "?ttype=" + "\(xmlttype)" + "&tempTxnId=" + "\(xmltempTxnId)" + "&token=" + "\(xmltoken)" + "&txnStage=" + "\(xmltxnStage)";
Atom2Request = Atom2Request.replacingOccurrences(of: " ", with: "%20") //(" ", "%20");
print("ATOM 2nd Request URl" + "\(Atom2Request)")
callBack(URL.init(string: Atom2Request)!)
}
case .failure(let error):
statusCode = error._code // statusCode private
print("status code is: \(String(describing: statusCode))")
print(error)
}
}
}
}
此类帮助创建用于为atom支付网关生成url的数据,下一步是将此url加载到web视图
创建视图控制器并在其中添加web视图,然后添加以下代码
@IBOutlet weak var paymentWebView: UIWebView!
var paymentAmount:String?
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Payment Gateway"
if paymentAmount != nil {
let paymentData = PaymentData.init(totalPrice: paymentAmount!)
paymentData.getRedirectUrl(callBack:{ url in
let request = URLRequest(url: url)
self.paymentWebView.loadRequest(request)
})
}
}