Payumoney IOS sdk测试显示付款失败“密钥无效”

时间:2018-04-06 09:47:12

标签: ios swift payumoney

我遵循了本指南。 https://www.payumoney.com/dev-guide/mobilecheckout/ios.html

Key,Merchant id,salt来自仪表板。它们是测试凭据。 有人能告诉我我做错了什么,并指导我解决这个问题吗?

completionHandler中的结果是:

nil
Optional(Error Domain=com.payumoney.ErrorDomain Code=7025 "key is not valid" UserInfo={NSLocalizedDescription=key is not valid})
nil

我的代码:

class PaymentTestViewController: UIViewController {

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

    func configureTxnParams() -> PUMTxnParam {
        let txnParam = PUMTxnParam()
        txnParam.hashValue = generateHash()
        txnParam.key = "placeholder"
        txnParam.merchantid = "placeholder"
        txnParam.txnID = "123"
        txnParam.surl = "https://www.payumoney.com/mobileapp/payumoney/success.php"
        txnParam.furl = "https://www.payumoney.com/mobileapp/payumoney/failure.php"
        txnParam.amount = "100"
        txnParam.productInfo = "test_product"
        txnParam.firstname = "placeholder"
        txnParam.email = "placeholder@something.com"
        txnParam.phone = "8888888888"
        txnParam.environment = .test;
        txnParam.udf1 = "qq"
        txnParam.udf2 = "qq"
        txnParam.udf3 = "qq"
        txnParam.udf4 = "qq"
        txnParam.udf5 = "qq"
        return txnParam
    }

    func generateHash() -> String {
        if let data = PUMUtils.createSHA512("oU4kI4EA", txnid: "123", amount: "100", productinfo: "test_product", firstname: "dibakar", email: "dibakar@something.com", salt: "6TlD3pBbV1"),
            let urlContent = NSString(data: data, encoding: String.Encoding.ascii.rawValue) {
            return urlContent as String
        } else { return "" }
    }

    @IBAction func startPayment(_ sender: Any) {
        PlugNPlay.presentPaymentViewController(withTxnParams: configureTxnParams(), on: self) { (paymentResponse, error, extraParam) in
            print(paymentResponse)
            print(error)
            print(extraParam)
        }
    }

}

enter image description here

1 个答案:

答案 0 :(得分:0)

从您的代码中,我觉得您在生成哈希时没有包含udf变量。这可能是您的问题的原因,或者您必须复制粘贴凭证错误。无论哪种方式,这是一个适用于生产模式的解决方案。试着这样做:

let txnParam = PUMTxnParam()

txnParam.phone = "Enter your phone number"
txnParam.email = "Enter your email"
txnParam.amount = "Enter your amount"
txnParam.environment = PUMEnvironment.production
txnParam.firstname = "Enter your first name"
txnParam.key = "Enter the merchant key which was sent to your mail."
txnParam.merchantid = "Enter the merchant ID which was sent to your mail."
txnParam.txnID = "Enter random text here"
txnParam.surl = "Enter your success url"
txnParam.furl = "Enter your failure url"
txnParam.productInfo = "Enter product info"
txnParam.udf1 = "udf1"
txnParam.udf2 = "udf2"
txnParam.udf3 = "udf3"
txnParam.udf4 = "udf4"
txnParam.udf5 = "udf5"
txnParam.udf6 = "udf6"
txnParam.udf7 = "udf7"
txnParam.udf8 = "udf8"
txnParam.udf9 = "udf9"
txnParam.udf10 = "udf10"
txnParam.hashValue = generateHash(txnParam, salt: "Enter merchant salt sent to your mail.")

func generateHash(_ txnParam: PUMTxnParam, salt: String) -> String {
    let hashSequence = "\(txnParam.key!)|\(txnParam.txnID!)|\(txnParam.amount!)|\(txnParam.productInfo!)|\(txnParam.firstname!)|\(txnParam.email!)|\(txnParam.udf1!)|\(txnParam.udf2!)|\(txnParam.udf3!)|\(txnParam.udf4!)|\(txnParam.udf5!)|\(txnParam.udf6!)|\(txnParam.udf7!)|\(txnParam.udf8!)|\(txnParam.udf9!)|\(txnParam.udf10!)|\(salt)"

    let hash = createSHA512(hashSequence).replacingOccurrences(of: "<", with: "").replacingOccurrences(of: ">", with: "").replacingOccurrences(of: " ", with: "")

    return hash
}

func createSHA512(_ string: String) -> String{
    var digest = [UInt8](repeating: 0, count: Int(CC_SHA512_DIGEST_LENGTH))
    if let data = string.data(using: String.Encoding.utf8) {
        let value =  data as NSData
        CC_SHA512(value.bytes, CC_LONG(data.count), &digest)

    }
    var digestHex = ""
    for index in 0..<Int(CC_SHA512_DIGEST_LENGTH) {
        digestHex += String(format: "%02x", digest[index])
    }

    return digestHex.replacingOccurrences(of: "<", with: "").replacingOccurrences(of: ">", with: "").replacingOccurrences(of: " ", with: "")
}

即使上述代码对您不起作用,PayUMoney方也一定有问题。如果问题仍然存在,请尝试与支持团队讨论。