I'm currently testing Braintree API with sandbox. When I post nonce to server I get the messages from Braintree API: Amount is required. Cannot determine payment method. I found out that I can use hard coded value for nonce: paymentMethodNonce: "fake-valid-nonce" and in this case I can see the transaction in sandbox. But I would like to see the credit card that I entered in drop-in UI. What might be the cause of "Cannot determine payment method" message? My server-side node.js code is the following:
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);
}
});
My client side code in 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()
}
nonceFromTheClient
being nil or invalid, so it may be helpful to see the full end-to-end – C Joseph$
that can be causing the values to become malformed? Have you tried printing out the nonce/amount on client to see what they look like? – C Joseph