Skip to main content

Overview

Use this endpoint to create a hosted checkout session for your customer. Kiotapay returns a checkout URL that you can redirect the customer to, open in a browser, or present as a pay button link inside your app. This is useful when you want Kiotapay to handle the payment collection flow for methods such as:
  • CARD
  • MPESA_STK
Once the session is created, your system receives a response containing:
  • a public checkout session ID
  • a unique checkout reference
  • the hosted checkout URL
  • the current status of the session

Endpoint

POST https://api.kiotapay.co/api/sandbox/v1/checkout-sessions
Use the sandbox base URL for testing. Switch to your production base URL when you go live.

Authentication

Send your bearer token in the Authorization header.

Headers

string
required
Bearer token used to authenticate your API request.
string
required
Must be application/json.

Request body

number
required
Amount to be charged. Provide the full monetary amount in the currency specified.
string
required
Three-letter currency code. Example: KES.
string
required
Human-readable description of the payment. Example: Payment for order #12345.
string
required
URL where the customer should be redirected after a successful payment.
string
required
URL where the customer should be redirected if they cancel the payment flow.
array[string]
required
List of allowed payment methods for this checkout session. Example: ["CARD", "MPESA_STK"].
string
Your own external reference for reconciliation, such as an order ID.
string
Customer email address.
string
Customer phone number in international format. Example: +237612345678.
string
Reference shown or associated with the payment. Often this matches your order or invoice reference.
string
Webhook URL that Kiotapay can notify with payment updates for this checkout session.

Example request


Example response


Response fields

uuid
Public checkout session ID.
string
Hosted Kiotapay checkout URL. Redirect your customer to this link to complete payment.
string
Unique Kiotapay checkout reference for support, reconciliation, and tracking.
enum
Current status of the checkout session.

Checkout session statuses

string
The checkout session has been created and is waiting for the customer to start or complete payment.
string
The payment needs an additional step from the customer, such as completing card authentication or approving an STK prompt.
string
The payment is being processed.
string
The payment completed successfully.
string
The payment failed.
string
The checkout session expired before payment was completed.

How it works

1

Create a checkout session

Call the endpoint with the payment details, redirect URLs, customer details, and allowed payment methods.
2

Receive the checkout URL

Kiotapay returns a checkoutUrl in the response.
3

Redirect or open the page

Send the customer to the hosted checkout page using the returned URL.
4

Track payment result

Use your successUrl, cancelUrl, and optional callbackUrl to track the final outcome.

Redirect example

After creating the checkout session on your backend, send the returned checkoutUrl to your frontend and redirect the user.

Best practices

  • Always generate a unique externalReference for each order or invoice.
  • Store the returned id and checkoutRef in your database for reconciliation.
  • Prefer using a callbackUrl so your backend can receive asynchronous payment updates.
  • Do not rely only on frontend redirects for final payment confirmation.
  • Validate that the final payment status is SUCCEEDED before fulfilling an order.

Notes

  • checkoutUrl is the main link your customer should open to complete payment.
  • successUrl and cancelUrl are customer-facing redirect URLs.
  • callbackUrl is intended for server-to-server notifications.
  • The initial returned status may be PENDING, even though the payment later moves to another state.

Sample integration flow


Error handling

Your integration should be prepared to handle standard API errors such as:
  • invalid authentication token
  • missing required headers
  • invalid payload fields
  • unsupported payment methods
  • invalid callback or redirect URLs
A typical error response may look like:

Full request schema

Full response schema