Apple Pay works on Safari browsers and the following versions of iOS devices:
- macOS 10.14.1 and later.
- iOS 12.1 and later.
DocsCurrentLast updated: March 15th 2023, @ 4:50:11 pm
Important: PayPal’s Apple Pay integration is only available in the US.
Apple Pay is a mobile payment and digital wallet service provided by Apple Inc.
Buyers can use Apple Pay to make payments on the web using the Safari web browser or an iOS device.
Sellers can use Apple Pay to sell:
Visit this site for more information about Apple Pay.
Apple Pay checkout example
Countries | Payment type | Payment flow | Currencies | Minimum amount | Refunds |
---|---|---|---|---|---|
United States US | push | direct | USD | 1 USD | Within 180 days |
The payment sheet helps streamline the checkout process by showing the customer the information needed to make the payment.
Payment sheets can show the user’s name, address, shipping information, and email address. You can customize this payment sheet to include the user details and payment information you need for your Apple Pay integration.
Visit this site for more details about Apple Pay’s compatibility.
Screenshot of a payment sheet on a mobile device
Watch our video tutorial for this integration:
Apple Pay works on Safari browsers and the following versions of iOS devices:
Currently supports Apple Pay one-time payments with the payer present.
Review Apple’s terms and conditions for the Apple Pay platform.
Get up and running in GitHub Codespaces
GitHub Codespaces are cloud-based development environments where you can code and test your PayPal integrations. Learn more
Before you can accept Apple Pay on your website, verify that your sandbox business account supports Apple Pay. Use the PayPal Developer Dashboard to set up your sandbox account to accept Apple Pay.
If you created a sandbox business account through sandbox.paypal.com, and the Apple Pay status for the account shows as disabled, complete the sandbox onboarding steps to enable Apple Pay.
Note: When your integration is ready to go live, read the Go live section for details about the additional steps needed for Apple Pay onboarding.
Before you develop your Apple Pay on the Web integration, you need to complete Get started to set up your PayPal account, client ID, and sandbox emails for testing.
Important: You need to verify any domain names that you want to show an Apple Pay button. Apple rejects payments from unverified domains. The Apple Pay payment method won’t work if the domain isn’t registered.
Create an Apple Pay sandbox account on the Apple Developer website to get a test wallet and test cards to test your Apple Pay integration.
If you already have an Apple sandbox account, you can use that account and move on to the next step.
Follow this integration process to add Apple Pay as a checkout option, customize the payment experience, and process payments.
Note: You can find a complete example in the GitHub repo.
To accept Apple Pay directly on your website, create API endpoints on your server that communicate with the PayPal Orders V2 API. These endpoints can create an order, authorize payment, and capture payment for an order.
The following example uses the PayPal Orders V2 API to add routes to an Express server for creating orders and capturing payments.
1import * as PayPal from "./paypal-api.js";23app.post("/api/orders", async (req, res) => {4 const order = await PayPal.createOrder();5 res.json(order);6});78app.post("/api/orders/:orderID/capture", async (req, res) => {9 const {10 orderID11 } = req.params;12 const captureData = await PayPal.capturePayment(orderID);13 res.json(captureData);14});
You need to Integrate with the Apple Pay JavaScript SDK and PayPal JavaScript SDK to add Apple Pay to your site.
Use this script to integrate with the PayPal JavaScript SDK:
1<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID¤cy=USD&buyer-country=US&merchant-id=SUB_MERCHANT_ID&components=applepay"></script>
Include applepay
in the components
list.
Use this script to integrate with the Apple JavaScript SDK:
1<script src="https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js"></script>
PayPal’s Apple Pay component interacts with your JavaScript code in 4 areas:
paypal.Applepay().config()
.onvalidatemerchant
callback: paypal.Applepay().validateMerchant()
.onpaymentauthorized
callback: paypal.Applepay().confirmOrder()
.Before you show the Apple Pay button, make sure that you can create an Apple Pay instance and that the device can make an Apple Pay payment.
Use ApplePaySession.canMakePayments
to check if the device can make Apple Pay payments.
Tip: When testing, you need to be logged into the iCloud account for your testing environment. Testing in the sandbox requires you to log into an iTunes Connect sandbox tester account, which you can create with an Apple Developer account. When you test in a live environment, log into a live iCloud account.
Check for device and merchant eligibility before setting up the Apple Pay button.
To check eligibility, use the PayPal JavaScript SDK API paypal.Applepay().config()
.
1<div id="applepay-container"></div>
1if (!window.ApplePaySession) {2 console.error('This device does not support Apple Pay');3}4if (!ApplePaySession.canMakePayments()) {5 console.error('This device is not capable of making Apple Pay payments');6}7const applepay = paypal.Applepay();8applepay.config()9.then(applepayConfig => {10 if (applepayConfig.isEligible) {11 document.getElementById("applepay-container").innerHTML = '<apple-pay-button id="btn-appl" buttonstyle="black" type="buy" locale="en">';12 }13})14.catch(applepayConfigError => {15 console.error('Error while fetching Apple Pay configuration.');16});
You can find more details on how to set up the Apple Pay button in Apple’s developer documentation.
The ApplePaySession
object manages the Apple Pay payment process on the web. Create a new ApplePaySession
each time a payer explicitly requests a payment, such as inside anonclick
event. If you don’t create anApplePaySession
each time, you get a "Must create a newApplePaySession
from a user gesture handler" JavaScript exception. For more information about this error, visit Apple's Creating an Apple Pay Session page.
For each ApplePaySession
, create anApplePayPaymentRequest
object, which includes information about payment processing capabilities, the payment amount, and shipping information.
The response object of the PayPal JavaScript SDK API paypal.Applepay().config()
provides the following parameters in the ApplePayPaymentRequest
object:
countryCode
merchantCapabilities
supportedNetworks
1const paymentRequest = {2 countryCode: applepayConfig.countryCode,3 merchantCapabilities: applepayConfig.merchantCapabilities,4 supportedNetworks: applepayConfig.supportedNetworks,5 currencyCode: "USD",6 requiredShippingContactFields: ["name", "phone", "email", "postalAddress"],7 requiredBillingContactFields: ["postalAddress"],8 total: {9 label: "Demo",10 type: "final",11 amount: "100.00",12 }13};14const session = new ApplePaySession(4, paymentRequest);
Include the new ApplePaySession
inside a gesture handler, such as an onclick
event or an addEventListener
click handler.
Creating an ApplePaySession
object throws a JavaScript exception if any of the following occurs:
https
.Use paypal.Applepay().validateMerchant()
in the onvalidatemerchant
callback to create a validated Apple Pay session object:
1session.onvalidatemerchant = (event) => {2 applepay.validateMerchant({3 validationUrl: event.validationURL,4 displayName: "My Store"5 })6 .then(validateResult => {7 session.completeMerchantValidation(validateResult.merchantSession);8 })9 .catch(validateError => {10 console.error(validateError);11 session.abort();12 });13};
Safari calls the onpaymentauthorized
callback with an event
object. The event
object passes a token
which you need to send to PayPal to confirm the order.
Capture the order using the PayPal Orders V2 API. Use paypal.Applepay().confirmOrder()
to send the orderID
, the Apple Pay token, billing contact details, and confirm the order.
1session.onpaymentauthorized = (event) => {2 console.log('Your billing address is:', event.payment.billingContact);3 console.log('Your shipping address is:', event.payment.shippingContact);4 fetch("/api/orders", {5 method: 'post' ,6 body : {}7 })8 .then(res => res.json())9 .then((createOrderData) => {10 var orderId = createOrderData.id;11 applepay.confirmOrder({12 orderId: orderId,13 token: event.payment.token,14 billingContact: event.payment.billingContact15 })16 .then(confirmResult => {17 session.completePayment(ApplePaySession.STATUS_SUCCESS);18 fetch(`/api/orders/${orderId}/capture`, {19 method: "post",20 })21 .then(res => res.json())22 .then(captureResult => {23 console.log(captureResult);24 })25 .catch(captureError => console.error(captureError));26 })27 .catch(confirmError => {28 if (confirmError) {29 console.error('Error confirming order with applepay token');30 console.error(confirmError);31 session.completePayment(ApplePaySession.STATUS_FAILURE);32 }33 });34 });35 };
After you have created the Apple Pay session and added the callbacks, call the session.begin
method to show the payment sheet. You can only call the begin
method when a payer explicitly requests a payment, such as inside an onclick
event. The begin
method throws a JavaScript exception if the buyer does not explicitly request the action:
1session.begin();
After the payer starts a payment in the browser, they use their Apple device to authorize the payment.
Customize payment using the Apple Pay JavaScript SDK.
Per Apple's development guidelines, your Apple Pay integration needs to follow these rules:
The commonly used customizations for Apple Pay are:
Customization | Apple Pay SDK Details |
---|---|
A set of line items that explain the subtotal, tax, discount, and additional charges for the payment. | lineItems |
The billing information fields that the payer must provide to fulfill the order. | requiredBillingContactFields |
The shipping information fields that the payer must provide to fulfill the order. | requiredShippingContactFields |
The payer’s billing contact information. | billingContact |
The payer’s shipping contact information. | requiredShippingContactFields Call the onshippingcontactselected event handler when the user selects a shipping contact in the payment sheet. |
The shipping method for a payment request. | ApplePayShippingMethod Call the onshippingmethodselected event handler when the user selects a shipping method in the payment sheet. |
Ensure your integration with Apple Pay is configured properly for sandbox and production environments.
Use your personal sandbox login information during checkout to complete a payment using Apple Pay. Then, log into the sandbox site sandbox.paypal.com to see that the money has moved into your account.
Make Apple Pay available to buyers using your website or app.
Note: Before going live, complete production onboarding to process Apple Pay payments with your live PayPal account.
If you’re a new merchant, sign up for a PayPal business account.
Use your personal production login information during checkout to complete an Apple Pay transaction. Then log into paypal.com to see the money move out of your account.
Verify any domain names in your live environment that will show an Apple Pay button. Apple Pay transactions only work on a domain and site registered to you.
Important: The Apple Pay payment method won't work if the domain and site aren't registered. The merchant that owns the domain is responsible for registering that domain.
Prerequisites
Enable Apple Pay for your live account:
Create an app:
Download and host live domain association file
Host a domain association file for each high-level domain and subdomain that show the Apple Pay button.
/.well-known/apple-developer-merchantid-domain-association
. For example:https://example.com/.well-known/apple-developer-merchantid-domain-association
https://subdomain.example.com/.well-known/apple-developer-merchantid-domain-association
Note: Remove the file extension from the domain association file when you host it on your server.
Register your live domain on PayPal
Add all high-level domains that show the Apple Pay button.
After your domain is registered:
When testing a purchase in production, consider:
How to test Apple Pay payments in a live environment:
Make sure that there are no browser console warnings or errors. The JavaScript SDK configuration attributes have distinct validation checks for input formatting and values.
If the validation fails, the web browser’s developer console shows warning messages that say which property is incorrect and what you need to do to address the issue. The library generally attempts to revert to the safe default values if missing or incorrect inputs exist.
Get started testing, add security to your checkout experience or create customizations for your audience.
Add PayPal payment buttons and customized card fields.