Checkout
Send customers to a payment page hosted by AutoPayKe and get a webhook when they've paid. No payment screens to build.
Checkout is the fastest way to take payments on a website or app. You create a checkout session on your server with the amount, send your customer to the session's url, and they pay on a page hosted by AutoPayKe. You don't build any payment screens or handle phone numbers. Endpoint details are in the Checkout reference.
How it works
Create a session on your server
With a key that has
collections:write.curl -X POST "https://api.autopayke.com/api/v1/checkout/sessions" \ -H "Authorization: Bearer $AUTOPAYKE_API_KEY" \ -H "Idempotency-Key: order-1042-checkout" \ -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" }'Send the customer to url
The page shows your workspace's name (with a verified tick once you have live access), the amount and your description. The customer types their M-Pesa number and gets a prompt. They can't change the amount or who gets paid.
Fulfil on the webhook
When they pay, the session moves to
completedand we sendcheckout.session.completedwith the session, including the id of the collection that paid it. Then we send the customer to yoursuccess_urlwith?session_id=cs_…added.
success_url is not proof of payment: anyone can open that URL. Ship the order only on checkout.session.completed (or a GET of the session that says completed).Rules
amountis in KES cents, whole shillings, KES 10 to KES 150,000.success_urlandcancel_urlmust be https.http://localhostis allowed with test keys.- Sessions expire after 30 minutes by default; set
expires_in_minutes(5 to 1440). Expire one early withPOST /api/v1/checkout/sessions/{id}/expirewhen the order is cancelled. - A customer gets 5 tries per session. A cancelled or failed prompt leaves the session open so they can try again.
- Each try is a collection, so the per-phone prompt cap and your workspace limits apply.
Statuses
| Status | Meaning | Webhook |
|---|---|---|
open | Waiting for the customer to pay. | - |
completed | Paid. collection is the col_ id that paid it. | checkout.session.completed |
expired | Not paid in time, or you expired it. | checkout.session.expired |
Testing
Create the session with an apk_test_ key. The hosted page shows a test-mode banner and no phone rings. Use the collection sandbox numbers on the page: 0700000001 pays, 0700000002 cancels, 0700000003 fails for insufficient funds and 0700000004 expires.