# Reseller webhooks

Each reseller can register up to `TREVO_WEBHOOK_MAX_ENDPOINTS` HTTPS endpoints (**Webhooks** in the panel).

## Events
- `order.updated`: an order you placed reached a new final or review state (success, partial, failed, manual_review, refunded).
- `webhook.test`: sent by the **Send test** button.

## Envelope
```json
{"id": "01J...", "type": "order.updated", "created_at": "2026-12-06T10:00:00Z",
 "data": {"order": {"order_id": "01J...", "status": "success", "amount": {"reserved": "100.00", "charged": "100.00", "released": "0.00"}, "items": []}}}
```
The envelope never contains provider references, voucher codes, credentials or internal ids.

## Headers
`X-Trevo-Event`, `X-Trevo-Delivery` (equals `id`), `X-Trevo-Signature: t=<unix>,v1=<hex>`.

## Verification
`v1 = HMAC-SHA256(secret, t + "." + raw_body)`. Compare in constant time, reject `t` older than 5 minutes, and de-duplicate on `id`.

## Delivery guarantees
- **At least once.** Duplicates are possible (for example after a timeout where your server did process the request). De-duplicate on `id`.
- **Not ordered across events.** Use the order endpoint for the current state rather than relying on arrival order.
- **Retries:** after a non-2xx response or a network error, retries follow about 1 min, 5 min, 15 min, 1 h, 2 h, 6 h and 12 h. After 8 attempts the delivery is marked `failed` and visible in the panel.
- **Timeout:** 10 seconds. Redirects are not followed.

## Safety (server side)
- HTTPS only, port 443, no credentials, IPv4 only.
- Every resolved address must be public. Private, loopback, link-local and reserved ranges are refused, which blocks requests into your internal network and cloud metadata services.
- The request connects to the address that was checked, which narrows DNS-rebinding attacks.
- Secrets are encrypted at rest and shown once. Rotating a secret stops old signatures verifying at once.

## Operations
- Scheduler: `trevo:webhooks:dispatch` (every minute) sends due first attempts and retries; `trevo:webhooks:prune` (daily) removes finished records older than `TREVO_WEBHOOK_RETENTION_DAYS`.
- A queue worker must be running. Deliveries wait in the table if it is not.
- Deliveries stuck `pending` for long periods usually mean the worker or scheduler is down; check `php artisan queue:failed`.
