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
- 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 theAuthorization 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 returnedcheckoutUrl to your frontend and redirect the user.
Best practices
- Always generate a unique
externalReferencefor each order or invoice. - Store the returned
idandcheckoutRefin your database for reconciliation. - Prefer using a
callbackUrlso 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
SUCCEEDEDbefore fulfilling an order.
Notes
checkoutUrlis the main link your customer should open to complete payment.successUrlandcancelUrlare customer-facing redirect URLs.callbackUrlis intended for server-to-server notifications.- The initial returned
statusmay bePENDING, 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
