Checkout Sessions
A Checkout Session represents a customer's payment session. It is a foundational object for creating one-time payments and subscriptions. When a customer initiates a payment process, you create a Checkout Session to define the line items, payment mode, and other configurations. The SDK then provides a URL to redirect the customer to a secure, hosted payment page.
The Checkout Session Object#
A Checkout Session object contains all the details for a single payment flow, including line items, payment status, customer details, and success/cancel URLs.
Properties#
Property | Type | Description |
---|---|---|
|
| Unique identifier for the Checkout Session. |
|
| The status of the session. Can be |
|
| The payment status of the session. Can be |
|
| The mode of the Checkout Session, determined by the line items. Can be |
|
| The URL to the hosted checkout page for this session. Redirect your customer to this URL to complete the payment. |
|
| A list of items the customer is purchasing. |
|
| The total amount for the session in the smallest currency unit (e.g., cents). |
|
| The ID of the currency for the payment. |
|
| The ID of the Customer for this session. |
|
| A set of key-value pairs that you can attach to an object. |
|
| The URL to which the customer will be redirected after a successful payment. |
|
| The URL to which the customer will be redirected if they cancel the payment. |
Create a Session#
Creates a Checkout Session object.
const session = await payment.checkoutSessions.create({
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
line_items: [
{
price_id: 'price_12345',
quantity: 1,
},
],
});
Parameters#
Parameter | Type | Description |
---|---|---|
|
| Required. A list of line item objects. See the Line Item Object Properties table below. |
|
| Required. The URL to redirect to after a successful payment. |
|
| Required. The URL to redirect to if the customer cancels the session. |
|
| Enables promo code redemption. Default is |
|
| Specifies whether to collect the customer's billing address. Can be |
|
| A unique string to reference the Checkout Session. |
|
| The currency for the session. If not provided, it's inferred from the first line item's price. |
|
| Determines when to create a Customer object. Can be |
|
| Groups multiple subscriptions into a single checkout flow. Default is |
|
| The Unix timestamp at which the Checkout Session will expire. Default is 30 minutes from creation. |
|
| If |
|
| Key-value data to attach to the session. |
|
| The text on the submit button. Can be |
|
| Data to be used when creating a subscription. See the Subscription Data Object Properties table below. |
Line Item Object Properties
Property | Type | Description |
---|---|---|
|
| Required. The ID of the Price object. |
|
| Required. The quantity of the line item. |
|
| Allows the customer to adjust the quantity on the checkout page. Contains |
|
| A custom amount for the line item, used for prices with |
Subscription Data Object Properties
Property | Type | Description |
---|---|---|
|
| Number of trial days for a new subscription. |
|
| Unix timestamp indicating the end of the trial period. |
|
| A threshold for the billing amount that triggers an invoice. |
|
| The minimum stake amount required for the subscription. |
|
| If |
|
| An optional description for the subscription. |
|
| An array of service action objects to display to the customer. Each object can define |
Returns#
Returns a Checkout Session object if the call succeeded.
{
"id": "cs_123456789",
"status": "open",
"payment_status": "unpaid",
"mode": "payment",
"url": "https://checkout.example.com/pay/cs_123456789",
"success_url": "https://example.com/success",
"cancel_url": "https://example.com/cancel",
"line_items": [
{
"price_id": "price_12345",
"quantity": 1
}
],
"amount_total": "1000",
"currency_id": "usd",
"customer_id": null,
"metadata": {},
"created_at": 1678886400,
"expires_at": 1678888200
}
Retrieve a Session#
Retrieves a Checkout Session object by its ID.
const sessionId = 'cs_123456789';
const session = await payment.checkoutSessions.retrieve(sessionId);
Parameters#
Parameter | Type | Description |
---|---|---|
|
| Required. The unique identifier of the Checkout Session to retrieve. |
Returns#
Returns the Checkout Session object, including expanded details for line_items
.
{
"id": "cs_123456789",
"status": "complete",
"payment_status": "paid",
"mode": "payment",
"line_items": [
{
"price_id": "price_12345",
"quantity": 1,
"price": {
"id": "price_12345",
"active": true,
"unit_amount": "1000",
"currency_id": "usd",
"type": "one_time"
}
}
],
"amount_total": "1000",
"currency_id": "usd",
"customer_id": "cus_abcdefg",
"payment_intent_id": "pi_hijklmn"
}
Update a Session#
Updates a Checkout Session object. Currently, only the metadata
can be updated.
const sessionId = 'cs_123456789';
const updatedSession = await payment.checkoutSessions.update(sessionId, {
metadata: {
order_id: '6735'
}
});
Parameters#
Parameter | Type | Description |
---|---|---|
|
| Required. The ID of the Checkout Session to update. |
|
| Required. A set of key-value pairs to store on the object. |
Returns#
Returns the updated Checkout Session object.
{
"id": "cs_123456789",
"status": "open",
"metadata": {
"order_id": "6735"
}
}
List all Sessions#
Returns a paginated list of Checkout Sessions.
const sessions = await payment.checkoutSessions.list({
pageSize: 5,
payment_status: 'paid'
});
Parameters#
Parameter | Type | Description |
---|---|---|
|
| Filter sessions by status ( |
|
| Filter sessions by payment status ( |
|
| Filter sessions by NFT mint status ( |
|
| Filter sessions for a specific customer ID. |
|
| Filter sessions for a specific customer DID. |
|
| Filter sessions associated with a specific Payment Intent. |
|
| Filter sessions created from a specific Payment Link. |
|
| Filter sessions associated with a specific Subscription. |
|
| Filter by custom metadata fields. |
|
| The page number for pagination. Default is |
|
| The number of items per page. Default is |
Returns#
Returns an object containing a list of Checkout Session objects and pagination details.
{
"count": 15,
"list": [
{
"id": "cs_123456789",
"status": "complete",
"payment_status": "paid"
},
{
"id": "cs_987654321",
"status": "complete",
"payment_status": "paid"
}
]
}
Expire a Session#
Expires an open Checkout Session. Once expired, it can no longer be used to complete a payment.
const sessionId = 'cs_123456789';
const expiredSession = await payment.checkoutSessions.expire(sessionId);
Parameters#
Parameter | Type | Description |
---|---|---|
|
| Required. The ID of the Checkout Session to expire. |
Returns#
Returns the expired Checkout Session object with its status changed to expired
.
{
"id": "cs_123456789",
"status": "expired",
"payment_status": "unpaid"
}