# Cancel Order

Use the Order Cancel API to cancel an unpaid or pending payment order created using the KwikPaisa Payment Gateway.

This API allows merchants to:

* Cancel abandoned payment sessions
* Expire unpaid payment links
* Prevent duplicate payment attempts
* Manage order lifecycle securely

Only eligible orders can be cancelled successfully.

***

## Endpoint

```http
POST /api/v3/pg/order/cancel
```

## Base URLs

### Sandbox

```http
https://sandbox.kwikpaisa.com
```

### Production

```http
https://api.kwikpaisa.com
```

***

## Authentication required.

Refer to:\
➡️ [Headers](/v3-guide/authentication/headers.md)\
➡️ [Signature Generation](/v3-guide/authentication/signature.md)\
➡️ [Timestamp Validation](/v3-guide/authentication/timestamp.md)

***

## Request Parameters

| Parameter  | Type           | Required | Description       |
| ---------- | -------------- | -------- | ----------------- |
| `order_id` | Integer/String | Yes      | Merchant order ID |

***

## Example Request Body

```json
{
  "order_id": 6116229263036
}
```

***

## Example cURL Request

```http
curl --request POST \
--url https://sandbox.kwikpaisa.com/api/v3/pg/order/cancel \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--header "X-API-KEY: pk_test_xxxxxxxxx" \
--header "X-SIGNATURE: GENERATED_SIGNATURE" \
--header "X-TIMESTAMP: GENERATED_TIMESTAMP" \
--data '{
  "order_id": 6116229263036
}'
```

***

## Example Success Response

```json
{
  "code": "200",
  "status": "success",
  "message": "Order cancelled successfully.",
  "return_data": {
    "order_id": 6116229263036,
    "order_status": "CANCELLED",
    "cancelled_at": "13-05-2026 09:14 AM"
  }
}
```

***

## Response Parameters

| Parameter      | Description                  |
| -------------- | ---------------------------- |
| `order_id`     | Merchant order ID            |
| `order_status` | Updated order status         |
| `cancelled_at` | Order cancellation timestamp |

***

## Cancel Eligible Statuses

Orders can typically be cancelled when they are in:

| Status       | Description              |
| ------------ | ------------------------ |
| `UN_PAID`    | Payment not completed    |
| `PROCESSING` | Payment under processing |

Orders that are already:

* `PAID`
* `FAILED`
* `EXPIRED`
* `CANCELLED`

may not be cancellable.

***

## Recommended Use Cases

Use Order Cancel API when:

* Customer abandons checkout
* Payment session expires
* Merchant wants to stop pending payment attempts
* Duplicate orders need cancellation

***

## Important Notes

* `order_id` must belong to your merchant account
* Cancellation may fail for completed payments
* Always verify final order status using Order Status API
* Cancelled payment links should not be reused

***

## Recommended Workflow

1. Create Order
2. Redirect customer to payment page
3. Customer abandons payment or session expires
4. Call Order Cancel API
5. Verify updated order status

***

## Common Errors

### 400 Bad Request

Possible reasons:

* Missing `order_id`
* Invalid request payload
* Incorrect request structure

***

### 401 Unauthorized

Possible reasons:

* Invalid API key
* Incorrect signature
* Expired timestamp

***

### Order Cannot Be Cancelled

Possible reasons:

* Payment already completed
* Order already cancelled
* Invalid order state

***

## Security Recommendations

* Generate signatures server-side only
* Use HTTPS for all API requests
* Never expose secret keys publicly
* Verify order ownership before cancellation
* Validate timestamps for every request

***

## Best Practices

* Cancel abandoned payment sessions regularly
* Verify order status before cancellation attempts
* Avoid duplicate payment links
* Store cancellation logs for reconciliation


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.kwikpaisa.com/v3-guide/payment-gateway-integration/cancel-order.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
