需要设置商家ID

When trying to execute my code I always get the error:

Uncaught exception 'Braintree\Exception\Configuration' with message 'Braintree\Configuration::merchantId needs to be set (or accessToken needs to be passed to Braintree\Gateway)

The error occurs at:

Braintree\Transaction::sale(Array) #4 {main} thrown in /braintree_folder/lib/Braintree/Configuration.php on line 260

My PHP Code is:

<?php
    require 'lib/Braintree.php';

    $gateway = new Braintree_Gateway([
                                         'environment' => 'sandbox',
                                         'merchantId' => '*********',
                                         'publicKey' => '********',
                                         'privateKey' => '*********'
                                         ]);

    $paymentMethodNonce =  $_POST['payment_method_nonce'];
    $amount = $_POST['amount'];


    $result = Braintree_Transaction::sale([
                                          'amount' => $amount,
                                          'paymentMethodNonce' => $paymentMethodNonce,
                                          'options' => [
                                          'submitForSettlement' => True
                                          ]
                                          ]);

    echo json_encode($result);

    ?>

Could you tell me what I have to change?

Because you are using the instance method to create the gateway credentials.

Try changing this (which is a class method):

$result = Braintree_Transaction::sale([ 'amount' => $amount,'paymentMethodNonce' => $paymentMethodNonce, 'options' => ['submitForSettlement' => True]]);

to this (which is an instance method):

$result = $gateway->transacation()->sale([ 'amount' => $amount,'paymentMethodNonce' => $paymentMethodNonce, 'options' => ['submitForSettlement' => True]]);

According to Braintree's documentation, you can't mix class methods with instance methods. You have to use one or the other. They are encouraging the instance method.

See this link it will give you more details: https://developers.braintreepayments.com/start/hello-server/php