# Cancelling

> Check what a cancellation costs, then cancel with a fee cap.

Source: https://docs.delivr.no/guides/cancelling/

What cancelling costs depends on how far the order has come. Always check first, or cap the fee.

## Check the fee

```bash
curl https://driver-staging-api.delivr.no/v1/merchant/orders/$ORDER/cancellation \
  -H "Authorization: Bearer $DELIVR_API_KEY"
```

```json
{
  "cancellable": true,
  "stage": "driver_en_route",
  "fee": { "amountMinor": 7900, "vatMinor": 1580, "exVatMinor": 6320, "currency": "NOK" }
}
```

| Stage             | On demand                                                           | Window             |
| ----------------- | ------------------------------------------------------------------- | ------------------ |
| `free`            | No driver has accepted yet, or a driver is handing the job back.    | Before `cutoffAt`. |
| `driver_en_route` | A driver accepted and is on the way. Your agreement's en-route fee. |                    |
| `driver_arrived`  | The driver is at the store. Your agreement's arrival fee.           |                    |
| `not_cancellable` | Picked up, or ended.                                                | After `cutoffAt`.  |

On demand there is no grace period: the fee applies from the moment a driver accepts.

## Cancel

```bash
curl -X POST https://driver-staging-api.delivr.no/v1/merchant/orders/$ORDER/cancel \
  -H "Authorization: Bearer $DELIVR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{ "reasonCode": "changed_mind", "maxFeeMinor": 0 }'
```

The answer has the cancelled `order` and the `fee` it settled with.

- **`maxFeeMinor`** caps the fee you accept. Send `0` to cancel only while it is free. If the fee is higher you get `409 fee_changed` with the current fee in `details`, and nothing is cancelled. Without `maxFeeMinor` you accept any fee.
- **`reasonCode`**: on demand `too_slow`, `changed_mind`, `price`, `found_other`, `wrong_details` or `other`; for windows `plans_changed` (default), `found_other`, `wrong_details` or `other`. `other` needs a `reasonText`.
- A window order after its cutoff answers `409 cancellation_not_allowed`.
- Cancelling again answers the same result, so retries are safe.

Fees appear on your weekly [invoice](/guides/billing/).