What is a Checkout Session?
A checkout session is a secure, temporary link where your customers complete their payment. Each session:- Is unique and expires after a set time
- Contains all the payment information
- Redirects customers after successful/failed payment
- Can be tracked via webhooks
Prerequisites
Before creating checkout sessions, you need:- API Key - Get it from your dashboard
- Product ID - You’ll need this to create checkout sessions
API Versions
Loops offers three API versions with different levels of flexibility:Version | Parameters | Best For |
---|---|---|
V1 | paymentLinkId only | Legacy applications |
V2 | paymentLinkId OR productId | Most Loops applications (recommended) |
V3 | line_items (Stripe-style) OR productId (Loops-style) | Stripe migrations & advanced use cases |
We recommend V2 for most use cases - it’s simple, flexible, and fully featured. Use V3 if you’re migrating from Stripe or need
line_items
support.Getting Your Product ID
You have two options to get your product ID:Option 1: From Dashboard (Easiest)
- Go to your Loops Dashboard
- Navigate to Products
- Find the product you want to sell
- Click the three-dot menu (⋮) next to your product
- Click “Copy Product ID”
- Use this ID in your checkout session creation
prod_abc123xyz
or pl_1234567890
(for payment links)

Option 2: Create Product via API
You can also create products programmatically and get the ID from the response:One-time setup: You typically create products once (either in dashboard or via API), then reuse the same product ID for multiple checkout sessions.
The Flow
Here’s the typical workflow:-
Create Product (one time)
- Via dashboard OR via API
- Get the product ID
-
Create Checkout Sessions (many times)
- Use the product ID from step 1
- Create a new session for each customer/purchase
-
Customer Pays
- Redirect customer to the checkout URL
- They complete payment
-
Receive Webhook
- Get notified when payment succeeds
- Fulfill the order
Creating a Checkout Session
Now that you have your product ID, you can create checkout sessions.Basic Example
V2 accepts both parameters: Since V2 supports both workflows:
productId
(recommended) - Direct product checkout:prod_abc123xyz
paymentLinkId
(alternative) - Pre-configured payment link:pl_1234567890
productId
for clarity!Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
productId | string | Yes* | Your product ID from dashboard or API (e.g., prod_abc123xyz ) |
paymentLinkId | string | Yes* | Alternative to productId - payment link ID (e.g., pl_1234567890 ) |
externalCustomerId | string | No | Your internal customer identifier |
metadata | object | No | Custom data (max 50 key-value pairs) |
*Either
productId
or paymentLinkId
is required (not both)Response
Redirecting Your Customer
After creating a checkout session, redirect your customer to theurl
field:
Complete End-to-End Example
Here’s a full example showing the entire flow from product creation to checkout:Important: Create your products once (either in dashboard or via API), then reuse the same product ID for all checkout sessions. Don’t create a new product for each checkout!
Using Metadata
Metadata allows you to attach custom data to a checkout session. This data is:- Returned in API responses
- Included in webhook events
- Visible in your dashboard
Example Use Cases
Metadata Limits:
- Maximum 50 keys
- Keys must be strings
- Values must be strings (use
JSON.stringify()
for objects/arrays) - Total size limit: 5KB
Listing Checkout Sessions
Retrieve all checkout sessions for your account:Query Parameters
Parameter | Type | Description |
---|---|---|
limit | number | Number of sessions to return (1-100, default: 50) |
offset | number | Pagination offset (default: 0) |
status | string | Filter by status: open , completed , expired , failed |
externalCustomerId | string | Filter by customer ID |
Getting a Specific Session
Retrieve details of a single checkout session:Session Statuses
Status | Description |
---|---|
open | Session is active and awaiting payment |
completed | Payment was successful |
expired | Session expired without payment (default: 1 hour) |
failed | Payment failed |
Handling Post-Payment
After a customer completes or cancels payment, they’ll be redirected based on your payment link configuration.Success Redirect
Set asuccessUrl
when creating your payment link:
Query Parameters
Loops automatically appends query parameters to your redirect URLs so you can track the session:Success URL Parameters
When a payment succeeds, customers are redirected to yoursuccessUrl
with these parameters:
Parameter | Description | Example |
---|---|---|
session_id | The checkout session ID | cs_abc123xyz |
status | Session status | completed |
Cancel URL Parameters
When a customer cancels, they’re redirected to yourcancelUrl
with these parameters:
Parameter | Description | Example |
---|---|---|
session_id | The checkout session ID | cs_abc123xyz |
status | Session status | canceled |
You can also use the
{CHECKOUT_SESSION_ID}
placeholder in your URLs, which will be replaced with the actual session ID:Example Redirect Flow
Here’s how the redirect flow works:-
You configure the payment link:
-
Customer completes payment → Redirected to:
-
Customer cancels payment → Redirected to:
If your URL already has query parameters, Loops will append the session parameters with
&
:Handling the Redirect
Don’t rely solely on redirects for order fulfillment! Always use webhooks to verify payment completion, as users can close the browser before being redirected.
Best Practices
1. Always Use HTTPS
Ensure your success and cancel URLs use HTTPS in production.2. Implement Webhooks
Use webhooks as your primary method for detecting successful payments. Redirects should only be used for user experience. See our Webhooks Guide for implementation details.3. Include Customer ID
Always includeexternalCustomerId
to link sessions to your users:
4. Handle Errors Gracefully
5. Set Appropriate Metadata
Use metadata to store information you’ll need later:Common Errors & FAQs
”Where do I get the payment link ID?”
This is the most common question! You have two options:- Copy from Dashboard: Products → Click ⋮ menu → “Copy Product ID”
- Create via API: Use the product creation endpoint and save the returned ID
Payment Link Not Found
- Verify the
paymentLinkId
orproductId
is correct (check for typos) - Make sure the product exists in your dashboard
- Confirm you’re using the right API key (test vs live mode)