Skip to content

Checkout

Create a checkout session and send your customer to a payment page hosted by AutoPayKe. You get checkout.session.completed when they've paid.

A session is open until it's paid (completed) or it runs out of time (expired). The customer's payment is a collection; the first one that succeeds completes the session.

The redirect to success_url isn't proof of payment. Fulfil on the webhook, or GET the session.

Send your API key as Authorization: Bearer apk_test_… (sandbox) or apk_live_… (live). Each endpoint lists the scope the key needs. See API keys.

Create a checkout session

POST/api/v1/checkout/sessions
API keycollections:write Idempotency-Key required

Fix the amount and where to send the customer afterwards, and get the hosted page's url.

Body (JSON)
  • amountintegerrequired

    KES cents, whole shillings, KES 10 to KES 150,000.

  • currencystringoptional

    Always "KES".

    KES
  • success_urlstringrequired

    https URL we send the customer to after paying, with ?session_id= added. http://localhost is allowed with test keys.

  • cancel_urlstringoptional

    https URL for the Cancel link and after the session expires.

  • descriptionstringoptional

    Shown to the customer, up to 140 characters.

  • referencestringoptional

    Your order or invoice id, up to 64 characters.

  • customer_namestringoptional

    Pre-fills the name on the page.

  • expires_in_minutesintegeroptional

    5 to 1440. Default 30.

  • metadataobjectoptional

    Up to 20 string key-value pairs.

Request
curl -X POST "https://api.autopayke.com/api/v1/checkout/sessions" \
  -H "Authorization: Bearer $AUTOPAYKE_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 250000,
    "currency": "KES",
    "description": "2 x Maasai blanket",
    "reference": "order_1042",
    "success_url": "https://shop.example.com/orders/1042/thanks",
    "cancel_url": "https://shop.example.com/cart",
    "metadata": {
      "cart_id": "c_7781"
    }
  }'
Response201 application/json
{
  "ok": true,
  "data": {
    "id": "cs_9Lp2Wq7Zt4Mn8Rx3Kb6Yc1Df",
    "object": "checkout.session",
    "livemode": false,
    "status": "open",
    "url": "https://www.autopayke.com/c/cs_9Lp2Wq7Zt4Mn8Rx3Kb6Yc1Df",
    "amount": 250000,
    "currency": "KES",
    "description": "2 x Maasai blanket",
    "reference": "order_1042",
    "metadata": {
      "cart_id": "c_7781"
    },
    "customer_name": null,
    "success_url": "https://shop.example.com/orders/1042/thanks",
    "cancel_url": "https://shop.example.com/cart",
    "collection": null,
    "expires_at": "2026-11-03T09:40:00.000Z",
    "completed_at": null,
    "created": "2026-11-03T09:10:00.000Z",
    "updated": "2026-11-03T09:10:00.000Z"
  }
}
Response fields
  • idstring

    cs_ followed by 24 characters.

  • statusstring

    open, completed or expired.

    opencompletedexpired
  • urlstring

    The hosted page to send your customer to.

  • collectionstring | null

    The col_ id of the collection that paid the session, once completed.

  • expires_atstring

    When an unpaid session closes.

  • completed_atstring | null

    When it was paid.

Errors

Plus the key and rate errors any keyed call can return.

List checkout sessions

GET/api/v1/checkout/sessions
API keycollections:read

Newest first, in the key's environment.

Query parameters
  • limitintegeroptional

    How many to return, 1 to 100. Default 20.

  • starting_afterstringoptional

    Cursor for the next page: the id of the last item you got. Lists are newest first; when has_more is true, pass the last id here.

  • statusstringoptional

    Only sessions in this status.

    opencompletedexpired
  • referencestringoptional

    Only sessions with this reference.

Request
curl "https://api.autopayke.com/api/v1/checkout/sessions?status=completed" \
  -H "Authorization: Bearer $AUTOPAYKE_API_KEY"
Response200 application/json
{
  "ok": true,
  "data": {
    "object": "list",
    "data": [
      {
        "id": "cs_9Lp2Wq7Zt4Mn8Rx3Kb6Yc1Df",
        "object": "checkout.session",
        "livemode": false,
        "status": "completed",
        "url": "https://www.autopayke.com/c/cs_9Lp2Wq7Zt4Mn8Rx3Kb6Yc1Df",
        "amount": 250000,
        "currency": "KES",
        "description": "2 x Maasai blanket",
        "reference": "order_1042",
        "metadata": {
          "cart_id": "c_7781"
        },
        "customer_name": null,
        "success_url": "https://shop.example.com/orders/1042/thanks",
        "cancel_url": "https://shop.example.com/cart",
        "collection": "col_5Ty8nQw3Rz2Lm7Kc9Pd4Hs1V",
        "expires_at": "2026-11-03T09:40:00.000Z",
        "completed_at": null,
        "created": "2026-11-03T09:10:00.000Z",
        "updated": "2026-11-03T09:10:00.000Z"
      }
    ],
    "has_more": false
  }
}

Get a checkout session

GET/api/v1/checkout/sessions/{id}
API keycollections:read

One session, to confirm payment before you fulfil an order.

Path parameters
  • idstringrequired

    The session id (cs_…).

Request
curl "https://api.autopayke.com/api/v1/checkout/sessions/cs_9Lp2Wq7Zt4Mn8Rx3Kb6Yc1Df" \
  -H "Authorization: Bearer $AUTOPAYKE_API_KEY"
Response200 application/json
{
  "ok": true,
  "data": {
    "id": "cs_9Lp2Wq7Zt4Mn8Rx3Kb6Yc1Df",
    "object": "checkout.session",
    "livemode": false,
    "status": "completed",
    "url": "https://www.autopayke.com/c/cs_9Lp2Wq7Zt4Mn8Rx3Kb6Yc1Df",
    "amount": 250000,
    "currency": "KES",
    "description": "2 x Maasai blanket",
    "reference": "order_1042",
    "metadata": {
      "cart_id": "c_7781"
    },
    "customer_name": null,
    "success_url": "https://shop.example.com/orders/1042/thanks",
    "cancel_url": "https://shop.example.com/cart",
    "collection": "col_5Ty8nQw3Rz2Lm7Kc9Pd4Hs1V",
    "expires_at": "2026-11-03T09:40:00.000Z",
    "completed_at": "2026-11-03T09:12:05.000Z",
    "created": "2026-11-03T09:10:00.000Z",
    "updated": "2026-11-03T09:10:00.000Z"
  }
}
Response fields
  • idstring

    cs_ followed by 24 characters.

  • statusstring

    open, completed or expired.

    opencompletedexpired
  • urlstring

    The hosted page to send your customer to.

  • collectionstring | null

    The col_ id of the collection that paid the session, once completed.

  • expires_atstring

    When an unpaid session closes.

  • completed_atstring | null

    When it was paid.

Errors

Plus the key and rate errors any keyed call can return.

Expire a checkout session

POST/api/v1/checkout/sessions/{id}/expire
API keycollections:write

Close an open session now, for example when the order is cancelled. A completed session can't be expired.

Path parameters
  • idstringrequired

    The session id (cs_…).

Request
curl -X POST "https://api.autopayke.com/api/v1/checkout/sessions/cs_9Lp2Wq7Zt4Mn8Rx3Kb6Yc1Df/expire" \
  -H "Authorization: Bearer $AUTOPAYKE_API_KEY"
Response200 application/json
{
  "ok": true,
  "data": {
    "id": "cs_9Lp2Wq7Zt4Mn8Rx3Kb6Yc1Df",
    "object": "checkout.session",
    "livemode": false,
    "status": "expired",
    "url": "https://www.autopayke.com/c/cs_9Lp2Wq7Zt4Mn8Rx3Kb6Yc1Df",
    "amount": 250000,
    "currency": "KES",
    "description": "2 x Maasai blanket",
    "reference": "order_1042",
    "metadata": {
      "cart_id": "c_7781"
    },
    "customer_name": null,
    "success_url": "https://shop.example.com/orders/1042/thanks",
    "cancel_url": "https://shop.example.com/cart",
    "collection": null,
    "expires_at": "2026-11-03T09:40:00.000Z",
    "completed_at": null,
    "created": "2026-11-03T09:10:00.000Z",
    "updated": "2026-11-03T09:10:00.000Z"
  }
}
Errors

Plus the key and rate errors any keyed call can return.