Braintree Payment with Payment Method Nonce failing

php
braintree
payments

#1

Hi,

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: https://docs.moltin.com/?javascript#braintree-payments

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 https://api.moltin.com/v2/orders/4ef4d016-5e4f-4445-b6ad-391fbf8c862c/payments` 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?


#2

Hi @thr.admin

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

Thanks,
James


#3

Hi @James,

I got the same error when using payment_method_token.


#4

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.


#5

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?

Thanks,
James


#6

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!


#7

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