Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Braintree API:无法确定沙箱交易的付款方式_Braintree - Fatal编程技术网

Braintree API:无法确定沙箱交易的付款方式

Braintree API:无法确定沙箱交易的付款方式,braintree,Braintree,我目前正在用沙盒测试BraintreeAPI。当我将nonce发布到服务器时,我从Braintree API获取消息:Amount是必需的。无法确定付款方式。 我发现我可以对nonce:paymentMethodNonce使用硬编码值:“假有效nonce”,在本例中,我可以在沙箱中看到事务。但是我想看看我在下拉界面中输入的信用卡。“无法确定付款方式”消息的原因可能是什么? 我的服务器端node.js代码如下: var amount = req.body.amount; // Use th

我目前正在用沙盒测试BraintreeAPI。当我将nonce发布到服务器时,我从Braintree API获取消息:Amount是必需的。无法确定付款方式。 我发现我可以对nonce:paymentMethodNonce使用硬编码值:“假有效nonce”,在本例中,我可以在沙箱中看到事务。但是我想看看我在下拉界面中输入的信用卡。“无法确定付款方式”消息的原因可能是什么? 我的服务器端node.js代码如下:

  var amount = req.body.amount;
  // Use the payment method nonce here
  var nonceFromTheClient = req.body.paymentMethodNonce;

  var newTransaction = gateway.transaction.sale({
                      amount: amount,                      
                      //paymentMethodNonce: "fake-valid-nonce",

                      paymentMethodNonce: nonceFromTheClient,
                      options: {                          
                      submitForSettlement: true }
                      }, function(error, result) {
                      if (result) {
                          res.send(result);
                      } else {                               
                          res.status(500).send(error);
                      }
                   });  
我的Swift客户端代码:

func sendRequestPaymentToServer(nonce: String, amount: String) {

    let paymentURL = URL(string: "http://localhost:5000/checkout")!
    var request = URLRequest(url: paymentURL)
    request.httpBody = "paymentMethodNonce=\(nonce)&amount=\(amount)".data(using: String.Encoding.utf8)
    request.httpMethod = "POST"

    URLSession.shared.dataTask(with: request) { (data, response, error) -> Void in
        guard let data = data else {
            print(error!.localizedDescription)
            return
        }
        if let result = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
            if result?["success"] as? Bool == true {
                print("Successfully charged. Thanks So Much :)")
            }
            else if let message = result?["message"] {
                print(message)
            }
            //dump(result)
        } else {
            print("No json result.")
        }
        }.resume()
}

问题出在我的主体解析器中-它没有正确配置。通过以下代码行解决了该问题:

.use(bodyParser.urlencoded({extended: true}))

在user@CJoseph确认代码对她有效后。

您还可以包含客户端代码吗?该错误很可能是由于
nonefromtheclient
为零或无效导致的,因此查看完整的结束代码可能会有所帮助-end@CJoseph我添加了客户端代码,是的,似乎我发送的请求参数有点不正确,因为API除了nonce之外,还无法识别我发送的金额。我尝试了您的代码,但没有出现问题,您是否可能发送了类似于
$
的金额,这可能会导致值格式错误?您是否尝试在客户机上打印当前值/金额以查看它们的外观?