Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Braintree - paymentMethodNonceReceived not being invoked

I have setup dropin UI for braintree. I can see the UI fine. Before that I created the customer and I can see the customer on braintree-sandbox. Now I want to add payment method to the customer. I am trying following code, but paymentMethodNonceReceived is not being invoked. Not sure why.

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();
      }
    }
);
like image 683
Haris ur Rehman Avatar asked Jan 21 '15 13:01

Haris ur Rehman


People also ask

How do Braintree's servers generate payment method nonces?

Braintree's servers generate payment method nonces in response to requests from our client and server SDKs. In general, your client will be responsible for receiving payment method nonces from Braintree and sending them to your server.

What is Braintree payment error 81709?

Braintree Payment Error Error 81709: Expiration date is required. Error 81714: Credit card number is required. Error 81725: Credit card must include number, paymentMethodNonce, or venmoSdkPaymentMethodCode.

What is a payment method nonce?

It's the key element that allows your server to communicate sensitive payment information to Braintree without ever touching the raw data. Any type of payment method can be referenced by a payment method nonce.


2 Answers

I am using below JavaScript and its working fine:

  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;

  }
    }

          ); 

Above gives below response and DOES NOT submit the form:

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

means use onPaymentMethodReceived instead of paymentMethodNonceReceived

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

like image 128
Poonam Gupta Avatar answered Oct 14 '22 13:10

Poonam Gupta


As per @kdetella's comment, there should be a submit button inside the <form> element to receive payment method nonce.

like image 44
Haris ur Rehman Avatar answered Oct 14 '22 12:10

Haris ur Rehman