braintree-web/paypal

A component to integrate with PayPal.

Deprecated:

Source:

Members

(static) VERSION :string

The current version of the SDK, i.e. 3.46.0.

Source:

Methods

(static) create(options, callback) → {Promise|void}

Parameters:
Name Type Description
options object

Creation options:

Properties
Name Type Attributes Description
client Client <optional>

A Client instance.

authorization string <optional>

A tokenizationKey or clientToken. Can be used in place of options.client.

callback callback

The second argument, data, is the PayPal instance.

Source:
Example
// We recomend creating your PayPal button with button.js
// For an example, see http://codepen.io/braintree/pen/LNKJWa
var paypalButton = document.querySelector('.paypal-button');

braintree.client.create({
  authorization: CLIENT_AUTHORIZATION
}, function (clientErr, clientInstance) {
  if (clientErr) {
    console.error('Error creating client:', clientErr);
    return;
  }

  braintree.paypal.create({
    client: clientInstance
  }, function (paypalErr, paypalInstance) {
    if (paypalErr) {
      console.error('Error creating PayPal:', paypalErr);
      return;
    }

    paypalButton.removeAttribute('disabled');

    // When the button is clicked, attempt to tokenize.
    paypalButton.addEventListener('click', function (event) {
      // Because tokenization opens a popup, this has to be called as a result of
      // customer action, like clicking a button. You cannot call this at any time.
      paypalInstance.tokenize({
        flow: 'vault'
        // For more tokenization options, see the full PayPal tokenization documentation
        // http://braintree.github.io/braintree-web/current/PayPal.html#tokenize
      }, function (tokenizeErr, payload) {
        if (tokenizeErr) {
          if (tokenizeErr.type !== 'CUSTOMER') {
            console.error('Error tokenizing:', tokenizeErr);
          }
          return;
        }

        // Tokenization succeeded
        paypalButton.setAttribute('disabled', true);
        console.log('Got a nonce! You should submit this to your server.');
        console.log(payload.nonce);
      });
    }, false);
  });
});

(static) isSupported() → {Boolean}

Returns true if PayPal supports this browser.

Source:
Example
if (braintree.paypal.isSupported()) {
  // Add PayPal button to the page
} else {
  // Hide PayPal payment option
}