Apple Pay

Enable and run Apple Pay checkout flows in Recurly.js—including button display, payment-sheet handling, and optional Braintree support.

Use Recurly.js to process Apple Pay transactions. Recurly.js supports Apple Pay out of the box. To get started, ensure your site is configured to accept Apple Pay transactions.

Setting up your Apple Pay integration in Recurly.js involves two parts:

  1. Displaying the button
  2. Invoking the purchase flow

Prerequisites and limitations

  • Site configuration – Apple Pay must already be enabled and verified in your Recurly admin settings. Follow the Apple Pay on the Web setup guide before adding client-side code.
  • Browser / device support – Customers must use Safari (macOS 10.14.4+, iOS 12.2+) or another Apple Pay–capable browser/device.
  • Token lifetime – Tokens returned from the Apple Pay flow follow standard Recurly.js rules: reusable for up to 20 minutes, then permanently expire.
  • Braintree processing – If you route Apple Pay through Braintree you must supply a valid client authorization string when instantiating recurly.ApplePay.

Key details

Displaying The Button

Your button styling needs to adhere to Apple’s specifications.

See Apple's documentation on Displaying the Apple Pay Button for guidelines on display and styling the button.

Invoking The Purchase Flow

Configure a new instance of recurly.ApplePay as follows.

// Handle when the token has been generated to keep the payment sheet in the "Processing"
// state until the onPaymentAuthorized callback has completed
function onPaymentAuthorized({ payment }) {
  const { recurlyToken: token, billingContact, shippingContact } = payment;
  // Submit the token to your server
  console.log('Apple Pay succeeded.',
              'Token:', token.id,
              'billingContact:', billingContact,
              'shippingContact', shippingContact);
}

const applePay = recurly.ApplePay({
  country: 'US',
  currency: 'USD',
  label: 'My Subscription', // This text will be displayed on the Apple Pay payment sheet as "My Subscription"
  total: '29.00',
  callbacks: {
    onPaymentAuthorized,
  }
});

// When the ApplePay instance is ready, bind the Apple Pay button click
// to applePay.begin
applePay.ready(function () {
  $('#my-apple-pay-button').on('click', function () {
    applePay.begin();
  });
});

// Handle errors. These may occur at any point in the Apple Pay flow
applePay.on('error', function (err) {
  // err.code, err.message
  console.error('Apple Pay error', err);
});

ApplePay via Braintree

If you're processing Apple Pay transactions with Braintree, you'll pass a client authorization during instantiation:

const applePay = recurly.ApplePay({
  country: 'US',
  currency: 'USD',
  label: 'My Subscription', // This text will be displayed on the Apple Pay payment sheet as "My Subscription"
  total: '29.00',
  callbacks: {
    onPaymentAuthorized,
  }
  braintree: {
    clientAuthorization: MY_CLIENT_AUTHORIZATION
  }
});

Additional configuration

If you are using the recurly.Pricing.Checkout class to calculate checkout prices, you may pass
your pricing instance instead of providing a total.

const pricing = recurly.Pricing.Checkout();

const applePay = recurly.ApplePay({
  // ...
  pricing: pricing
});

To provide additional customer data to tokens generated by recurly.ApplePay, you may pass a form
reference. recurly.ApplePay will collect customer data from the form just as would occur during credit card tokenization. See Getting a Token for more information on building such a form.

const applePay = recurly.ApplePay({
  // ...
  form: document.querySelector('#my-payment-form')
});

Integration Notes

  • Recurly.js will automatically pull in the billing info from the customer's Apple account if their Apple Pay setup is complete with full billing information in their Apple Wallet. If the user does NOT have a billing name or address attached to their card in their Apple Wallet, the Apple Pay flow will prompt the customer for a billing address.
  • If you choose to include a Recurly.js payment form, any billing name or address fields entered on that form will replace the billing address in the user's Apple Wallet on the payment sheet. The user can always change their billing address once the payment sheet has loaded.
  • Integration examples

Reference

fn - recurly.ApplePay

Arguments
ParamTypeDescription
optionsObject
[options.country]StringYour ISO 3166 country code (ex: 'US'). This is your country code as the merchant. Required if options.paymentRequest.countryCode is not provided.
[options.currency]StringISO 4217 purchase currency (ex: 'USD'). Required if options.paymentRequest.currencyCode is not provided.
[options.label]StringPurchase description to display in the Apple Pay payment sheet. Defaults to "Total".
[options.total]StringTotal cost to display in the Apple Pay payment sheet. Defaults to '0.00' if options.pricing and options.paymentRequest.total are not provided.
[options.recurring]BooleanDisplay the options.total and options.label as a monthly recurring line item in the Apple Pay payment sheet.
[options.pricing]CheckoutPricingIf provided, will override options.total and provide the current total price and line items on the CheckoutPricing instance when the Apple Pay flow is initiated.
[options.form]HTMLElementIf provided, the Apple Pay payment sheet billing address will be populated by the customer billing address from the form. See Getting a Token for all compatible fields.
[options.enforceVersion]BooleanRequires the user to have the minimum supported browser version for configured payment request features. Currently, this will force the minimum requirements of macOS 10.14.4 and iOS 12.2 if options.paymentRequest.requiredShippingContactFields is set.
[options.callbacks]ObjectCallbacks to handle the user selection events in the session.
[options.paymentRequest]ObjectThe ApplePayPaymentRequest object. While all fields in the ApplePayPaymentRequest are supported, listed in this table are the overrides for the top level options.
[options.braintree]ObjectOptional. Braintree configuration.
[options.braintree.clientAuthorization]StringIf using Braintree to process Apple Pay transactions, provide your client authorization code here.
[options.braintree.displayName]StringIf using Braintree to process Apple Pay transactions, the name for the store, displayed on the transactions.
ApplePay options.callbacks Arguments
ParamTypeDescription
[options.callbacks.onPaymentMethodSelected]FunctionCalled with the ApplePayPaymentMethodSelectedEvent that should return the ApplePayPaymentMethodUpdate object, a Promise resolving with that update or rejecting with the appropriate error array. The total attribute is added for users that do not wish to support the native newTotal API to simplify the integration.
[options.callbacks.onShippingContactSelected]FunctionCalled with the ApplePayShippingContactSelectedEvent that should return the ApplePayShippingContactUpdate object, a Promise resolving with that update or rejecting with the appropriate error array. The total attribute is added for users that do not wish to support the native newTotal API to simplify the integration.
[options.callbacks.onShippingMethodSelected]FunctionCalled with the ApplePayShippingMethodSelectedEvent that should return the ApplePayShippingMethodUpdate object, a Promise resolving with that update or rejecting with the appropriate error array. The total attribute is added for users that do not wish to support the native newTotal API to simplify the integration.
[options.callbacks.onCouponCodeChanged]FunctionCalled with the ApplePayCouponCodeChangedEvent that should return the ApplePayCouponCodeUpdate, a Promise resolving with that update or rejecting with the appropriate error array. The total attribute is added for users that do not wish to support the native newTotal API to simplify the integration.
[options.callbacks.onPaymentAuthorized]FunctionCalled with the ApplePayPaymentAuthorizedEvent that includes the payment.recurlyToken as the token accepted by Recurly for checkout. Should return undefined, a resolving Promise or a rejecting Promise with the appropriate error array.
ApplePay options.paymentRequest Arguments
ParamTypeDescription
[options.paymentRequest.countryCode]StringThe ISO 3166 country code. Overrides options.country.
[options.paymentRequest.currencyCode]StringThe ISO 4217 currency code. Overrides options.currency.
[options.paymentRequest.total]ObjectThe ApplePayLineItem. Overrides the options.total and options.label options for the total line item on the payment sheet.
[options.paymentRequest.supportedNetworks]ArrayThe list of Apple Pay supported networks to be available based on your gateway settings.
[options.paymentRequest.recurringPaymentRequest]ObjectThe ApplePayRecurringPaymentRequest. Overrides the options.total and options.label options if options.recurring is true for the recurring line item on the payment sheet.
[options.paymentRequest.requiredBillingContactFields]ArrayThe list of ApplePayContactField that must be provided in the billing contact. Will always include postalAddress by Recurly.js, regardless if overridden.
Returns

A new recurly.ApplePay instance

fn - applePay.ready

Arguments
ParamTypeDescription
callbackFunctionCalled when the ApplePay instance has completed initialization. Will immediately invoke if the instance is already initialized. The callback is called with no arguments.
Returns

Nothing.

event - Emits
paymentAuthorized

This event is fired when the customer has authorized the payment presented on the Apple Pay payment sheet.

Payload
ParamTypeDescription
eventObjectThe ApplePayPaymentAuthorizedEvent object.
event.payment.recurlyToken.idStringToken identifier to be sent to the API.
token

This event is fired when the customer has completed the Apple Pay payment sheet flow. Recurly has received the payment details, and generated this token to be used in our API.

Payload
ParamTypeDescription
tokenObject
token.idStringToken identifier to be sent to the API
eventObjectThe ApplePayPaymentAuthorizedEvent object.
error

This event is emitted when any error is encountered, whether during setup of the Apple Pay payment sheet, or during payment authorization. It will be useful to display errors to your customer if a problem occurs during the Apple Pay flow.

Payload
ParamTypeDescription
errorRecurlyErrorAn error describing the issue that occurred.