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

时间:2017-12-21 15:40:01

标签: braintree

我目前正在使用沙箱测试Braintree API。当我将nonce发布到服务器时,我从Braintree API获取消息:需要金额。无法确定付款方式。 我发现我可以使用nonce的硬编码值:paymentMethodNonce:" fake-valid-nonce"在这种情况下,我可以在沙箱中看到该事务。但我希望看到我在drop-in UI中输入的信用卡。可能是什么原因"无法确定付款方式"信息? 我的服务器端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()
}

1 个答案:

答案 0 :(得分:1)

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

internal interface IEnumIDList {
  [PreserveSig]
  [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
  HResult Next(uint celt, in IntPtr rgelt, out uint pceltFetched);
}

用户@CJoseph确认代码在她身边有效。