ios - Payu Swift 集成中 PayUCreateRequest 的 createRequest() 函数中的 NSURL 问题

标签 ios payu

我正在使用 Swift 语言将 Payu 集成到 iOS 应用程序中。由于Payu没有提供iOS SDK和文档,所以我使用的链接是Integrating PayU Money Gateway iOS SwiftHow to integrate PayU Money in swift .但是我在两个集成中都面临同样的问题。

问题:调用了 [NSURL init];这会导致 NSURL 实例带有一个空的 URL 字符串。请改用已记录的 NSURL 初始化方法之一(initWithString:、initFileURLWithPath: 等)。此消息仅显示一次。

我正在使用的代码(来自链接 1):

 import UIKit

class ViewController: UIViewController {

    @IBAction func onTapBtnPay(_ sender: UIButton) {
        continueWithCardPayment()
        createRequest.createRequest(withPaymentParam: paymentParamForPassing,forPaymentType: PAYMENT_PG_PAYU_MONEY , withCompletionBlock: {(request, postParam , error) in
            if error == nil {
                print("Success")
            }
            else
            {
                print("Error data : \(error.debugDescription)")
                print("Failure")
            }
        })
    }

    var paymentParamForPassing = PayUModelPaymentParams()
    var webServiceResponse: PayUWebServiceResponse = PayUWebServiceResponse()
    var createRequest: PayUCreateRequest = PayUCreateRequest()

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func continueWithCardPayment()  {

        paymentParamForPassing.key = "0MQaQP"
        paymentParamForPassing.transactionID = "Ywism0Q9XC88qvy";
        paymentParamForPassing.amount = "10.0"
        paymentParamForPassing.productInfo = "Nokia";
        paymentParamForPassing.firstName = "Ram";
        paymentParamForPassing.email = "email@testsdk1.com";
        paymentParamForPassing.userCredentials = "ra:ra";
        paymentParamForPassing.phoneNumber = "1111111111";
        paymentParamForPassing.surl = "https://www.google.com/";
        paymentParamForPassing.furl = "https://www.facebook.com/";
        paymentParamForPassing.udf1 = "u1";
        paymentParamForPassing.udf2 = "u2";
        paymentParamForPassing.udf3 = "u3";
        paymentParamForPassing.udf4 = "u4";
        paymentParamForPassing.udf5 = "u5";
        paymentParamForPassing.environment = ENVIRONMENT_MOBILETEST
        paymentParamForPassing.offerKey =  "offertest 1411";

        paymentParamForPassing.hashes.paymentHash =  "ade84bf6dd9da35d0aab50a5bf61d6272ab0fc488b361b65c66745054aacf1900e3c60b5022d2114bae7360174ebcb3cd7185a5d472e5c99701e5e7e1eccec34";
        paymentParamForPassing.hashes.paymentRelatedDetailsHash =  "915299224c80eff0eb2407b945a5087556292f58baca25fd05a0bceb6826aa9eb531810001dd4b4677dd928dd60d39eecf843b2189f213f9bb82c5a9483e3aac";
        paymentParamForPassing.hashes.vasForMobileSDKHash =  "5c0314c2781876f7e0a53676b0d08e1457dafe904d2d15d948626b57409538d51093eef4f15c792b1b9651be7b5659efdd45926e43a1145d68cea094687011ca";
        paymentParamForPassing.hashes.deleteUserCardHash =  "03e10e892005755f91061121036fb1b10f46202b4138d182f153c5de5c7fd44930ed94b32fac230e59bac1e4ca123aca3297e4b9d25024bf13237db9721fec1a";
        paymentParamForPassing.hashes.offerHash =  "1e99fdb59bd91c1a85624104c0fcfae34d7fcb850dd17a0b75e7efe49857d15fdefc47dd0d86ca34cbc3a8b580839aea6341a573e4e60dc1ddcf7ecc32bf9cae";
  }
}

我正在使用的另一个代码(来自链接 2)是:

    import UIKit

class ViewController: UIViewController {

    @IBAction func onTapBtnPay(_ sender: UIButton) {
        continueWithCardPayment()
    }


    let paymentParam: PayUModelPaymentParams  = PayUModelPaymentParams()
    var hashes :PayUModelHashes  = PayUModelHashes()
//    let PUSAhelper:PUSAHelperClass = PUSAHelperClass()

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func continueWithCardPayment()  {

        paymentParam.key = "smsplus"
        paymentParam.transactionID = "umangtxn123"
        paymentParam.amount = "100.0"
        paymentParam.productInfo = "Nokia"
        paymentParam.surl = "https://www.payumoney.com/mobileapp/payumoney/success.php"
        paymentParam.furl = "https://www.payumoney.com/mobileapp/payumoney/failure.php"
        paymentParam.firstName = "Umang"
        paymentParam.email = "umangarya336@gmail.com"
        paymentParam.environment = ENVIRONMENT_MOBILETEST
        paymentParam.udf1 = "udf1"
        paymentParam.udf2 = "udf2"
        paymentParam.udf3 = "udf3"
        paymentParam.udf4 = "udf4"
        paymentParam.udf5 = "udf5"
        paymentParam.offerKey = ""
        // Set this property if you want to give offer:
        paymentParam.userCredentials = ""

        PUSAHelperClass.generateHash(fromServer: self.paymentParam) { (hashes, errorString) in
            self.hashes = hashes ?? PayUModelHashes()
            self.paymentParam.hashes = hashes
            self.callPaymentGateway()
        }
    }

    func callPaymentGateway()  {

        let webServiceResponse :PayUWebServiceResponse = PayUWebServiceResponse()

        webServiceResponse.getPayUPaymentRelatedDetail(forMobileSDK: paymentParam) { (paymentDetail, errString, extraParam) in

            if errString == nil {

                let storyboard = UIStoryboard(name: "Main", bundle: nil)
                let payOptionVC = storyboard.instantiateViewController(withIdentifier: "PUUIPaymentOptionVC") as! PUUIPaymentOptionVC

                payOptionVC.paymentParam = self.paymentParam
                payOptionVC.paymentRelatedDetail = paymentDetail

                DispatchQueue.main.async {
                    NotificationCenter.default.addObserver(self, selector: #selector(self.paymentResponseReceived(notify:)), name: NSNotification.Name(rawValue: kPUUINotiPaymentResponse), object: nil)
                    self.navigationController?.pushViewController(payOptionVC, animated: true)
                }
                              }
            }
            else{
                print("Failed to proceed for payment : \(errString)")
            }
        }
    }

    @objc func paymentResponseReceived(notify:NSNotification) {
        print(notify)
    }

}

最佳答案

我已经解决了这个问题。

您可以在 PayU Integration in iOS using swift 上使用博客链接。

请检查博客并尝试提到的步骤。

关于ios - Payu Swift 集成中 PayUCreateRequest 的 createRequest() 函数中的 NSURL 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52667148/

相关文章:

ios - UITableView 中最后一个单元格丢失

php - 在测试模式下集成 PayUMoney 支付网关时出现“抱歉出现错误”

ios - UIImageView 缩放以填充不剪辑 subview

ios - 如何使用传输实用程序从 S3 下载大量文件?

android - TransformClassesWithJarMergingForRelease Android

node.js - 使用 Node 请求 OAuth 凭据

php - 付款后PayUMoney支付网关错误

ios - 我如何判断某个手势识别器附加到哪个 View ?

ios - 在 Swift 中将 Int 更改为 CGFloat 以返回 heightForRowAtIndexPath tableview 函数