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:
- Displaying the button
- 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
Param | Type | Description |
---|---|---|
options | Object | |
[options.country] | String | Your ISO 3166 country code (ex: 'US'). This is your country code as the merchant. Required if options.paymentRequest.countryCode is not provided. |
[options.currency] | String | ISO 4217 purchase currency (ex: 'USD'). Required if options.paymentRequest.currencyCode is not provided. |
[options.label] | String | Purchase description to display in the Apple Pay payment sheet. Defaults to "Total". |
[options.total] | String | Total 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] | Boolean | Display the options.total and options.label as a monthly recurring line item in the Apple Pay payment sheet. |
[options.pricing] | CheckoutPricing | If 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] | HTMLElement | If 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] | Boolean | Requires 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] | Object | Callbacks to handle the user selection events in the session. |
[options.paymentRequest] | Object | The ApplePayPaymentRequest object. While all fields in the ApplePayPaymentRequest are supported, listed in this table are the overrides for the top level options. |
[options.braintree] | Object | Optional. Braintree configuration. |
[options.braintree.clientAuthorization] | String | If using Braintree to process Apple Pay transactions, provide your client authorization code here. |
[options.braintree.displayName] | String | If using Braintree to process Apple Pay transactions, the name for the store, displayed on the transactions. |
ApplePay options.callbacks
Arguments
options.callbacks
ArgumentsParam | Type | Description |
---|---|---|
[options.callbacks.onPaymentMethodSelected] | Function | Called 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] | Function | Called 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] | Function | Called 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] | Function | Called 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] | Function | Called 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
options.paymentRequest
ArgumentsParam | Type | Description |
---|---|---|
[options.paymentRequest.countryCode] | String | The ISO 3166 country code. Overrides options.country . |
[options.paymentRequest.currencyCode] | String | The ISO 4217 currency code. Overrides options.currency . |
[options.paymentRequest.total] | Object | The ApplePayLineItem . Overrides the options.total and options.label options for the total line item on the payment sheet. |
[options.paymentRequest.supportedNetworks] | Array | The list of Apple Pay supported networks to be available based on your gateway settings. |
[options.paymentRequest.recurringPaymentRequest] | Object | The 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] | Array | The 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
Param | Type | Description |
---|---|---|
callback | Function | Called 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
paymentAuthorized
This event is fired when the customer has authorized the payment presented on the Apple Pay payment sheet.
Payload
Param | Type | Description |
---|---|---|
event | Object | The ApplePayPaymentAuthorizedEvent object. |
event.payment.recurlyToken.id | String | Token identifier to be sent to the API. |
token
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
Param | Type | Description |
---|---|---|
token | Object | |
token.id | String | Token identifier to be sent to the API |
event | Object | The ApplePayPaymentAuthorizedEvent object. |
error
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
Param | Type | Description |
---|---|---|
error | RecurlyError | An error describing the issue that occurred. |
Updated 12 days ago