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
/api/v1/checkout/sessionscollections:write Idempotency-Key requiredFix the amount and where to send the customer afterwards, and get the hosted page's url.
amountintegerrequiredKES cents, whole shillings, KES 10 to KES 150,000.
currencystringoptionalAlways "KES".
KESsuccess_urlstringrequiredhttps URL we send the customer to after paying, with ?session_id= added. http://localhost is allowed with test keys.
cancel_urlstringoptionalhttps URL for the Cancel link and after the session expires.
descriptionstringoptionalShown to the customer, up to 140 characters.
referencestringoptionalYour order or invoice id, up to 64 characters.
customer_namestringoptionalPre-fills the name on the page.
expires_in_minutesintegeroptional5 to 1440. Default 30.
metadataobjectoptionalUp to 20 string key-value pairs.
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"
}
}'{
"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"
}
}idstringcs_ followed by 24 characters.
statusstringopen, completed or expired.
opencompletedexpiredurlstringThe hosted page to send your customer to.
collectionstring | nullThe col_ id of the collection that paid the session, once completed.
expires_atstringWhen an unpaid session closes.
completed_atstring | nullWhen it was paid.
Plus the key and rate errors any keyed call can return.
List checkout sessions
/api/v1/checkout/sessionscollections:readNewest first, in the key's environment.
limitintegeroptionalHow many to return, 1 to 100. Default 20.
starting_afterstringoptionalCursor 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.
statusstringoptionalOnly sessions in this status.
opencompletedexpiredreferencestringoptionalOnly sessions with this reference.
curl "https://api.autopayke.com/api/v1/checkout/sessions?status=completed" \
-H "Authorization: Bearer $AUTOPAYKE_API_KEY"{
"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
/api/v1/checkout/sessions/{id}collections:readOne session, to confirm payment before you fulfil an order.
idstringrequiredThe session id (cs_…).
curl "https://api.autopayke.com/api/v1/checkout/sessions/cs_9Lp2Wq7Zt4Mn8Rx3Kb6Yc1Df" \
-H "Authorization: Bearer $AUTOPAYKE_API_KEY"{
"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"
}
}idstringcs_ followed by 24 characters.
statusstringopen, completed or expired.
opencompletedexpiredurlstringThe hosted page to send your customer to.
collectionstring | nullThe col_ id of the collection that paid the session, once completed.
expires_atstringWhen an unpaid session closes.
completed_atstring | nullWhen it was paid.
Expire a checkout session
/api/v1/checkout/sessions/{id}/expirecollections:writeClose an open session now, for example when the order is cancelled. A completed session can't be expired.
idstringrequiredThe session id (cs_…).
curl -X POST "https://api.autopayke.com/api/v1/checkout/sessions/cs_9Lp2Wq7Zt4Mn8Rx3Kb6Yc1Df/expire" \
-H "Authorization: Bearer $AUTOPAYKE_API_KEY"{
"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"
}
}