Create a checkout session
Checkout sessions allow your consumer to initiate a purchase on your web app. The checkout session token you receive is what allows you to utilize the capabilities of the Checkout API, such as Drop-in UI and Hosted Payments Page (HPP).
How it works
- The consumer initiates a checkout with your server via their browser.
- Your server then sends an authentication request via the Checkout API.
- If authentication is successful, an accessToken (bearer token) is sent in response to your server.
- Your server then creates a checkout session by sending a POST request to the /checkout/intent endpoint, using the accessToken, the merchant ID, an order reference, and a cart object.
- The Checkout API sends the checkoutSessionToken as a response to your server, which is then sent to the consumer’s browser.
- The webpage loads the checkout feature you chose (Drop-in UI or HPP) and initializes it with the checkoutSessionToken.
The following settings can help you better utilize the Checkout API for your business needs.
Setting | Scenario description |
---|---|
Set |
Use this to get the tokens for the cards or bank accounts without going through Zero Dollar Authorization (ZDA). |
Set |
Use this to authorize and manually capture a payment via the Payments API. Learn more about how to authorize and capture a payment. |
Set |
Use this to authorize and automatically capture a payment. |
Set isSaveConsumerProfile = true |
Use this to store consumer details so they don’t have to re-enter the information next time. When set to true, Payments API makes a call to consumer profile to either create a new profile or retrieve an existing profile at the time of making the payment. |
The following is a sample request to create a checkout session and provide the checkoutSessionToken.
Method: POST
Endpoint: /checkout/intent
const config = {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer ${accessToken}",
"requestId": "merchantOrderReference",
"merchantId": "merchantId"
},
body: JSON.stringify(sessionRequestPayload)
};
const response = await fetch(ENDPOINT,config);
The following is a sessionRequestPayload sample request to express the intent to authorize and capture $55.00 USD:
{
"currencyCode": "USD",
"merchantOrderNumber": "X1G5VZMxplIm1tRRcrC85o",
"checkoutOptions": {
"authorization": {
"authorizationType": "AUTH_METHOD_CART_AMOUNT"
},
"capture": {
"captureMethod": "CAPTURE_METHOD_NOW"
}
},
"cart": {
"totalTransactionAmount": 1000
}
}
Response:
{
"checkoutSessionToken": "exampleCh3ck0utT0k3n"
}
Your backend server returns the checkoutSessionToken
back to your web app, where it will be used to render the Checkout form using the JavaScript library.