如何从PayU支付网关成功付款后获得回复?

时间:2017-03-14 11:53:07

标签: ios iphone swift cocoa-touch 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 = "akshatrathore@live.com";  //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 个答案:

答案 0 :(得分: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 = "akshatrathore@live.com";  //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"                    }
  }