Reputation: 81
Hello I try to set up a braintree payement on my website but I have an error when i create my Transaction sale : Unknown paymentMethodNonce. I generate a client token like an example from Braintree support (They sand me a mail with an example) :
<?php
require_once("../lib/Braintree.php");
$clientToken = Braintree_ClientToken::generate(); ?>
...
<script>
var clientToken = "<?php echo $clientToken; ?>";
braintree.setup(clientToken, "dropin", {
container: "payment-form"
});
</script>
And on my checkout page :
require_once("../lib/Braintree.php");
$nonce = $_POST["payment_method_nonce"];
$result = Braintree_Transaction::sale([
'amount' => "100",
'paymentMethodNonce' => $nonce,
'options' => [
'submitForSettlement' => True
]
]);
I try to remove configuration line, it's work but the account merchant is not mine and if I set up the account in sale with :
'merchantAccountId' => 'MyAccount',
or to configure before :
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('xxx');
Braintree_Configuration::publicKey('xxx');
Braintree_Configuration::privateKey('xxxxx');
But I have an error : Exception need to be catch .
Thanks for your help
Upvotes: 1
Views: 1391
Reputation: 319
Full disclosure: I work for Braintree.
The error you are getting suggests the payment_method_nonce
is not reaching your server. Make sure you have a form like this in your client:
<form id="checkout" method="post" action="/checkout">
<div id="payment-form"></div>
<input type="submit" value="Pay $10">
</form>
You need to configure your application with the Braintree_Configuration::environment
, merchantId
, publicKey
, and privateKey
. You would only pass in merchantAccountId
with a Braintree_Transaction::sale
if you want to use a merchant account that is not your default account.
If you are still having trouble, please continue working with Braintree support.
Upvotes: 1