Braintree - paymentMethodNonceReceived 未被调用

Braintree - paymentMethodNonceReceived not being invoked

我已经为 braintree 安装了 dropin UI。我可以看到 UI 很好。在此之前,我创建了客户,我可以在 braintree-sandbox 上看到客户。现在我想为客户添加付款方式。我正在尝试使用以下代码,但未调用 paymentMethodNonceReceived。不知道为什么。

braintree.setup("<?=CLIENT_TOKEN_FROM_PHP?>", 
    "dropin", 
    {
      container: "divBrainTreeContainer",
      paymentMethodNonceReceived: function (event, nonce) {
        console.log(nonce);
        $('#formProfile').append('<input type="hidden" name="payment_method_nonce" value="'+nonce+'" />');
        $('#formProfile').submit();
      }
    }
);

根据@kdetella 的评论,<form> 元素中应该有一个 submit 按钮来接收付款方式随机数。

我正在使用 JavaScript 并且它 工作正常:

  braintree.setup(clientToken, "custom", {
    id: "my-sample-form",
    hostedFields: {
      number: {
        selector: "#card-number"
      },
      cvv: {
        selector: "#cvv"
      },
      expirationMonth: {
        selector: "#expiration-month"
      },
      expirationYear: {
        selector: "#expiration-year"
      },
    },onPaymentMethodReceived:function(nonce){
        console.log(JSON.stringify(nonce));
        return false;

  }
    }

          ); 

上面给出了以下回复并且没有提交表格:

{"nonce":"ff2662e1-f1fd-42a3-a16f-d8f3213a2406","details":{"lastTwo":"11","cardType":"Visa"},"type":"CreditCard"}

表示使用 onPaymentMethodReceived 而不是 paymentMethodNonceReceived

谢谢 http://www.web-technology-experts-notes.in/2015/06/braintree-payment-gateway-integration.html

https://github.com/braintree/braintree-web/issues/58

对于与多种支付方式的自定义集成,请使用 onSuccess 而不是 onPaymentMethodReceived。

braintree.setup(TOKEN, 'custom', {
  id: 'checkout',
  paypal: {
    container: 'paypal-container',
    onSuccess: function (nonce, email) {
      // This will be called as soon as the user completes the PayPal flow
      // nonce:String
      // email: String
    }
  },
  onPaymentMethodReceived: function(obj) {
    // This will be called when the user submits the form
  }
});