Framework

Apple Pay JS

Use JavaScript to incorporate Apple Pay into your websites.

Overview

The Apple Pay JavaScript API lets you accept Apple Pay payments on the web. The Apple Pay Javascript API is supported on the following platforms:

  • iOS 10. Apple Pay JavaScript is supported on all iOS devices with a Secure Element. It is supported both in Safari and in SFSafariViewController objects.

  • macOS 10.12. Apple Pay JavaScript is supported in Safari. The user must have an iPhone or Apple Watch that can authorize the payment.

The Apple Pay Javascript API is analogous to the PassKit API for using Apple Pay in apps. If you have used that API, then the Apple Pay JavaScript API should feel familiar to you.

Apple Pay Requirements

There are three requirements for using Apple Pay on your website:

  • You must have an Apple Developer Account.

  • All pages that incorporate Apple Pay must be served over HTTPS.

  • Your website must comply with the Apple Pay guidelines. For more information, see Apple Pay on the Web Acceptable Use Guidelines.

Server Requirements

To incorporate Apple Pay on your website, your server must have the following setup:

  • All pages that include Apple Pay must be served over HTTPS.

  • Your server must support the Transport Layer Security (TLS) 1.2 protocol and one of the cipher suites listed in Table I-1.

  • To enable merchant validation, your server must allow access over HTTPS (TCP over port 443) to the Apple Pay IP addresses provided in List 1 below.

List 1

Apple Pay IP addresses for merchant validation

17.171.78.7      
17.171.78.71     
17.171.78.135   
17.171.78.199   
17.171.79.12       
17.141.128.7       
17.141.128.71     
17.141.128.135    
17.141.128.199    
17.141.129.12 
17.171.78.9       
17.171.78.73      
17.171.78.137    
17.171.78.201    
17.171.79.13   
17.141.128.9     
17.141.128.73   
17.141.128.137  
17.141.128.201  
17.141.129.13         

Configuring Your Environment

Similar to Apple Pay in apps, you must register a merchant identifier and set up cryptographic keys. However, iOS uses digitally signed entitlements in the app binary to add an additional layer of security. These entitlements help validate and verify both the user and the merchant.

To provide a similar layer of security on the web, there are a few additional steps, both to configure your environment and to validate payment requests.

To accept Apple Pay on the web, you need the following three pieces of information:

  • Merchant ID. A unique identifier that represents a merchant for Apple Pay.

    The same merchant ID can be used for Apple Pay payments both in-app and on the web. For information on creating your merchant ID, see Configuring Your Environment in Apple Pay Programming Guide.

  • Payment Processing Certificate. A certificate used to securely transfer payment data. Apple Pay servers use the payment processing certificate’s public key to encrypt the payment data. Use the private key to decrypt the data when processing payments.

    The same payment processing certificate can be used for Apple Pay payments both in-app and on the web. For information on creating your Payment Processing Certificate, see Configuring Your Environment in Apple Pay Programming Guide.

  • Merchant Identity Certificate. A Transport Layer Security (TLS) certificate used to authenticate your merchant sessions with the Apple Pay servers.

To register and verify your domain, and create your Merchant Identity Certificate:

  1. In Member Center, select Certificates, Identifiers, and Profiles.

  2. Under Identifiers, select Merchant IDs.

  3. Select the merchant ID from the list, and click Edit.

  4. In the Apple Pay on the Web section, click the Add Domain button.

  5. Enter your fully qualified domain name, and click Continue.

  6. The site creates a file and makes it available to download. Download this file and host it at the provided location.

    Your server must support the TLS 1.2 protocol and one of the cipher suites listed in Table I-1.

    Table I-1

    Supported cipher suites

    Ciphersuite Value

    Description

    0xC02F

    TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256

    0xC027

    TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256

    0xC013

    TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA

    0x009E

    TLS_DHE_RSA_WITH_AES_128_GCM_SHA256

    0x0067

    TLS_DHE_RSA_WITH_AES_128_CBC_SHA256

    0x009C

    TLS_RSA_WITH_AES_128_GCM_SHA256

    0x003C

    TLS_RSA_WITH_AES_128_CBC_SHA256

  7. As soon as the file is available on your server, click the Verify button. If the verification succeeds, the site returns to the iOS Merchant ID Settings page and shows a green Verified status label.

  8. In the Apple Pay on the Web section, click the Create Certificate button. Follow the instructions to create and download your Merchant Identity Certificate. Use this certificate when requesting a merchant session during payment validation. For more information, see Merchant Validation in ApplePaySession.

Symbols

Creating an Apple Pay Session

ApplePaySession

Use the ApplePaySession class to manage the payment process on the web. The session object is the entry point for Apple Pay on the web.

Working with Events

ApplePayPaymentAuthorizedEvent

The ApplePayPaymentAuthorizedEvent class defines the attributes contained by the onpaymentauthorized callback function.

ApplePayPaymentMethodSelectedEvent

The ApplePayPaymentMethodSelectedEvent class defines the attributes contained by the onpaymentmethodselected callback function.

ApplePayShippingContactSelectedEvent

The ApplePayShippingContactSelectedEvent class defines the attributes contained by the onshippingcontactselected callback function.

ApplePayShippingMethodSelectedEvent

The ApplePayShippingMethodSelectedEvent class defines the attribute contained by the onshippingmethodselected callback function.

ApplePayValidateMerchantEvent

The ApplePayValidateMerchantEvent class defines the attributes contained by the onvalidatemerchant callback function.

Data Types

ApplePay JS Data Types

Lists the dictionaries used in Apple Pay JS that are not described elsewhere.