Cancel an unpaid order
POST
/Transactions/CancelOrder
const url = 'https://cybqa.pesapal.com/pesapalv3/api/Transactions/CancelOrder';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"order_tracking_id":"2489E9AD-2EE2-8E00-8EC9-32D5F69181C0"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://cybqa.pesapal.com/pesapalv3/api/Transactions/CancelOrder \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "order_tracking_id": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0" }'Cancels an order that has not been paid.
Cancelling is not idempotent: a second cancellation of the same order
fails with Invalid order state. Order cannot be cancelled.
The cancellation is not reflected anywhere else in the API.
getTransactionStatus continues to report the order as pending, so
record the cancellation yourself.
Every failure returns the same message, Invalid order request.,
whether the id is unknown, malformed, empty or missing.
Authorizations
Section titled “Authorizations”Request Bodyrequired
Section titled “Request Bodyrequired”Media typeapplication/json
object
order_tracking_id
required
string format: uuid
Examplegenerated
{ "order_tracking_id": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0"}Responses
Section titled “Responses”Returned for both success and failure. This response has no error
key in either case. Read status.
Media typeapplication/json
Returned by cancellation and refund operations. There is no error key
in this shape, on success or failure.
object
status
"200" on success, "500" on failure.
string
message
string
Examples
{ "status": "200", "message": "Order successfully cancelled."}{ "status": "500", "message": "Invalid order state. Order cannot be cancelled."}