# Cancel an order

`POST /v3/session/{sessionId}/order/cancel`

Section: Order Management. Base URLs: Playground https://playground-api.briqpay.com, Production https://api.briqpay.com. Auth: HTTP Basic.

Cancel an order of a payment session. It is only possible to cancel an order that has order status `order_approved_not_captured`. If the order has been captured it is no longer possible to cancel the order as it should be refunded instead. It is also not possible to cancel a pending or rejected order.  
  
Most payment providers confirm a cancellation right away and you get a `204`. A few process it in the background and answer `202` with `status: cancel_pending` instead. In that case the order sits in `order_cancel_pending` and the authorization stays live until the provider replies. You then get an `order_status` webhook with one of:  
  
* `order_cancelled` - the cancellation went through. An authorization that had already expired ends up here too, since it can no longer be captured. Look at `transaction.status` to tell them apart: `cancelled` or `expired`.  
* `order_approved_not_captured` - the provider refused the cancellation. The order is back where it was and can still be captured.

## Path parameters

- `sessionId` (string, required): **Format:** UUID

## Headers

- `Content-Type` (string, one of: `"application/json"`)
- `Accept` (string, one of: `"application/json"`)
- `Authorization` (string): Format: "Basic <base64(username:secret)>"

## Request example

```bash
curl -X POST 'https://playground-api.briqpay.com/v3/session/{sessionId}/order/cancel' \
  -H 'Authorization: Basic <base64(merchantId:secret)>' \
  -H 'Content-Type: application/json'
```

## Responses

### 202 The cancellation is accepted but not confirmed yet. The order is now `order_cancel_pending` and the authorization stays live until the provider replies. Wait for the `order_status` webhook - see the endpoint description for the outcomes.

- `status` (string, required, one of: `"cancel_pending"`)

### 204 The order is cancelled. The payment provider confirmed it right away, so there is no webhook to wait for.

No content.

### 400

- `error` (object)
  - `code` (string, one of: `"INVALID_CREDENTIALS"`, `"CANCEL_NOT_SUPPORTED"`, `"INVALID_DATA"`, `"ORDER_NOT_COMPLETED"`, `"ORDER_REJECTED"`, `"ORDER_PENDING"`, `"ORDER_ALREADY_CAPTURED"`, `"ORDER_ALREADY_CANCELLED"`, `"UNKNOWN"`)
  - `message` (string)

### 403

- `error` (object)
  - `code` (string, one of: `"INVALID_CREDENTIALS"`, `"INVALID_API_KEY"`, `"AUTH_SECRET_EXPIRED"`)
  - `message` (string)

### 404

- `error` (object)
  - `code` (string, one of: `"SESSION_NOT_FOUND"`)
  - `message` (string)
