Add credit card by using braintree.js

Js

Posted on 18 Dec 15 by Vickey
  705



For create credit card in braintree fir we need to verify credit card details.If card verified successfull we get nonce from braintree for this we can use braintree.js

https://js.braintreegateway.com/v2/braintree.js
var client = new braintree.api.Client({clientToken: "your client tocken"});
      var credit_card_number = 411111111111111
      var credit_card_exp_month = 01
      var credit_card_exp_year = 2020
      var credit_card_card_name = 'Jhon'
      var zip = 12345
      client.tokenizeCard({

        number: credit_card_number ,
        cardholderName: credit_card_card_name ,
        expirationMonth: credit_card_exp_month ,
        expirationYear: credit_card_exp_year ,
        
        billingAddress: {

          postalCode: zip

        }

      }, function (err, nonce) {

            //here we get nonce 
      });

This nonce we can pass to braintree php api with customer id and it will add new credit crad with customer

      try {
      $result = Braintree_PaymentMethod::create([
        'customerId' => customer_id,
        'paymentMethodNonce' => $nonce,
        'options' => [
          'verifyCard' => true          
        ]
      ]);
      } 
      catch (Exception $e) {
      return $this->_returnJson(false, $e->getMessage());
      }

 


If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com