Pay with Apple Pay SDK

DocsCurrent

Last updated: Oct 25th, 9:37am

Overview

Apple Pay is a mobile payment and digital wallet service provided by Apple Inc.

Buyers can use Apple Pay on PayPal to make payments on the web using the Safari web browser or an iOS device.

Sellers can use Apple Pay on PayPal to sell:

  • physical goods, such as clothes and electronics
  • digital goods, such as software
  • intangible professional services, such as concerts or gym memberships.

Visit this site for more information about Apple Pay.

image

Supported countries and currencies

Apple Pay supports payments in 36 countries and 22 currencies:

  • Countries: Australia, Austria, Belgium, Bulgaria, Canada, China, Cyprus, Czech Republic, Denmark, Estonia, Finland, France, Germany, Greece, Hong Kong, Hungary, Ireland, Italy, Japan, Latvia, Liechtenstein, Lithuania, Luxembourg, Malta, Netherlands, Norway, Poland, Portugal, Romania, Singapore, Slovakia, Slovenia, Spain, Sweden, United States, United Kingdom
  • Currencies: AUD, BRL, CAD, CHF, CZK, DKK, EUR, GBP, HKD, HUF, ILS, JPY, MXN, NOK, NZD, PHP, PLN, SEK, SGD, THB, TWD, USD

How it works

The Apple Pay button shows up on your website when a customer uses the Safari web browser on an eligible device. When your buyer selects the Apple Pay button, they confirm purchase details and authorize the payment on a payment sheet.

Visit this site for more details about Apple Pay's compatibility.

  • A buyer taps or clicks on the Apple Pay button on your website.
  • The Safari browser or iOS device shows the payer a payment sheet.
  • The buyer can choose a different shipping address and payment method.
  • The buyer authorizes the payment

image

Integration video

Know before you code

Required

You have to be an approved partner to integrate the Apple Pay SDK

Apple Pay works on Safari browsers and the following versions of iOS devices:

  • macOS 10.14.1 and later.
  • iOS 12.1 and later.
  • Supported devices and where you can use them
Check Compatibility

Optional

Currently supports Apple Pay one-time payments with the payer present.

Review Apple's terms and conditions for the Apple Pay platform. See Apple's developer terms for more information.

1

Onboard sellers

2

Set up your sandbox account to accept Apple Pay

Before you can accept Apple Pay on your website, verify that your sandbox business account supports Apple Pay.

Partners can use the PayPal Developer Dashboard to set up their sandbox accounts to accept Apple Pay. The integration for partner accounts includes creating a sandbox business account through sandbox.paypal.com. If the Apple Pay status for the account shows as disabled, complete the sandbox onboarding steps to enable Apple Pay.

  1. Log into the PayPal Developer Dashboard and go to your sandbox account.
  2. Go to Apps & Credentials.
  3. Make sure you are in the PayPal sandbox environment by selecting Sandbox at the top.
  4. Select or create an app.
  5. Scroll down to Mobile and digital payments and check if Apple Pay is enabled. If Apple Pay isn't enabled, select the Apple Pay checkbox.

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.

3

Set up your testing environment

Before you develop your Apple Pay on the web integration, you need to set up your PayPal account, client ID, and sandbox emails for testing.

  1. Download and host the domain association file for your sandbox environment.
  2. Register your sandbox domain.
  3. Create an Apple Pay sandbox account for testing. You don't need an Apple developer account to go live.

Download and host sandbox domain association file

  1. Download the domain association file for your sandbox environment.
  2. Host the file on your test environment at /.well-known/apple-developer-merchantid-domain-association.

Download

Register your sandbox domain

  1. Request an access token by sending a POST request to https://api-m.sandbox.paypal.com/v1/oauth2/token. Note the access token from the response body.
  2. Generate a PayPal Auth Assertion header and make a note of it. Make sure to replace merchant_payer_id with the merchant ID for which you are registering the domain.
  3. Register the domain by sending a POST request to https://api-m.sandbox.paypal.com/v1/customer/wallet-domains.
    Include the following in your request:
    1. The authorization header with the value `Bearer: <your_access_token>`.
    2. The paypal-auth-assertion header with the value your_generated_auth_assertion.
    3. "provider_type": "APPLE_PAY" to indicate that this is an `APPLE_PAY` domain registration.
    4. "domain": {"name": "example.com" }, and replace "example.com" with the domain you would like to register.

    Example JSON request:

      1// Register a domain
      2{
      3 "provider_type": "APPLE_PAY",
      4 "domain": {
      5 "name": "example.com"
      6 }
      7}
    1. You will receive a 201 CREATED response with the merchant and domain registration details if this is successful.

    Deregister your sandbox domain

    1. Request an access token by sending a POST request to https://api-m.sandbox.paypal.com/v1/oauth2/token. Note the access token from the response body.
    2. Generate a PayPal Auth Assertion header and make a note of it. Make sure to replace merchant_payer_id with the merchant ID for which you are deregistering the domain.
    3. Deregister the domain by sending a POST request to https://api-m.sandbox.paypal.com/v1/customer/unregister-wallet-domain.
      Include the following in your request:
      1. The authorization header with the value `Bearer: <your_access_token>`.
      2. The paypal-auth-assertion header with the value your_generated_auth_assertion.
      3. "provider_type": "APPLE_PAY" to indicate that this is an `APPLE_PAY` domain deregistration
      4. "domain": { "name": "example.com" }, and replace "example.com" with the domain you would like to deregister.
      5. "reason": "Why you are deregistering this domain" to indicate the reason for deregistration.

      Example JSON request:

        1// Deregister a domain
        2{
        3 "provider_type": "APPLE_PAY",
        4 "domain": {
        5 "name": "example.com"
        6 },
        7 "reason": "Merchant requested to deregister domain",
        8}
      1. You will receive a 200 OK response with the merchant and domain deregistration details if this is successful.

      View list of registered sandbox domains

      1. Request an access token by sending a POST request to https://api-m.sandbox.paypal.com/v1/oauth2/token. Note the access token from the response body.
      2. Generate a PayPal Auth Assertion header and make a note of it. Make sure to replace merchant_payer_id with the merchant ID that you are registering the domain for.
      3. Register the domain by sending a GET request to https://api-m.sandbox.paypal.com/v1/customer/wallet-domains.
        1. The authorization header with the value Bearer: <your_access_token>.
        2. The paypal-auth-assertion header with the value your_generated_auth_assertion to indicate the merchant for which you are getting the domain.
      4. You will receive a 200 OK response with the registered domains under the wallet_domains field if this is successful.

      Create Apple Pay sandbox account

      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.

      1. Create an Apple developer account.
      2. Create an Apple sandbox account.
      Create Apple Pay sandbox account
      4

      Integrate Apple Pay checkout

      Follow this integration process to add Apple Pay as a checkout option, customize the payment experience, and process payments.

      Call the Orders API

      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.

      Server-side example (Node.js)

      The following example uses the PayPal Orders V2 API to add routes to an Express server for creating orders and capturing payments. Find the complete sample code in the GitHub repo.

      1. server.js
      2. paypal-api.js
      1import * as PayPal from "./paypal-api.js";
      2
      3// Create order
      4app.post("/api/orders", async (req, res) => {
      5 const order = await paypal.createOrder();
      6 res.json(order);
      7});
      8
      9// Capture payment
      10app.post("/api/orders/:orderID/capture", async (req, res) => {
      11 const {
      12 orderID
      13 } = req.params;
      14 const captureData = await paypal.capturePayment(orderID);
      15 res.json(captureData);
      16});
      5

      Set up your Apple Pay button

      You need to Integrate with the Apple Pay JavaScript SDK and PayPal JavaScript SDK to add Apple Pay to your site.

      Integrate PayPal JavaScript SDK

      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.

        Integrate Apple JavaScript SDK

        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:

          1. Checking merchant eligibility for Apple Pay: paypal.Applepay().config()
          2. Creating an Apple Pay session
          3. Handling the onvalidatemerchant callback: paypal.Applepay().validateMerchant()
          4. Handling the 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.

          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}
              4
              5
              6if (!ApplePaySession.canMakePayments()) {
              7 console.error('This device is not capable of making Apple Pay payments');
              8}
              9
              10
              11const applepay = paypal.Applepay();
              12
              13
              14applepay.config()
              15 .then(applepayConfig => {
              16 if (applepayConfig.isEligible) {
              17 document.getElementById("applepay-container").innerHTML = '<apple-pay-button id="btn-appl" buttonstyle="black" type="buy" locale="en">';
              18 }
              19 })
              20 .catch(applepayConfigError => {
              21 console.error('Error while fetching Apple Pay configuration.');
              22 });

              You can find more details on how to set up the Apple Pay button in Apple's developer documentation.

              Create Apple Pay sandbox account

              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.

              1. Create an Apple developer account.
              2. Create an Apple sandbox account.

              image

              6

              Show the payment sheet

              After you have created the Apple Pay session and added the callbacks, call the session's 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 doesn't 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

                Customize payment using the Apple Pay JavaScript SDK.

                The commonly used customizations for Apple Pay are:

                CustomizationApple 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.

                shippingContact

                Call the onshippingcontactselected event handler when the user selects a shipping contact in the payment sheet.

                The shipping method for a payment request.

                ApplePayShippingMethodCall the onshippingmethodselected event handler when the user selects a shipping method in the payment sheet.
                7

                Test your integration

                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.

                1. Open your test page with the Safari web browser on an iOS device or computer.
                2. Get a test card from your Apple sandbox account.
                3. Add the test card to your Apple Wallet on your iOS device or by using the Safari browser on the web.
                4. Tap the Apple Pay button to open a pop-up with the Apple Pay payment sheet.
                5. Make a payment using the Apple Pay payment sheet.
                6. If you have an additional confirmation page on your merchant website, continue to confirm the payment.
                7. Log in to your merchant account and continue to your confirmation page to confirm that the money you used for payment showed up in the account.
                8

                Go live

                Make Apple Pay available to buyers using your website or app.

                Live environment

                If you are a new partner setting up a marketplace or platform for individual sellers, contact us to become an approved partner. Then, see Get Started and Configure your account to sign up for a PayPal business account.

                Use your personal production login information during checkout to complete an Apple Pay transaction. Log into paypal.com to see the money move out of your account.

                Getting started in your live environment

                You need to verify any domain names in your production environment that will show an Apple Pay button. If Apple hasn't verified a domain, they will reject any payments from that domain.

                • Download and host the domain association file for your live environment.
                • Register your live domain on your PayPal Developer Dashboard.

                Download and host live domain association file

                1. Download the domain association file for your live environment.
                2. Host the file on your production site at /.well-known/apple-developer-merchantid-domain-association.

                Register your live domain

                1. Request an access token by sending a POST request to https://api.paypal.com/v1/oauth2/token. Note the access token from the response body.
                2. Generate a PayPal Auth Assertion header and make a note of it. Make sure to replace merchant_payer_id with the Merchant ID for which you are registering the domain.
                3. Register the domain by sending a POST request to https://api-m.paypal.com/v1/customer/wallet-domains.
                  Include the following in your request:
                  1. The authorization header with the value `Bearer: <your_access_token>`.
                  2. The paypal-auth-assertion header with the value your_generated_auth_assertion.
                  3. "provider_type": "APPLE_PAY" to indicate that this is an `APPLE_PAY` domain registration.
                  4. "domain": { "name": "example.com" }, and replace "example.com" with the domain you would like to register.

                  Example JSON request:

                    1// Register a domain
                    2
                    3
                    4{
                    5 "provider_type": "APPLE_PAY",
                    6 "domain": {
                    7 "name": "example.com"
                    8 }
                    9}
                  1. You will receive a 201 CREATED response with the merchant and domain registration details if this is successful.

                  Deregister your live domain

                  1. Request an access token by sending a POST request to https://api.paypal.com/v1/oauth2/token. Note the access token from the response body.
                  2. Generate a PayPal Auth Assertion header and make a note of it. Make sure to replace merchant_payer_id with the merchant ID for which you are deregistering the domain.
                  3. Deregister the domain by sending a POST request to https://api-m.paypal.com/v1/customer/unregister-wallet-domain.
                    Include the following in your request:
                    1. The authorization header with the value `Bearer: <your_access_token>`.
                    2. The paypal-auth-assertion header with the value your_generated_auth_assertion.
                    3. "provider_type": "APPLE_PAY" to indicate that this is an `APPLE_PAY` domain deregistration
                    4. "domain": { "name": "example.com" }, and replace "example.com" with the domain you would like to deregister.
                    5. "reason": "Why you are deregistering this domain" to indicate the reason for deregistration.

                    Example JSON request:

                      1// Deregister a domain
                      2{
                      3 "provider_type": "APPLE_PAY",
                      4 "domain": {
                      5 "name": "example.com"
                      6 },
                      7 "reason": "Merchant requested to deregister domain",
                      8}
                    1. You will receive a 200 OK response with the merchant and domain deregistration details if this is successful.

                    View list of registered live domains

                    1. Request an access token by sending a POST request to https://api.paypal.com/v1/oauth2/token. Note the access token from the response body.
                    2. Generate a PayPal Auth Assertion header and make a note of it. Make sure to replace merchant_payer_id with the merchant ID that you are registering the domain for.
                    3. Register the domain by sending a GET request to https://api.paypal.com/v1/customer/wallet-domains.
                      1. The authorization header with the value Bearer: <your_access_token>.
                      2. The paypal-auth-assertion header with the value your_generated_auth_assertion to indicate the merchant for which you are getting the domain.
                    4. You will receive a 200 OK response with the registered domains under the wallet_domains field if this is successful.

                    Testing your live environment

                    When testing a purchase in production, consider:

                    • The business account receiving money can't also make the purchase.
                    • If you create a personal account with the same information as the business account, those accounts might experience restrictions.

                    How to test Apple Pay payments in a live environment

                    1. Open your test page with Safari on iOS or desktop.
                    2. Select the Apple Pay button to open a pop-up with the Apple Pay payment sheet.
                    3. Proceed with the Apple Pay checkout transaction.
                    4. If you have an additional confirmation page on your merchant website, confirm the payment.
                    5. Log in to your seller account and confirm that the money has moved into that account.

                    Troubleshoot your integration

                    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.

                    Next steps and customizations

                    Get started testing, add security to your checkout experience, or create customizations for your audience.

                    Optional
                    Integrate advanced Checkout

                    Add more card payment options to your integration.

                    We use cookies to improve your experience on our site. May we use marketing cookies to show you personalized ads? Manage all cookies