Cancel Order
Cancel an existing order. Only orders that haven't been delivered can be cancelled.
Endpoint
POST /v1/orders/{order_id}/cancel
Request
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
order_id | string | Yes | The order ID |
Headers
Authorization: Bearer YOUR_ACCESS_TOKEN
Content-Type: application/json
Request Body (Optional)
| Field | Type | Required | Description |
|---|---|---|---|
reason | string | No | Cancellation reason |
Example Request
curl -X POST ${API_URL}/v1/orders/order_1a2b3c4d5e6f/cancel \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"reason": "Customer requested cancellation"
}'
PHP Example
<?php
$access_token = 'YOUR_ACCESS_TOKEN';
$order_id = 'order_1a2b3c4d5e6f';
$ch = curl_init("${API_URL}/v1/orders/{$order_id}/cancel");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'reason' => 'Customer requested cancellation'
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $access_token,
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$order = json_decode($response, true);
echo "Order cancelled: " . $order['status'];
?>
Response
Success Response (200 OK)
{
"id": "order_1a2b3c4d5e6f",
"tracking_number": "FUF123456789",
"status": "cancelled",
"cancellation": {
"reason": "Customer requested cancellation",
"cancelled_at": "2024-01-15T12:00:00Z"
},
"updated_at": "2024-01-15T12:00:00Z"
}
Error Response (400 Bad Request)
{
"error": {
"code": "cannot_cancel",
"message": "Cannot cancel order with status 'delivered'"
}
}
Error Response (404 Not Found)
{
"error": {
"code": "order_not_found",
"message": "Order not found"
}
}
Cancellation Rules
| Status | Can Cancel? | Notes |
|---|---|---|
pending | ✅ Yes | Full refund |
picked_up | ✅ Yes | May incur cancellation fee |
in_transit | ✅ Yes | May incur cancellation fee |
out_for_delivery | ⚠️ Maybe | Contact support |
delivered | ❌ No | Cannot cancel delivered orders |
cancelled | ❌ No | Already cancelled |
Refunds
Cancellation refunds are processed based on the order status:
- Pending: Full refund within 3-5 business days
- Picked up: Partial refund (minus pickup fee)
- In transit: Partial refund (minus handling fees)