braintree-web/paypal-checkout

A component to integrate with the PayPal Checkout.js library.

Source:

Members

(static) VERSION :string

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

Source:

Methods

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

Parameters:
Name Type Attributes Description
options object

Creation options:

Properties
Name Type Description
client Client

A Client instance.

callback callback <optional>

The second argument, data, is the PayPalCheckout instance.

Source:
Example
// Be sure to have checkout.js loaded on your page.
// You can use the paypal-checkout package on npm
// with a build tool or use a script hosted by PayPal:
// <script src="https://www.paypalobjects.com/api/checkout.js" data-version-4 log-level="warn"></script>

braintree.paypalCheckout.create({
  client: clientInstance
}, function (createErr, paypalCheckoutInstance) {
  if (createErr) {
    console.error('Error!', createErr);
    return;
  }

  paypal.Button.render({
    env: 'production', // or 'sandbox'

    locale: 'en_US',

    payment: function () {
      return paypalCheckoutInstance.createPayment({
        flow: 'vault'
      });
    },

    onAuthorize: function (data, actions) {
      return paypalCheckoutInstance.tokenizePayment(data).then(function (payload) {
        // Submit payload.nonce to your server
      });
    },

    onCancel: function (data) {
      console.log('checkout.js payment cancelled', JSON.stringify(data, 0, 2));
    },

    onError: function (err) {
      console.error('checkout.js error', err);
    }
  }, '#paypal-button'); // the PayPal button will be rendered in an html element with the id `paypal-button`
});

(static) isSupported() → {Boolean}

Returns true if PayPal Checkout supports this browser.

Deprecated:
  • Previously, this method checked for Popup support in the brower. Checkout.js now falls back to a modal if popups are not supported.

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