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
Bearer token used to authenticate your API request.
Must be
application/json.Request body
Amount to be charged. Provide the full monetary amount in the currency specified.
Three-letter currency code. Example:
KES.Human-readable description of the payment. Example:
Payment for order #12345.URL where the customer should be redirected after a successful payment.
URL where the customer should be redirected if they cancel the payment flow.
List of allowed payment methods for this checkout session. Example:
["CARD", "MPESA_STK"].Your own external reference for reconciliation, such as an order ID.
Customer email address.
Customer phone number in international format. Example:
+237612345678.Reference shown or associated with the payment. Often this matches your order or invoice reference.
Webhook URL that Kiotapay can notify with payment updates for this checkout session.
Example request
Example response
Response fields
Public checkout session ID.
Hosted Kiotapay checkout URL. Redirect your customer to this link to complete payment.
Unique Kiotapay checkout reference for support, reconciliation, and tracking.
Current status of the checkout session.
Checkout session statuses
The checkout session has been created and is waiting for the customer to start or complete payment.
The payment needs an additional step from the customer, such as completing card authentication or approving an STK prompt.
The payment is being processed.
The payment completed successfully.
The payment failed.
The checkout session expired before payment was completed.
How it works
Create a checkout session
Call the endpoint with the payment details, redirect URLs, customer details, and allowed payment methods.
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
