代码之家  ›  专栏  ›  技术社区  ›  H.Epstein

无法将nonce发送到Braintree

  •  0
  • H.Epstein  · 技术社区  · 8 年前

    我正在尝试与大脑树沙盒集成,

    我正在尝试将nonce从ios客户端发送到服务器,但在控制台中出现以下错误: TypeError: Cannot read property 'payment_method_nonce' of undefined

    我的服务器端代码是:

    app.post("/checkout", function (req, res) {
    var nonceFromTheClient = req.body.payment_method_nonce;
    gateway.transaction.sale({
    amount: "10.00",
    paymentMethodNonce: nonceFromTheClient,
    options: {
      submitForSettlement: true
    }
    }, function (err, result) {
    if (err) {
      print(err)
    }
    else if (result.success) {
      console.log(result);
    }
    });});
    

    在Ios端:

        func createTransaction(paymentMethodNonce:String) {
        let paymentURL = postUrl!
        var request = URLRequest(url: paymentURL)
        request.httpBody = "payment_method_nonce=\(paymentMethodNonce)".data(using: String.Encoding.utf8)
        request.httpMethod = "POST"
    
        URLSession.shared.dataTask(with: request) { (data, response, error) -> Void in
            if let err = error {
                print(err.localizedDescription)
                return}
            else {
                print(response)}
            }.resume()
    }
    
    1 回复  |  直到 8 年前
        1
  •  2
  •   Harish    8 年前

    TypeError: Cannot read property 'payment_method_nonce' of undefined

    这意味着您的需求。正文为空/未分析。是否导入了正文分析器?此模块将解析正文并将其提供给您。