Skip to content

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

  1. 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"
      }'
  2. 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.

  3. Fulfil on the webhook

    When they pay, the session moves to completed and we send checkout.session.completed with the session, including the id of the collection that paid it. Then we send the customer to your success_url with ?session_id=cs_… added.

The redirect to 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

  • amount is in KES cents, whole shillings, KES 10 to KES 150,000.
  • success_url and cancel_url must be https. http://localhost is allowed with test keys.
  • Sessions expire after 30 minutes by default; set expires_in_minutes (5 to 1440). Expire one early with POST /api/v1/checkout/sessions/{id}/expire when 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

StatusMeaningWebhook
openWaiting for the customer to pay.-
completedPaid. collection is the col_ id that paid it.checkout.session.completed
expiredNot 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.