logoAccess

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

Create checkout 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

FieldTypeRequiredDescription
modestringYespayment or subscription
customer_idstringYesID of an existing customer
line_itemsarrayYes1–20 line items
success_urlstringYesRedirect URL after successful payment
cancel_urlstringYesRedirect URL if customer cancels
currencystringNoISO 4217 code (default: ETB)
metadataobjectNoArbitrary key-value pairs
expires_innumberNoSession expiry in seconds (300–86400, default 1800)
billing_intervalstringNomonthly 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

Get 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

List sessions
curl "https://api.tryaccess.xyz/api/v1/checkout/sessions?status=completed&limit=10" \
  -H "x-api-key: sk_..."
ParameterDescription
cursorPagination cursor
limitResults per page (1–100, default 20)
statusFilter: open, completed, expired, canceled
customer_idFilter by customer

Expire a Session

Manually expire an open session:

Expire 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:

EventDescription
checkout.completedPayment was successful
checkout.session.expiredSession expired

See Webhooks for setup instructions.

Endpoint Summary

ActionMethodEndpoint
CreatePOST/api/v1/checkout/sessions
ListGET/api/v1/checkout/sessions
GetGET/api/v1/checkout/sessions/:id
ExpirePOST/api/v1/checkout/sessions/:id/expire

How is this guide?