braintree-web/paypal-checkout

Members

(static) VERSION :string

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

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
braintree.paypalCheckout.create({
  client: clientInstance
}, function (createErr, paypalCheckoutInstance) {
  if (createErr) {
    if (createErr.code === 'PAYPAL_BROWSER_NOT_SUPPORTED') {
      console.error('This browser is not supported.');
    } else {
      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
      }).catch(function (err) {
        // handle error
      });
    },

    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`
});