如何设置payment_method_nonce

时间:2019-03-30 23:57:10

标签: php braintree

我是Braintree的新手,我很难确定如何设置payment_method_nonce,以便我可以提交交易。

尝试将其与PHP结合起来作为后端。

直接填写表格

<form action="charge.php" method="post" id="payment-form" >
    <input id="nonce" name="payment_method_nonce" type="hidden" />
    <div id="dropin-container"></div>
    <button id="submit-button">Submit</button>
</form>

dropin js:

var button = document.querySelector('#submit-button');

        braintree.dropin.create({
        authorization: 'MyClientToken',
          container: '#dropin-container'
        }, function (createErr, instance) {
          button.addEventListener('click', function () {
            instance.requestPaymentMethod(function (requestPaymentMethodErr, payload) {

            });
          });
        });

php:

require_once('vendor/autoload.php'); 

    $POST = filter_var_array($_POST, FILTER_SANITIZE_STRING);
    $nonceFromTheClient = $POST['payment_method_nonce'];

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

    $clientToken = $gateway->clientToken()->generate();

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

0 个答案:

没有答案