Checkout Sessions
Create hosted checkout sessions to collect payments from customers.
Checkout sessions provide a hosted payment page. Create a session, redirect your customer to the returned URL, and poll or use webhooks to detect completion.
Create a Session
curl -X POST https://api.tryaccess.xyz/api/v1/checkout/sessions \
-H "Content-Type: application/json" \
-H "x-api-key: sk_..." \
-d '{
"mode": "payment",
"customer_id": "cus_01HXYZ...",
"line_items": [
{
"price": 15000,
"quantity": 1,
"product_data": {
"name": "Premium Plan",
"description": "Monthly subscription"
}
}
],
"currency": "ETB",
"success_url": "https://yourapp.com/success",
"cancel_url": "https://yourapp.com/cancel"
}'Response:
{
"id": "cs_live_01HXYZ...",
"url": "https://yourapp.com/c/pay/cs_live_01HXYZ...",
"status": "open",
"expires_at": "2025-01-15T11:00:00.000Z"
}Redirect your customer to the url to complete payment. The session returns 201 Created.
Session Parameters
| Field | Type | Required | Description |
|---|---|---|---|
mode | string | Yes | payment or subscription |
customer_id | string | Yes | ID of an existing customer |
line_items | array | Yes | 1–20 line items |
success_url | string | Yes | Redirect URL after successful payment |
cancel_url | string | Yes | Redirect URL if customer cancels |
currency | string | No | ISO 4217 code (default: ETB) |
metadata | object | No | Arbitrary key-value pairs |
expires_in | number | No | Session expiry in seconds (300–86400, default 1800) |
billing_interval | string | No | monthly or yearly. Required when mode is subscription, must be omitted for payment |
Line Item Schema
{
"price": 5000,
"quantity": 2,
"product_data": {
"name": "Widget",
"image": "https://example.com/widget.png",
"description": "A useful widget"
}
}Prices are in minor units (santim for ETB). image and description in product_data are optional.
Get a Session
curl https://api.tryaccess.xyz/api/v1/checkout/sessions/cs_live_01HXYZ... \
-H "x-api-key: sk_..."Returns the full session including customer details, line items, billing interval, and linked transaction_id (once completed).
List Sessions
curl "https://api.tryaccess.xyz/api/v1/checkout/sessions?status=completed&limit=10" \
-H "x-api-key: sk_..."| Parameter | Description |
|---|---|
cursor | Pagination cursor |
limit | Results per page (1–100, default 20) |
status | Filter: open, completed, expired, canceled |
customer_id | Filter by customer |
Expire a Session
Manually expire an open session:
curl -X POST https://api.tryaccess.xyz/api/v1/checkout/sessions/cs_live_01HXYZ.../expire \
-H "x-api-key: sk_..."Only sessions with open status can be expired. Expiring a session also cancels the scheduled auto-expire job.
Session Lifecycle
open → completed (customer pays)
open → expired (timeout or manual expiry)
open → canceled (customer cancels)Sessions auto-expire after the expires_in duration (default 30 minutes).
Webhooks
Subscribe to checkout events to get notified when a session completes:
| Event | Description |
|---|---|
checkout.completed | Payment was successful |
checkout.session.expired | Session expired |
See Webhooks for setup instructions.
Endpoint Summary
| Action | Method | Endpoint |
|---|---|---|
| Create | POST | /api/v1/checkout/sessions |
| List | GET | /api/v1/checkout/sessions |
| Get | GET | /api/v1/checkout/sessions/:id |
| Expire | POST | /api/v1/checkout/sessions/:id/expire |
How is this guide?