tokenizeCard 的回调函数在 Braintree 上没有被调用

Callback function of tokenizeCard it's not called on Braintree

我一直在将 Braintree 与我的应用程序集成,但我发现了一个问题。我需要使用 tokenizeCard 方法,但它似乎没有调用回调,我不明白为什么。

function buyNow() {
    var token = getSessionVarFromView('client_token_braintree');
    console.error(token);
    braintree.setup(token, "custom", {id: "braintreePaymentForm"});
    var client = new braintree.api.Client({clientToken: token});
    client.tokenizeCard({number: "4111111111111111", expirationDate: "10/20"}, function (err, nonce) {
       console.error("On tokenize card");
    });
}

我的表格是这个:

      <form method="POST" name="braintreePaymentForm" id="braintreePaymentForm">
                <div class='form-row'>
                  <div class='col-xs-8 form-group required'>
                    <label class='control-label'>Card number</label>
                    <input class='form-control' size="20" autocomplete="off" data-braintree-name="number">
                  </div>
                  <div class='col-xs-4 form-group required'>
                    <label class='control-label'>Security Code</label>
                    <input class='form-control' size="20" autocomplete="off" data-braintree-name="cvv">
                  </div>
                </div>
                <div class='form-row'>
                  <div class='col-xs-6 form-group required'>
                    <label class='control-label'>Name on card</label>
                    <input class='form-control' size="20" autocomplete="off" data-braintree-name="name_on_card">
                  </div>
                  <div class='col-xs-3 form-group required'>
                    <label class='control-label'>Expires on</label>
                    <input class='form-control' size="20" autocomplete="off" data-braintree-name="expiration_month">
                  </div>
                  <div class='col-xs-3 form-group required'>
                    <input class='form-control' size="20" autocomplete="off" data-braintree-name="expiration_year">
                  </div>
                </div>
                  <div id="buyNowBtn">
                </div>
            </form>

buyNow 方法在用户按下购买后调用。在服务器中生成我的客户端令牌的方法是:

Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('merchantId');
Braintree_Configuration::publicKey('publicKey');
Braintree_Configuration::privateKey('privateKey');  

$clientToken = Braintree_ClientToken::generate();
return $clientToken;

此后,tokenizeCard 的回调函数再也不会被调用。

希望有人能帮助我。

谢谢

我在布伦特里工作。如果您还有其他问题,可以随时 get in touch with our support team.

表单提交按钮必须是 <button><input type="submit"> 才能正确触发回调。您正在使用 <div>.