PayPal

Use Recurly to process PayPal transactions using a PayPal Complete, Braintree, or PayPal Business gateway.

PayPal manages the consumer payment authorization flow directly. Your customers will authorize a transaction within PayPal. Recurly will then record the authorization and return a token for you to use with our APIs, as we
do for other payment methods.

PayPal Complete

A PayPal Complete integration utilizes the PayPal JavaScript SDK. Using Recurly.js, you'll place a PayPal button on your page.

First, we'll need a target on your page to which the PayPal button will be added:

<div id="paypal-button"></div>

Next, create a new recurly.PayPal instance and provide the target. We also recommend setting up an error handling listener.

const paypal = recurly.PayPal({
  payPalComplete: {
    target: '#paypal-button',

    // You may optionally provide buttonOptions
    //
    // See the PayPal JavaScript SDK documentation for all possible values that may be provided to
    // paypal.Buttons()
    buttonoptions: {}
  }
});

paypal.on('error', (err) => {
  // err.code
  // err.message
  // [err.cause] if there is an embedded error
});

Finally, add a listener to receive the token once your customer completes the checkout flow. At this point you will
send the token id to your server to be used in the Recurly API to create a billing info for an account.

paypal.on('token', function (token) {
  // token.id
});

PayPal on Braintree

First, place a button on your page specifically for checking out with PayPal.

<button>Checkout with PayPal</button>

Next, create a new recurly.PayPal instance and provide a Braintree client authorization.

const paypal = recurly.PayPal({
  braintree: { clientAuthorization: MY_CLIENT_AUTHORIZATION }
});

paypal.on('error', (err) => {
  // err.code
  // err.message
  // [err.cause] if there is an embedded error
});

Next we must bind a listener to a user action on the button and have it trigger the start function on your
recurly.PayPal instance. This will open the PayPal Express Checkout flow.

document.querySelector('#paypal-button').addEventListener('click', function () {
  paypal.start();
});

Finally, add a function to receive the token once your customer completes the checkout flow. At this point you will
send the token id to your server to be used in the Recurly API to create a billing info for an account.

paypal.on('token', function (token) {
  // token.id
  // token.email
  // token.payer_id
});

PayPal Business

If you are using PayPal Business, please see the documentation for Recurly.js v4.35.0. Recurly will maintain
backward compatibility with this integration through its major version.

Reference

fn recurly.PayPal

Arguments, PayPal complete
ParamTypeDescription
optionsObject
options.payPalCompleteObjectPayPal Complete configuration.
options.payPalComplete.targetStringA query selector referencing an HTMLElement on your page in which to place the PayPal Button.
options.payPalComplete.buttonOptionsObjectOptional. A pass-through set of options to provide to paypal.Buttons. See the PayPal JavaScript SDK reference .
Arguments, PayPal on Braintree
ParamTypeDescription
optionsObject
options.braintreeObjectBraintree configuration.
options.braintree.clientAuthorizationStringYour Braintree client authorization code.
Returns

A new PayPal instance

fn payPal.start

Initiates the PayPal customer flow for PayPal on Braintree.

Arguments
ParamTypeDescription
optionsObjectOptional.
options.descriptionStringOptional. In legacy PayPal flows, this description will be displayed during the checkout flow.
Returns

Nothing.

events Emits

error

This event is emitted when any error is encountered, whether during setup of the PayPal flow, or during the checkout process. It will be useful to display errors to your customer if a problem occurs during PayPal checkout.

Payload
ParamTypeDescription
errorRecurlyErrorAn error describing the issue that occurred.
cancel

This event is emitted when the customer has canceled the PayPal checkout flow before completion. You may wish to reset parts of your checkout experience if this occurs.

Payload

None.

token

This event is emitted when the customer has completed the PayPal checkout flow. Recurly has received the payment details, and generated this token to be used in our API.

Payload
ParamTypeDescription
tokenObject
token.typeString'paypal'
token.idStringToken identifier to be sent to the API
token.emailStringThe email of the customer.
token.payer_idStringThe unique identifier of the customer PayPal account. Braintree only.