JSPM

braintree-web

3.0.0-beta.6
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 356635
  • Score
    100M100P100Q171136F
  • License MIT

A suite of tools for integrating Braintree in the browser

Package Exports

  • braintree-web
  • braintree-web/client
  • braintree-web/data-collector
  • braintree-web/hosted-fields
  • braintree-web/paypal

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (braintree-web) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

braintree-web

NOTE: v3 of our JavaScript SDK is currently in closed beta. If you are interested in using this new major version and not already part of the closed beta, join our Google Group for updates on the public beta (coming soon).

A suite of tools for integrating Braintree in the browser.

This is the repo to submit issues if you have any problems or questions about any v.zero JavaScript integration.

Install

npm install braintree-web@3.0.0-beta.6
bower install braintree-web@3.0.0-beta.6

Usage

For more thorough documentation, visit the JavaScript client SDK docs.

####Hosted Fields integration

<form action="/" id="my-sample-form">
  <input type="hidden" name="payment_method_nonce">
  <label for="card-number">Card Number</label>
  <div id="card-number"></div>

  <label for="cvv">CVV</label>
  <div id="cvv"></div>

  <label for="expiration-date">Expiration Date</label>
  <div id="expiration-date"></div>

  <input id="my-submit" type="submit" value="Pay" disabled/>
</form>
var submitBtn = document.getElementById('my-submit');
var form = document.getElementById('my-sample-form');

braintree.client.create({
  authorization: 'YOUR_CLIENT_TOKEN'
}, clientDidCreate);

function clientDidCreate(err, client) {
  braintree.hostedFields.create({
    client: client,
    styles: {
      'input': {
        'font-size': '16pt',
        'color': '#3A3A3A'
      },

      '.number': {
        'font-family': 'monospace'
      },

      '.valid': {
        'color': 'green'
      }
    },
    fields: {
      number: {
        selector: '#card-number'
      },
      cvv: {
        selector: '#cvv'
      },
      expirationDate: {
        selector: '#expiration-date'
      }
    }
  }, hostedFieldsDidCreate);
});

function hostedFieldsDidCreate(err, hostedFields) {
  submitBtn.addEventListener('click', submitHandler.bind(null, hostedFields));
  submitBtn.removeAttribute('disabled');
}

function submitHandler(hostedFields, event) {
  event.preventDefault();
  submitBtn.setAttribute('disabled', 'disabled');

  hostedFields.tokenize(function (err, payload) {
    if (err) {
      submitBtn.removeAttribute('disabled');
      console.error(err);
    } else {
      form['payment_method_nonce'].value = payload.nonce;
      form.submit();
    }
  });
}

Advanced integration

braintree.client.create({
  authorization: 'YOUR_CLIENT_TOKEN'
}, function (err, client) {
  client.request({
    endpoint: 'payment_methods/credit_cards',
    method: 'post',
    data: {
      creditCard: {
        number: '4111111111111111',
        expirationDate: '10/20'
      }
    }
  }, function (err, response) {
    // Send response.creditCards[0].nonce to your server
  });
});