2017-03-14 126 views
0

我正在嘗試將PayU支付網關集成到我們的應用程序中。但成功付款後,我無法獲得回覆或付款狀態。我也張貼我的代碼。請幫我解決這個問題。PayU支付網關成功付款後如何獲得回覆?

import UIKit 

class PayUWebViewController: UIViewController, UIWebViewDelegate { 

    static let KEY = "W0weql" 
    static let SALT = "Q00w5qtc" 
    var params : PUMRequestParams = PUMRequestParams.shared() 

    var utils : Utils = Utils() 
    @IBOutlet weak var webView: UIWebView! 


    override func viewDidLoad() { 
     super.viewDidLoad() 


     params.amount = "0.50" 

     params.environment = PUMEnvironment.production; 
     params.firstname = "Akshat"; 
     params.key = PayUWebViewController.KEY; 
     params.merchantid = "1234567"; //Merchant merchantid 
     params.logo_url = ""; //Merchant logo_url 
     params.productinfo = "Product Info"; 
     params.email = "[email protected]"; //user email 
     params.phone = "1234567890"; //user phone 
     params.txnid = utils.getRandomString(2) //set your correct transaction id here 
     params.surl = "https://www.google.com"; 
     params.furl = "https://www.facebook.com"; 

     params.udf1 = ""; 
     params.udf2 = ""; 
     params.udf3 = ""; 
     params.udf4 = ""; 
     params.udf5 = ""; 
     params.udf6 = ""; 
     params.udf7 = ""; 
     params.udf8 = ""; 
     params.udf9 = ""; 
     params.udf10 = ""; 

     let hashSequence : NSString = "\(params.key!)|\(params.txnid!)|\(params.amount!)|\(params.productinfo!)|\(params.firstname!)|\(params.email!)|||||||||||\(PayUWebViewController.SALT)" as NSString 
     let data :NSString = utils.createSHA512(hashSequence as String!) as NSString 

     params.hashValue = data as String! 
     params.delegate = self 
     makePayURequest() 
    } 


    func makePayURequest() 
    { 

     let url = URL(string: "https://secure.payu.in/_payment")! 
     var request = URLRequest(url: url) 
     let params = "key=\(self.params.key!)&txnid=\(self.params.txnid!)&amount=\(self.params.amount!)&productinfo=\(self.params.productinfo!)&firstname=\(self.params.firstname!)&email=\(self.params.email!)&phone=\(self.params.phone!)&surl=\(self.params.surl!)&furl=\(self.params.furl!)&hash=\(self.params.hashValue!)" 
     request.httpBody = params.data(using: String.Encoding.utf8) 
     request.httpMethod = "POST" 
     request.cachePolicy = NSURLRequest.CachePolicy.reloadIgnoringCacheData 
     request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") 

     webView.loadRequest(request) 


    } 



    func webViewDidStartLoad(_ webView: UIWebView) { 
    } 

    func webViewDidFinishLoad(_ webView: UIWebView) { 
     let requestURL = self.webView.request?.url 
     let requestString:String = (requestURL?.absoluteString)! 


     if requestString == "https://www.google.com" { 
      print("success payment done") 
     } 
     else if requestString == "https://www.facebook.com" { 
      print("payment failure") 
     } 
    } 

    func webView(_ webView: UIWebView, didFailLoadWithError error: Error) { 
     print(error.localizedDescription) 
    } 

} 
+1

我希望密鑰和鹽是隨機的,不是真正的價值。在發佈機密信息時要非常小心。 – Scriptable

+0

你不應該在這裏使用webview,你應該使用API​​。看到這個其他答案:http://stackoverflow.com/questions/33908484/payu-money-gateway-ios-swift – Scriptable

+0

@Scriptable是這些關鍵和鹽值是隨機的,而不是真正的。 我已查看此鏈接。這裏也使用了網絡視圖,我們沒有收到任何迴應。 –

回答

0

在我來說,我已經使用https://github.com/payu-intrepos/PayUMoney-IOS-SDK例子中,你只需要設置

var params : PUMRequestParams = PUMRequestParams.shared() 
var utils : Utils = Utils() 

override func viewDidAppear(_ animated: Bool) { 
     params.amount = "0.50" 

    params.environment = PUMEnvironment.production; 
    params.firstname = "Akshat"; 
    params.key = PayUWebViewController.KEY; 
    params.merchantid = "1234567"; //Merchant merchantid 
    params.logo_url = ""; //Merchant logo_url 
    params.productinfo = "Product Info"; 
    params.email = "[email protected]"; //user email 
    params.phone = "1234567890"; //user phone 
    params.txnid = utils.getRandomString(2) //set your correct transaction id here 
    params.surl = "https://www.google.com"; 
    params.furl = "https://www.facebook.com"; 

    params.udf1 = ""; 
    params.udf2 = ""; 
    params.udf3 = ""; 
    params.udf4 = ""; 
    params.udf5 = ""; 
    params.udf6 = ""; 
    params.udf7 = ""; 
    params.udf8 = ""; 
    params.udf9 = ""; 
    params.udf10 = ""; 

    let hashSequence : NSString = "\(params.key!)|\(params.txnid!)|\(params.amount!)|\(params.productinfo!)|\(params.firstname!)|\(params.email!)|||||||||||\(PayUWebViewController.SALT)" as NSString 
    let data :NSString = utils.createSHA512(hashSequence as String!) as NSString 

    params.hashValue = data as String! 
    params.delegate = self; 
} 

func transactionCompleted(withResponse response : NSDictionary,errorDescription error:NSError) -> Void { 
    self.dismiss(animated: true){ 
     self.showAlertViewWithTitle(title: "Message", message: "congrats! Payment is Successful") 
     } 
    } 

func transactinFailed(withResponse response : NSDictionary,errorDescription error:NSError) -> Void { 
     self.dismiss(animated: true){ 
      self.showAlertViewWithTitle(title: "Message", message: "Oops!!! Payment Failed"     } 
    }