<!--
{
  "documentType" : "article",
  "framework" : "ApplePayontheWeb",
  "identifier" : "/documentation/ApplePayontheWeb/creating-an-apple-pay-session",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Creating an Apple Pay Session"
}
-->

# Creating an Apple Pay Session

Provide a payment request and create the session.

## Discussion

After you’ve checked that the Apple Pay JS API is available and is enabled on the current device, you’re ready to create the payment request and start the session.  You can create a session only when a user explicitly asks to make a payment.  For example, you can create the session when the user taps the Apple Pay button.

You supply two parameters to [`ApplePaySession`](/documentation/ApplePayontheWeb/ApplePaySession/ApplePaySession):

- Version number. The Apple Pay version you’re using.  (See [Apple Pay on the Web version history](/documentation/ApplePayontheWeb/apple-pay-on-the-web-version-history) for version information.)
- Payment Request. An [`ApplePayPaymentRequest`](/documentation/ApplePayontheWeb/ApplePayPaymentRequest) dictionary that contains all the information needed to display the payment sheet.

Creating an [`ApplePaySession`](/documentation/ApplePayontheWeb/ApplePaySession) object throws a JavaScript exception if any of the following occur:

- Any Apple Pay JS API is called from an insecure page.
- You pass an invalid payment request. Payment requests are invalid if they contain missing, unknown, or invalid properties, or if they have a total that is zero or less.
- You attempt to create the [`ApplePaySession`](/documentation/ApplePayontheWeb/ApplePaySession) outside of a user gesture handler.  The exception error  “Must create a new ApplePaySession from a user gesture handler” appears.

After the session is created, call its [`begin`](/documentation/ApplePayontheWeb/ApplePaySession/begin) method to show the payment sheet.

Listing 1 shows creating a payment request and a new Apple Pay session, and displaying the payment sheet.

Listing 1. Example of constructing an Apple Pay session

```javascript
var request = {
  countryCode: 'US',
  currencyCode: 'USD',
  supportedNetworks: ['visa', 'masterCard', 'amex', 'discover'],
  merchantCapabilities: ['supports3DS'],
  total: { label: 'Your Merchant Name', amount: '10.00' },
}
var session = new ApplePaySession(3, request);
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)