Add Pretix ticketing integration (every-minute sidecar sync)
- docs/backend/pretix.md: Pretix REST API reference (auth, orders/items endpoints, pagination, rate limiting, worked example) - migration 20260909000000_pretix_sync.sql: events.pretix_organizer + pretix_event_slug; _map_ticket_type, _ensure_auth_user (QR token = password), sync_pretix_attendees (service-role-only, idempotent) - sidecar: pretixFetch/fetchPretixOrders/fetchPretixItems/transformPretix, runPretixSync + every-minute runPretixLoop, POST /run-pretix, /status extended with pretix state - admin: Pretix panel + recent runs in Interfaces, per-event Pretix config + Sync button in Events, api/types for Pretix - docker-compose: PRETIX_API_KEY / PRETIX_BASE / PRETIX_SYNC_INTERVAL_MS Verified on VM: 25 paid orders -> 25 attendees, auto-sync every minute, login via QR token works, idempotent (no duplicate registrations). Co-authored-by: Stephan Charles <[email protected]> Co-authored-by: Amelia Hernandez <[email protected]> Co-authored-by: Markus Franz <[email protected]> Co-authored-by: Sabrina Hota <[email protected]> Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
1 parent
d5ec009cb5
commit
509e342204
8 files changed
+1009
-10
No files matched your search
@@ -0,0 +1,158 @@
|
||||
# Pretix — ticket order sync
|
||||
|
||||
The **Pretix integration** pulls paid ticket orders from
|
||||
[pretix.eu](https://pretix.eu) (pretix Hosted) into Convivo so that ticket
|
||||
buyers become registered attendees. The **sidecar** owns the polling and the
|
||||
transform; the database owns the write (a service-role-only RPC).
|
||||
|
||||
- Consumer: [`apps/sidecar/`](../../apps/sidecar/) — see
|
||||
[sidecar.md](./sidecar.md)
|
||||
- DB side: the `sync_pretix_attendees` RPC — see [rpcs.md](./rpcs.md)
|
||||
|
||||
## Service & credentials
|
||||
|
||||
| What | Value |
|
||||
|---|---|
|
||||
| Service | pretix.eu (pretix Hosted) |
|
||||
| REST API base URL | `https://pretix.eu/api/v1/` |
|
||||
| Authentication | token-based — header `Authorization: Token <API_KEY>` |
|
||||
| API key | `zkex2grqjxpcialy9msnm6zd7x1i2bc08gm8k5b7vlstpit7xb98p33oq7zggxqy` |
|
||||
| Organizer | "Austrian Power Platform Enthusiasts" (slug `appecommday`) |
|
||||
| Event | "Community Day 2026" (slug `tickets`), live, currency EUR, 2026-10-23 |
|
||||
|
||||
The API key is a **team-level token** created in the pretix web UI under an
|
||||
organizer team (Organizer → Teams → create token). It is **shown once** at
|
||||
creation — there is no way to retrieve it later, only regenerate.
|
||||
|
||||
## Endpoints we use
|
||||
|
||||
### 1. List paid orders
|
||||
|
||||
```
|
||||
GET https://pretix.eu/api/v1/organizers/appecommday/events/tickets/orders/?status=p
|
||||
```
|
||||
|
||||
Order resource fields we rely on:
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `code` | string | the order code (e.g. `BZWHN`) |
|
||||
| `status` | string | one of `n`=pending, `p`=paid, `e`=expired, `c`=canceled |
|
||||
| `email` | string | the buyer email |
|
||||
| `invoice_address` | object or null | has `name` |
|
||||
| `positions` | list | order-position objects (see below) |
|
||||
|
||||
Order-position fields we rely on:
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | integer | the position id |
|
||||
| `item` | integer | the item id |
|
||||
| `attendee_name` | string or null | |
|
||||
| `attendee_email` | string or null | **often null in practice** — fall back to the order `email` |
|
||||
| `secret` | string | the per-ticket secret — **we use this as the QR token / login password** |
|
||||
| `canceled` | boolean | |
|
||||
|
||||
### 2. List items (to map ticket type by name)
|
||||
|
||||
```
|
||||
GET https://pretix.eu/api/v1/organizers/appecommday/events/tickets/items/
|
||||
```
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | integer | |
|
||||
| `name` | multi-lingual object | e.g. `{"en": "Regular ticket"}` |
|
||||
| `active` | boolean | |
|
||||
|
||||
Currently the event has a **single item**: id `1074118`, name "Regular ticket".
|
||||
|
||||
## Pagination
|
||||
|
||||
List responses are:
|
||||
|
||||
```json
|
||||
{ "count": 42, "next": "https://.../orders/?status=p&page=2", "previous": null, "results": [ ... ] }
|
||||
```
|
||||
|
||||
50 results per page by default; **follow `next` until it is null**. You can
|
||||
pass `page_size` (max 50) and `page` query parameters.
|
||||
|
||||
## Conditional fetching (optional optimization)
|
||||
|
||||
The orders list returns an **`X-Page-Generated`** header (ISO 8601 server
|
||||
time). Pass it back as the **`modified_since`** query parameter on the next
|
||||
call to fetch only changed orders.
|
||||
|
||||
## Errors
|
||||
|
||||
4xx responses are JSON:
|
||||
|
||||
- General errors: `{"detail": "..."}`
|
||||
- Field errors: `{"<field>": ["message", ...]}`
|
||||
|
||||
| Status | Meaning |
|
||||
|---|---|
|
||||
| `401` | auth failure (bad/missing token) |
|
||||
| `403` | no permission / not found |
|
||||
| `404` | not found |
|
||||
|
||||
## Rate limiting (pretix.eu only)
|
||||
|
||||
**360 requests/minute per organizer account.** Exceeding it returns
|
||||
`429 Too Many Requests` with a **`Retry-After`** header (seconds to wait).
|
||||
Our usage (~2–4 requests/minute) is far below the limit.
|
||||
|
||||
## Worked example (anonymized)
|
||||
|
||||
A real paid-order response shape, based on verified data:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": "BZWHN",
|
||||
"status": "p",
|
||||
"email": "[email protected]",
|
||||
"invoice_address": { "name": "Markus Franz" },
|
||||
"positions": [
|
||||
{
|
||||
"id": 48560142,
|
||||
"item": 1074118,
|
||||
"attendee_name": "Markus Franz",
|
||||
"attendee_email": null,
|
||||
"secret": "awu65383xd8kyte8xkh...",
|
||||
"canceled": false
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Note `attendee_email` is null — the sync falls back to the order `email`
|
||||
(`[email protected]`) as the attendee's identity.
|
||||
|
||||
## How Convivo uses this
|
||||
|
||||
The sidecar **polls paid orders every minute** and, for each order:
|
||||
|
||||
1. **Groups positions by attendee email** — using `attendee_email`, falling
|
||||
back to the order `email` when `attendee_email` is null (one buyer, several
|
||||
tickets → several attendees under the same email).
|
||||
2. **Maps the ticket item name to a registration type** — `speaker` / `staff` /
|
||||
`sponsor` / `attendee` by substring match on the item name, **defaulting to
|
||||
`attendee`**.
|
||||
3. **Uses the position `secret` as the QR token** — which doubles as the
|
||||
contact's **login password** (the same convention as
|
||||
`create_registration` / `reset_registration_qr_token` in
|
||||
[rpcs.md](./rpcs.md)).
|
||||
4. **Writes via the service-role-only `sync_pretix_attendees` RPC** — the
|
||||
sidecar is the only component that holds the service-role key (see
|
||||
[sidecar.md](./sidecar.md)); the RPC upserts contacts + registrations
|
||||
transactionally and is idempotent on re-run.
|
||||
|
||||
## Source
|
||||
|
||||
- [REST API overview](https://docs.pretix.eu/dev/api/)
|
||||
- [Fundamentals — auth, pagination, errors, conditional fetching](https://docs.pretix.eu/dev/api/fundamentals.html)
|
||||
- [Token authentication](https://docs.pretix.eu/dev/api/tokenauth.html)
|
||||
- [Orders resource](https://docs.pretix.eu/dev/api/resources/orders.html)
|
||||
- [Items resource](https://docs.pretix.eu/dev/api/resources/items.html)
|
||||
- [Rate limiting](https://docs.pretix.eu/dev/api/ratelimit.html)
|
||||
Reference in new issue
Block a user