Braintree Payment with Payment Method Nonce failing




I’m trying to pay for an order using Braintree with a pre-generated Payment Method Nonce using the PHP SDK. I followed the docs here:

Here is the code I’m using for the payment:

$payment_params = [
  'payment' => $post_data->paymentNonce,
  'options' => ['payment_method_nonce' => TRUE],
$payment = $order->pay('braintree', 'purchase', $payment_params);

When the code is run, I get the following error:

Client error: `POST` resulted in a `400 Bad Request` response:
{"errors":[{"title":"Payment gateway error","detail":"The request to the payment gateway failed"}]}

Can you please look into it and let me know how to fix it?


Hi @thr.admin

Could you try passing payment_method_token instead of payment_method_nonce in your options array?



Hi @James,

I got the same error when using payment_method_token.


Any updates on this please? I have been focusing on other parts of the website for now, but it would be good if I could make this work.


Hi @thr.admin

I’ve just tested this out locally and Braintree does differentiate between a nonce and a token so you were correct initially.

This request works for me (using a test nonce):

$payment = $order->pay('braintree', 'purchase', [
    'payment' => 'fake-valid-nonce',
    'options' => [
        'payment_method_nonce' => true

If that doesn’t work for you then there could be an issue with the configuration of the gateway. Are you able to see the failed transaction in Braintree?



There were no failed transactions in Braintree; I switched back to using payment_method_nonce and verified my gateway configuration. It turns out that in the Environment field, I had typed in Sandbox instead of sandbox (big ‘s’ instead of small).

Fixed that, and it’s now working; can’t believe it was something that simple!

Thank you for your help @James!


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.