Partner dashboard
The partner / affiliate surface lets an external affiliate sign in and see the seats and
expected monthly payout attributed to its referral code. A partner is a distinct trust tier from
admins and tenants: it is served by the /partner/* surface on the admin-API host (ai-api-admin.myra.eu), authenticates with its
own cookie (aig_partner) and JWT (purpose="partner", never the aig_admin session), and can reach
only its own aggregates — never another partner's data, and never any referred customer's identity.
Partners may be admin-provisioned (see Admin: partners) or self-register through the open, instant self-signup below — a self-registered partner is active immediately (referral code + payout eligibility), with no human approval gate. Email ownership is still proven via the partner email-OTP before any session is granted (anti-squatting).
Cross-origin (CORS) policy
The partner SPA is served from the app origin (https://ai.myra.eu in production,
https://ai-beta.myra.eu on beta) and calls the /partner/* surface on the admin-API origin
(ai-api-admin*.myra.eu), so every partner request is cross-origin and credentialed (the
aig_partner cookie). Each response — the OPTIONS preflight, every success, and every error (401 /
403 / 404 / 429 / 503) — carries Access-Control-Allow-Origin: <the app origin> together with
Access-Control-Allow-Credentials: true. Every error answer also carries X-Request-Id (32 hexadecimal
characters) and exposes it to the browser — the id support uses to find the request; see
Error codes › Request id on admin errors.
- The allowed origin is a single, fixed, server-configured value — the one SPA front door of the deployment, resolved once per request from the platform's configured app origin (falling back to the admin SPA origin). Beta and production each resolve to their own app origin automatically; there is no per-surface override to misconfigure.
- The request
Originheader is never trusted. It is never reflected intoAccess-Control-Allow-Originand never widened to*. An absentOrigin, a mismatched one (e.g.https://evil.example), and a malformed/garbage one all produce the same header — the configured app origin — so a browser whose page origin is not the configured SPA origin has its credentialed request rejected by the browser's own CORS check. A*wildcard is never emitted on this credentialed surface (it is forbidden with credentials and would be a cross-site read). - Fail-closed: if the front door is unconfigured the response still carries a fixed origin (the platform default), never the caller's origin, so a misconfiguration can only block partners on the wrong host — never expose their data to an attacker page.
Attribution & payout model
- Attribution is stamped on the whole referred tenant, for its lifetime, by the partner id
(never the code string, so a code rename never breaks past attributions). It is set once — at
self-serve signup from the
refcode (see Authentication) or by an admin crediting a sales deal — and never mutated afterward. - Commission defaults to 10% of the referred tenant's monthly recurring revenue (per-partner overridable). The expected payout is computed from the active paying subscriptions below and paid out through the SEPA credit-transfer and Gutschrift export flow described later in this chapter.
- Payout base = active paying subscriptions only: a subscription counts toward the expected payout
only when it is
activeand its Stripe status isactiveand it is not cancel-at-period-end. Trials and cancel-at-period-end accounts count as attributed seats (grace-period accounts count as attributed tenants only, and are excluded from the active-seat tile) but contribute €0 to payout. Currency is EUR; a non-EUR, tiered, unpriced, or unresolvable subscription is skipped from the payout (never silently counted as €0) and logged for ops.
Sign-in (partner front-door)
Email one-time-passcode, at ai-api-admin.myra.eu/partner/auth/*. The address is canonicalised; unknown/suspended
partners are indistinguishable from known ones (anti-enumeration).
| Method | Path | Auth | Description |
|---|---|---|---|
POST |
/partner/auth/otp/request |
none | Body { "email": "…" }. Always 200 {message} for a well-formed email ("if that email is a registered partner, a code has been sent"); 400 invalid_email for a malformed address, 400 email_required for an absent, empty or blank email, 400 invalid_email for a JSON null or non-string one; 429 otp_request_cap over the per-address request cap; 503 unavailable on a backend fault (never a false "code sent"). |
POST |
/partner/auth/otp/verify |
none | Body { "email": "…", "code": "<emailed six-digit code or static code>" }. 200 {partner} + sets the aig_partner cookie on success; 401 invalid_otp (sentence invalid or expired code) for a wrong or expired code; 403 partner_inactive for a valid code whose partner is no longer active; 429 otp_attempt_cap/otp_failure_cap (a spent 24 h guess budget answers otp_failure_cap: wait for the window or ask Support); 503 unavailable on a backend fault; 400 when email/code absent or malformed — the email is judged first (email_required / invalid_email, as on /otp/request), then the code: absent → code_required, a JSON null or non-string/non-number → invalid_code, over 64 raw bytes → code_too_long (the sentence stays email and code required). A malformed non-empty email (or one over the length limit) combined with a code that is absent, wrong-typed or over 64 bytes answers 400 { "error": "email and code required", "code": "invalid_email" } (the email is judged first, so its code wins); with a code of acceptable type it answers 400 { "error": "invalid email address", "code": "invalid_email" }. The code is trimmed of surrounding ASCII whitespace and must then be 4–32 bytes, else 400 { "code": "invalid_otp" }; both checks run before any counter or database read and are never counted as a guess. The partner is re-checked active at issuance. |
POST |
/partner/auth/logout |
aig_partner |
Clears the cookie. |
Mail cap. At most 5 code mails per hour per address are sent for partner sign-in codes, counted across the whole cluster (a fixed hourly window, so a burst straddling the window boundary can briefly reach up to twice the cap). Above it the route gives its normal success answer, with the same status, body and headers: no mail is sent and no code is stored. A per-node emergency brake of 120 mails per minute across all code-mail routes does the same and writes an error-log line for operators. A database fault while counting is the route's usual transient 503. Limits (accepted side effects). A stranger who keeps sending 5 requests per hour for a victim's address can keep the victim from getting a new code for that hour (an earlier, still-live code keeps working); and the per-node emergency brake (120 mails per minute) can be used up by requests for about two dozen known addresses, after which no code mails go out from that node for the rest of the minute.
Self-signup (open/instant)
A prospective affiliate registers itself at the public partner front-door. The partner is created
active at once (no approval queue); the session is granted only after the emailed OTP is verified
through the existing /partner/auth/otp/verify — so the flow is
signup → (emailed code) → verify → dashboard.
| Method | Path | Auth | Description |
|---|---|---|---|
POST |
/partner/auth/signup |
none | Body { "name": "…", "email": "…", "referral_code"?: "…" }. Creates an active partner and emails an OTP, then 201 { message, email, referral_code }. Issues no session cookie — the client then verifies the emailed code at /partner/auth/otp/verify. |
- Accepted/rejected input (trust boundary, fail-closed — the client is never the authz boundary):
Content-Type—signup,otp/requestandotp/verifyrequireapplication/json; any other type (or none) →400 { "code": "unsupported_content_type" }before the body is read.- A JSON body in which an object repeats a key (
{"email":"a@x.com","email":"b@x.com"}) →400 { "code": "duplicate_key" }; nothing is stored and no code is mailed. name— trimmed, then 1–200 characters of well-formed UTF-8, not blank, with no control or format characters. Absent / non-string / blank / too-long / control- or format-char →400 invalid_name. The admin partner routes apply the same rule with a 255-character cap; aPATCHthat leaves a legacy stored name unchanged is a no-op, a changed name is validated.email— a single-@, ASCII, whitespace-free address ≤ 254 bytes, canonicalised before use. Absent or malformed →400 invalid_email. A second signup with an existing address →409 duplicate_email(one partner per email).referral_code— optional. Absent (omitted or JSONnull) → a unique code is auto-generated. Present → it must normalise to^[A-Z0-9-]{4,64}$(trimmed, upper-cased); a present-but-malformed code (wrong type, charset or length) →400 invalid_referral_codeand is never silently replaced by an auto-generated one (absent and malformed do not share a path). A code already in use →409 duplicate_code(one code per partner).- Abuse controls (still enforced under the open policy): a per-IP fixed-window signup cap (IPv6: per /64 — see How the public rate limits behave)
(
429 signup_rate_cap) and a per-IP cap on/otp/request; a transient backend fault is503(never a false201).commission_rateis not client-settable at signup — it defaults to the platform default (10%).
Static OTP. A partner may be assigned a fixed login code by an admin (see
Admin: partners below) — the partner-login mirror of the admin-account static OTP. A partner
carrying a static code does not receive an emailed one: /otp/request returns the same generic
200 but mints nothing (so the fixed code is never invalidated by the newest-code purge), and
/otp/verify accepts the fixed code via the shared verifier. Clearing the code (below) restores the
ordinary email-OTP flow. Used for demo/test partners and automation where a mailbox round-trip isn't
practical; the plaintext is never stored (only its sha256).
Accepted/rejected input (trust boundary): email must be a single-@, ASCII, whitespace-free
address ≤ 254 bytes; anything else → 400 invalid_email. On POST /partner/auth/otp/verify,
code is a string or number of 4–32 bytes (a minted 6-digit code or the static code; a new static code is at least 12 characters, a legacy shorter one signs in only until its 30-day grace ends, then 403 static_code_expired);
a JSON null, object, or array → 400 invalid_code and is never counted as a wrong guess.
Referral link & click tracking
The link a partner shares is a tracked redirect (shown as referral_url on the dashboard):
| Method | Path | Auth | Description |
|---|---|---|---|
GET |
/r/<code> |
none (public) | Logs a click, sets the aig_ref attribution cookie, then 302s to <app>/signup?ref=<code>. |
The link is the clean app-origin https://<app-host>/r/<code> (e.g. https://ai.myra.eu/r/ACME),
served same-origin on every environment's SPA front door (ai.myra.eu, ai-int.myra.eu,
ai-beta.myra.eu) — not the ai-api-admin API host. referral_url on the dashboard is built from the
app origin so partners always share the short form.
- Accepted/rejected input (trust boundary):
<code>is normalised to^[A-Z0-9-]{4,64}$and resolved to an active partner before any write or cookie. An unknown / malformed / suspended code (or a DB fault) still302s the visitor to/signupbut with norefand no cookie (fail-closed — no wrong attribution). The redirect host is fixed (the app origin); only the normalised code is interpolated, so it is not an open redirect and cannot inject headers. - Click counting: each hit is deduplicated to one per (partner, visitor, day) via a coarse,
non-identifying
sha256(client_ip)+daykey (aUNIQUE+INSERT IGNORE); the endpoint is also per-IP rate-limited (IPv6: per /64 — see How the public rate limits behave). The dashboard showsclicks_30d. Click rows are not used for attribution or payout, and cascade-delete with the partner on erasure. aig_refcookie (attribution window): scoped to the registrable domain (Domain=.myra.eu, derived from the app origin — not host-only),HttpOnly,Secure,SameSite=Lax, 60-dayMax-Age, carrying the normalised code. The domain scope lets the cookie — set by/r/on the app host (e.g.ai.myra.eu) — reach the cross-origin same-site signupPOSTonai-api-admin.myra.eu. BothPOST /admin/auth/signup/request(e-mail funnel) andPOST /admin/auth/<provider>/start(the OAuth Sign up with Google/Microsoft button) read it as a fallback whenbody.refis absent (explicitrefwins), through the one shared normalise + active-partner resolver — so a signup within the window is credited even when?ref=isn't on the signup URL and regardless of whether the prospect finishes via e-mail or OAuth, and a forged/garbage cookie can never attribute or inject (fail-closed). On the OAuth path the resolver runs at/start(the credentialed same-site POST, where the cookie is reliably present) and the resolved partner id rides the server-side sign-in state to the callback, which stamps the referred tenant's attribution exactly as the e-mail funnel does. On a dev/single host with no registrable parent (localhost/IP) the cookie is host-only. This assumes the app host and the admin API share one registrable domain.- Multi-intent fallback: attribution locks when a signup intent is created, but a
person may have several (e.g. a first request with the
aig_refcookie present, then a later one on a device where it was gone). If the intent that is finally consumed carries no partner, the tenant is still credited to the most-recent unconsumed ref-bearing intent for the same email — provided that partner is still active (so in the common case the attribution never blocks the signup; only in the microsecond race where that partner is hard-erased between the lookup and the insert does the insert fail safe — the signup retries and simply proceeds unattributed). This only ever FILLS a missing credit — it can never change or overwrite one already set (the fallback runs solely when the consumed intent carried no partner). (A partner's own GDPR erasure is the one unrelated path that later clears the credit.)
Dashboard
| Method | Path | Auth | Description |
|---|---|---|---|
GET |
/partner/v1/summary |
aig_partner |
The partner's own aggregate (counts + expected payout). |
GET |
/partner/v1/referrals |
aig_partner |
The partner's own referred tenants, in full detail. |
/summary response:
{
"referral_code": "ACME",
"referral_url": "https://ai.myra.eu/r/ACME",
"partner_name": "Acme GmbH",
"attributed_tenant_count": 12,
"total_active_seats": 87,
"expected_monthly_payout_eur": 214.50,
"commission_rate": 0.10,
"clicks_30d": 340
}
/referrals response — one row per referred tenant, in full:
{ "referrals": [ {
"company": "acme-gmbh",
"admin_name": "Jane Doe", "admin_email": "jane@acme.example",
"status": "active",
"seats": 12,
"usage": { "requests": 48210, "tokens": 91200000 },
"last_active_at": 1790000000,
"monthly_contribution_eur": 21.40,
"referred_at": 1788000000
} ] }
status ∈ active|trialing|grace|canceling|canceled|none. usage is a bounded 30-day rollup of the
billing ledger. admin_name/admin_email may be null when no admin resolves.
Isolation (full transparency, still hard-scoped): the v1 "aggregates-only / anonymized"
rule is superseded by CEO decision — a partner now sees its own referred tenants' identity
(company + admin name/email, for direct contact), status, seats, and usage, so it can coordinate. The
scope is still absolute: the partner id is taken only from the verified session; no path/query/body
accepts a partner or tenant id, so a partner can never see another partner's tenants. Exposing
referred-customer PII to the affiliate is deliberate — the legal footing (affiliate agreement + T&C/DPA)
is tracked internally. Data is read-through (the partner surface stores no copy), so a referred
customer's erasure removes it from the partner view automatically. A 503 catalog_unavailable is
returned if the price catalog is temporarily cold (never a misleading €0).
Referral code (self-service)
A partner can change its own referral code from the dashboard. The old code is kept as a permanent
alias (CEO decision): old /r/OLD and ?ref=OLD links keep attributing to the partner forever, so
a code change never loses conversions. The new code becomes primary. Attribution is keyed on the
partner id, never the code string, so a change never touches past attributions.
Partner-session scoped: the partner id comes only from the verified session (ngx.ctx.partner),
never a path/query/body — a partner can only ever read or change its own code.
| Method | Path | Auth | Description |
|---|---|---|---|
GET |
/partner/v1/referral-code |
aig_partner |
Current code + retired alias codes + cooldown state. |
PATCH |
/partner/v1/referral-code |
aig_partner |
Change the code. Body { code }. |
GET response:
{
"referral_code": "ACME",
"alias_codes": ["ACME2025", "OLDACME"],
"code_change_available_at": 1793000000,
"cooldown_days": 30
}
alias_codes are the partner's retired codes (all still attributing). code_change_available_at is
the unix-seconds time the next self-service change is allowed, or null when changeable now.
PATCH { code } — accepted shape: after trim + uppercase, the code must match [A-Z0-9-] and be
4–64 characters. On success (200) the current code is retired into the partner's retired codes, the new
code becomes primary, code_changed_at is stamped, and a partner.code_changed audit row is written
(old/new code only — codes are public vanity strings, never PII). Response { ok, referral_code,
code_changed_at }. The change and its partner.code_changed audit row commit in one transaction:
if the audit row cannot be written the code is not changed. A refused write answers
503 { error, code: "unavailable" } when nothing was written (retry) or 500 { error, code: "internal" }.
Rejected (each a DISTINCT outcome — the control is not defeated by sending garbage):
| Case | Status | code |
|---|---|---|
no code field (absent / JSON null) |
400 |
code_required |
| malformed (wrong charset / length / non-string) | 400 |
invalid |
| the code you already have | 400 |
unchanged |
| collides any live code OR any retired alias (incl. your own past codes — a code maps to exactly one place, forever) | 409 |
code_taken |
| within the 30-day cooldown | 429 |
cooldown (+ available_at, unix seconds) |
| too many attempts (per-partner rate limit) | 429 |
rate_limited |
| session partner no longer live | 404 |
not_found |
Cross-table uniqueness (a code lives in exactly one place across the partners' live codes and their retired codes) is enforced at every write path — self-service change, admin rename, and admin create — so a code can never resolve to two partners. The resolver checks the live code first (it wins), then the alias table.
Admin note: an admin rename (PATCH /admin/v1/partners/{id} with a new referral_code) also
retires the old code to an alias (old links keep attributing) and is rejected if the new code
collides a live code or any alias (409 duplicate_code / duplicate_alias). Admin changes have no
cooldown and do not consume or reset the partner's self-service cooldown clock. A multi-field
admin PATCH is atomic: status, name/email/commission and the code change commit together with
their audit rows in one transaction, so a refused field (409 duplicate_*, 400 invalid, 404 not_found
for a partner that vanished meanwhile) leaves nothing changed and mints no alias. A body that only
repeats the partner's unchanged legacy name stays a 200 no-op. Erasing a partner frees its codes (including
aliases) for future reuse — the partner is GDPR-gone and attribution is by id.
Bank & tax details (self-service)
The partner enters and maintains its own payout bank & tax detail from the dashboard. Partner-session
scoped: the partner id + on-file email come only from the verified session (ngx.ctx.partner),
never a path/query/body — so a partner can only ever see or change its own detail. The IBAN is
financial PII: it is stored in full server-side but only ever returned MASKED to last-4; the full
value never leaves the server on this surface (only the payout generator reads it in full).
| Method | Path | Auth | Description |
|---|---|---|---|
GET |
/partner/v1/bank |
aig_partner |
Own bank detail. IBAN is iban_last4 + has_iban only — never the full IBAN. Also returns bic, account_holder_name, country, vat_status, vat_id, address_line, postal_code, city, self_billing_consent_at, payout_min_cents, payout_hold, iban_changed_at. An unset bank is { "has_iban": false, "payout_hold": false }. |
PUT |
/partner/v1/bank |
aig_partner |
Set the non-IBAN tax/bank fields. Body any of { account_holder_name, bic, country, vat_status, vat_id, address_line, postal_code, city, self_billing_consent }. No OTP (not the account-takeover vector). |
POST |
/partner/v1/bank/iban-otp |
aig_partner |
Mail a fresh one-time code to the on-file address (the change confirmation). 200 {message}; 429 otp_request_cap over the per-address cap; 503 unavailable on a backend fault; 500 internal when the on-file address is unusable (not retryable; contact Support). |
PUT |
/partner/v1/bank/iban |
aig_partner |
Change the payout IBAN. Body { iban, otp }. Requires the fresh OTP; on an actual change it stamps iban_changed_at, audits (old-masked → new-masked + ip) and emails the on-file address. 200 {ok, changed, iban_last4}. |
Anti-account-takeover controls (mandatory). Changing the IBAN — the money-drain vector — requires a
fresh emailed OTP (partner_iban_change purpose, isolated from the login code), sends an email
alert to the on-file address on any change, stamps iban_changed_at (which drives a 7-day
cooling-off hold on the next payout, enforced at export), and writes a full partner.iban_changed
audit row (old/new last-4 only, ts, ip). A stolen session alone cannot drain funds: the attacker
also needs the on-file mailbox, and the owner is alerted.
Accepted / rejected input (trust boundary, invariant 11 — a malformed value is rejected, never degraded to "no value"):
iban— normalised (whitespace stripped, upper-cased) then validated:[A-Z0-9]only, 15–34 chars, exact per-country length, ISO 7064 mod-97 checksum, and the country must be in the SEPA allowlist. Any failure →400 invalid_iban; the IBAN is never stored. A malformed IBAN is validated before the OTP is consumed (a typo does not burn a code). Re-submitting the IBAN already on file is a no-op200(no re-stamp, no notification, so a replay cannot reset the cooling-off). A500 internalanswered before any code check means the on-file address is unusable: retrying does not help, and nothing was consumed or written (contact Support). The IBAN change and itspartner.iban_changedaudit row are one transaction.503 unavailablemeans nothing changed; the OTP is always consumed before the save, so a fresh code is needed after any refused or failed save. After a500 internalthe outcome may be unknown: checkGET /partner/v1/bank(masked last-4) and, if the IBAN is not yet the new one, request a fresh code and retry. The notification mail is skipped when the commit outcome is unknown.otp— a string or number; a JSONnull/object/array →400 otp_requiredand is never counted as a wrong guess. A code over 64 raw bytes, or whose trimmed form is not exactly 6 ASCII digits, →400 invalid_otp(checked before any counter or database read, never counted as a guess); a wrong/expired code of valid shape →401 invalid_otp; caps →429 otp_attempt_cap/otp_failure_cap. The partner sign-in code (POST /partner/auth/otp/verify) and this IBAN-change code each also carry a database-backed budget of 20 kept wrong guesses per address per fixed 24 hours, shared by every gateway node and kept separately for the two flows. When it is spent the answer is429 otp_failure_cap("try again later") and the code is not compared, even if correct; an unknown and a known address answer identically. While it is spent a successful verify is impossible too, and a code request does not clear it: a locked partner gets back in when the 24 h window (it starts with the first counted failure since the budget was last empty) ends, or when Support lifts the lock after verifying identity. A budget fault is503. A partner's static code that reaches the cap recordsauth.static_otp_locked(Audit log). Same budget rules as Authentication, except the answer code.vat_status— one ofvat_registered|kleinunternehmer|non_eu; anything else →400.nullclears it.bic— validated only when present: 8 or 11 chars,AAAAAA(6 letters) +NN+ optionalNNN[A-Z0-9]; otherwise400.nullclears it.country— a 2-letter code;vat_id—[A-Z0-9]{4,20}(whitespace stripped, upper-cased);account_holder_name— 1–255 bytes of well-formed UTF-8 with at least one visible character; no control characters (C0, DEL, C1) and none of the invisible characters that would disguise the value on a printed document: the line/paragraph separators U+2028/U+2029, the interlinear annotation controls U+FFF9–U+FFFB, the braille blank U+2800, and every Unicode default-ignorable code point (zero-width and bidi controls, soft hyphen, byte-order mark, word joiner / invisible operators, Hangul fillers, Unicode tag characters …) except a variation selector (U+180B–U+180D, U+180F, U+FE00–U+FE0F, U+E0100–U+E01EF) that directly follows a base character of its own kind (a symbol or emoji, a CJK ideograph, a Mongolian letter), at most one per base; any other variation selector is refused, so emoji (❤️), CJK variants and Mongolian text stay accepted. A malformed value →400; a JSONnullclears the field; an absent key leaves it unchanged (three distinct paths).- Postal address (the supplier address the self-billing Gutschrift must carry, §14 UStG):
address_line(street and house number) — 1–255 bytes,city— 1–128 bytes, both trimmed and held to the same character rule asaccount_holder_name(well-formed UTF-8, a visible character, no control or invisible characters);postal_code— 1–16 chars of letters, digits, spaces and hyphens, starting with a letter or digit (upper-cased, inner spaces collapsed:sw1a 1aa→SW1A 1AA). Anything else (empty, non-string, too long, other characters) →400;nullclears; absent leaves unchanged. self_billing_consent— a boolean:truestampsself_billing_consent_at = now(the partner accepts the self-billing credit-note / Gutschrift T&C);falsewithdraws it; a non-boolean →400.payout_min_cents/payout_holdare operator-only — a self-servicePUTcan never set its own payout floor or lift its own hold (they are silently not accepted on this surface; see admin CRUD).
Error responses carry a stable code. Every error on the partner surfaces returns
{ "error": "<short text>", "code": "<stable code>" }. The code is the contract the dashboard keys
on — it maps each partner-specific code to a localized, friendly message and never renders the raw
error text (a closed set keyed by code). Any other failure — internal, unavailable, an unknown or
absent code, a network problem — is explained like every other error in the app: what failed, why (from the
status), what to do, and the support reference (Error messages in the app). Raw validation
detail (e.g. an IBAN "checksum failed" reason) is log-only and is scrubbed from the client body.
Codes in use:
code |
Status | When |
|---|---|---|
unauthenticated |
401 |
No aig_partner cookie, or the session names no partner. |
invalid_session |
401 |
A cookie is present but its session token is rejected. |
partner_inactive |
401 / 403 |
The session's partner is suspended or gone (401, on any /partner/v1 route); a valid sign-in code for a partner that is no longer active (403, on /partner/auth/otp/verify). |
unavailable |
503 |
Transient backend fault, or an audited write (referral-code change, bank save) that wrote nothing; retry. |
internal |
500 |
Unexpected storage fault on the dashboard, referral-code and bank routes. |
route_not_found |
404 |
No /partner/* or /partner/auth/* route matches the method and path. |
email_required / invalid_email |
400 |
Sign-in email: absent, empty or blank vs. malformed, null or not a string. |
code_required / invalid_code / code_too_long |
400 |
Sign-in code on /otp/verify: absent vs. null or the wrong type vs. over 64 raw bytes. |
invalid_otp |
400 / 401 |
(formerly otp_invalid) A malformed code (400), or a well-formed code that is wrong or expired (401). |
otp_required, otp_attempt_cap, otp_failure_cap, otp_request_cap |
400 / 429 |
IBAN-change and sign-in code flow, as described above. |
invalid_body |
400 |
Unparseable request body. |
invalid_iban, invalid, not_found |
400 / 404 |
Bank and referral-code field validation and lookups. |
Key off code, never the error sentence. A wrong IBAN-change OTP
is a 401 invalid_otp (or, for a wrong-shape code, 400 invalid_otp) with a code, so the client shows the "invalid code" message in place rather
than mistaking it for a session expiry and redirecting to login.
Admin: partners
Platform-admin only (PARTNERS_MANAGE). Every mutation is audited (the audit record carries ids and
changed-field names only — never the partner email/name; the IBAN only as a masked last-4).
| Method | Path | Description |
|---|---|---|
GET |
/admin/v1/partners |
List non-deleted partners. |
POST |
/admin/v1/partners |
Create. Body { name, email, referral_code, commission_rate? }. 201 { id } on success; 409 duplicate_code/duplicate_email; 400 invalid on a bad field. email must be a plain ASCII address (single @, dotted domain, no inner whitespace or control characters, at most 254 bytes; surrounding whitespace is trimmed first); it is stored trimmed and lower-case. Absent, null or blank → 400 invalid ("required"); a non-string → 400 invalid ("must be a string"); a malformed address → 400 { "error": "email must be a valid address", "code": "invalid_email", "field": "email" } (the partner signs in by this address). The admin UI's New partner page (/platform/partners/new) sends commission_rate as its percentage field divided by 100; an empty percentage, one that is not a number, or one outside 0–100 is refused on the page and nothing is sent (an empty field must not become 0, nor a malformed one null, which the server reads as the 10 % default). |
PATCH |
/admin/v1/partners/{id} |
Update status (active/suspended) and/or name/email/referral_code/commission_rate. 404 if no such live partner; 400 invalid for a bad value; email: null counts as not supplied (with no other field: 400 invalid, "no updatable fields provided"); a new email follows the same shape rules as on create, and a malformed one is 400 invalid_email (field: "email"); an empty or whitespace-only email is 400 invalid ("email is required"), never a clear and never invalid_email. An unchanged stored address is kept: re-sending the partner's current address (compared after trimming and lower-casing, against the stored row at the time of the write) is accepted even when it would fail the check today (a legacy row such as bob@localhost stays editable); it is not written and not listed in the audit's changed_fields, and a PATCH that only re-sends it answers 200 without an audit row. The PATCH is ONE transaction with its partner.updated (and, for a referral-code change, partner.code_changed) audit row: a refused or failed later step (409 duplicate_email / duplicate_code, 400 invalid / invalid_email, a database fault) rolls back the earlier steps, so nothing changes and no audit row is written — e.g. { "status": "suspended", "email": "x@y" } leaves the status as it was. No database connection or a retryable lock-wait fault is 503 { "error": "temporarily unavailable; retry later" } (nothing written); any other database fault is the sanitised 500 { "error": "internal error", "request_id": "…" } (never a 400). The steps run in order (status, then name/email/commission, then the referral code). |
PUT |
/admin/v1/partners/{id}/static-otp |
Set or clear the partner's static OTP. The body is absent/empty or a JSON object { "code": … }. code is a JSON string of 12–32 printable ASCII characters (space allowed inside) after trimming surrounding whitespace (hashed server-side; plaintext never stored). An absent body, {} or { "code": null } clears it. Nothing else clears it: any top-level key other than code (a misspelt Code, otp, or a stray key beside a valid code) is 400 unknown_field with the key in field (capped at 64 bytes; checked before the partner lookup, so an unknown key on a non-existent id is still 400), a body that is valid JSON but not an object (null, a string, a number, a boolean, an array) is 400 invalid_body, a body that is not valid JSON, or holds a non-finite number such as 1e400, is 400 malformed_body, a code that is not a JSON string (a number such as 12345 unquoted or 1e20, a boolean, an object, an array), that holds anything but printable ASCII after the trim (a non-ASCII character such as an umlaut or a non-breaking space, a control character, invalid UTF-8) or that is shorter than 12 characters is 400 invalid_code, and one longer than 32 characters is 400 code_too_long. These checks run before the length, so a code that is both over-long and malformed answers invalid_code. A refused request changes nothing and writes no audit row. Success is 200 { ok, code } on set (the chosen code is echoed once so the console can show it) or 200 { ok, cleared: true } on clear. 404 not_found if no such live partner, and also for a path id that is not 1–36 printable non-space ASCII characters, and for an id that differs from a real partner id only in letter case (the id is matched byte-exact; nothing is written and no audit row is added). A database fault answers one of the two generic storage-fault bodies (see Storage faults): a failed partner lookup is the retryable 503 and changes nothing. Audited as partner.static_otp_set / partner.static_otp_cleared (never the code). |
POST |
/admin/v1/tenants/{id}/credit-partner |
Credit a tenant to a partner (sales deal). Body { partner_id }. Set-once and atomic: 409 already_credited if the tenant already has a referrer; 400 partner_inactive for a suspended/unknown partner; 404 tenant_not_found. |
GET |
/admin/v1/partners/{id}/bank |
View a partner's bank detail (IBAN masked to last-4). An unset bank is { "has_iban": false, "payout_hold": false }. |
PUT |
/admin/v1/partners/{id}/bank |
Set/update the bank detail + payout config. Body any of { iban, bic, account_holder_name, country, vat_status, vat_id, address_line, postal_code, city, self_billing_consent, payout_min_cents, payout_hold }. The IBAN goes through the same validator (mod-97 + SEPA) and stamps iban_changed_at; payout_min_cents overrides the platform default (10000 cents = €100, enforced at export); payout_hold suspends payouts. payout_min_cents must be a JSON integer number (a string, even a numeric one, is 400 invalid). A body with nothing to write (e.g. {} or {"iban":null} alone) is 400 invalid and records no audit entry; re-sending the stored IBAN unchanged is 200 with changed_fields: [] and no audit entry. 400 invalid/invalid_iban on a bad field; 404 if no such partner. |
DELETE |
/admin/v1/partners/{id}/bank |
Clear a partner's entire bank detail (IBAN + all tax/config). 404 if there was none. |
DELETE |
/admin/v1/partners/{id}/erase |
GDPR Art. 17 erasure — see below. 200 { ok, counts } (the number of rows removed or cleared per kind); 404 not_found if no such partner. |
Accepted shape / what is rejected (create and update). The body must be a JSON object — a non-object body (array, scalar, null) on create, update, the bank PUT and credit-partner is
400 { "error": "request body must be a JSON object", "code": "malformed_body" } and nothing is written. referral_code is trimmed, upper-cased and must be
4–64 characters of A-Z 0-9 - (a non-string or any other character is 400 invalid); a code that is
live on another partner is 409 duplicate_code, one held as a retired alias 409 duplicate_alias. name must be a non-empty string. email goes through the shared address
normaliser (lower-cased, trimmed, one well-formed address); a malformed or absent address on create is
400 invalid, and an address already in use is 409 duplicate_email. commission_rate is a fraction
in [0, 1] (the admin console sends its percentage divided by 100); absent or JSON null on create
means the default 0.10, while a present value that is not a JSON number in that range (any string,
even a numeric one such as "0.2", NaN, infinity, negative, above 1) is 400 invalid — never coerced
or clamped. An accepted rate is stored to 4 decimal places (0.12345 is kept as 0.1235). On PATCH, commission_rate: null is 400 invalid (it never resets to the default) and
status must be exactly active or suspended, and a body with no updatable field is 400 invalid.
Every 400 invalid carries code: "invalid" and nothing is written by the refused step.
Number spellings (create, update, the bank PUT). These three routes read the body through the exact-number gate: a number written in a spelling JSON does not allow but a lenient parser would accept (hex 0x1, a leading + as in +0.5, a leading zero as in 01, a trailing dot) is refused 400 number_invalid, and an integer a double cannot hold exactly is 400 number_not_exact. Both name the offending top-level member in field (for example commission_rate, payout_min_cents) and nothing is written. The partner self-service bank PUT (/partner/v1/bank) reads no number: its operator-only columns (payout_min_cents, payout_hold) are never writable by the partner.
Atomic with the audit trail. Create, update, the bank PUT/DELETE, credit-partner, erasure and static-OTP
changes commit together with their audit row. A write that is refused before anything was written
(lock timeout, deadlock, connection lost before send) answers 503 { "error": "temporarily unavailable; retry later" }
— nothing changed, retry. Any other storage fault answers the sanitised
500 { "error": "internal error", "request_id": "…" } (the cause is logged under the request_id). A
bank PUT that carries a valid iban plus another invalid field is 400 (invalid_iban when the IBAN is the bad one) and
leaves the stored IBAN unchanged — the bank row is never half-applied. A bank PUT/DELETE or PATCH
on a partner that vanished meanwhile is 404 not_found.
Admin: partner payout export (SEPA + Gutschrift)
The partner-payout epic turns the payout ledger
into money actually paid: a bank-ready ISO 20022 pain.001.001.09 SEPA credit-transfer batch plus, per
partner, a self-billing Gutschrift (§14 Abs. 2 UStG) structured e-invoice. The gateway is the system
of record and produces the files; a human approves before any file exists; Finance submits the
file through the existing EBICS channel (the gateway never talks to the bank). All routes are
platform-admin only (PARTNERS_MANAGE); the money-mutating routes are additionally refused while
impersonating. Every approve/generate/export/pay is written to audit_log. Money is integer EUR cents.
A period is a run key YYYY-MM (the closed calendar month, Europe/Berlin). A malformed or absent
period is rejected 400 invalid_period — never coerced.
| Method | Path | Description |
|---|---|---|
GET |
/admin/v1/partner-payouts |
List generated batches (newest period first). |
GET |
/admin/v1/partner-payouts/review?period=YYYY-MM |
Per-partner eligibility for the run: status (ready/approved/exported/skipped), net/VAT/gross cents, VAT treatment, masked IBAN last-4, and a skip_reason for each skipped partner (no_consent/no_iban/payout_hold/dispute_hold/iban_cooling_off/below_threshold/no_balance/vat_*). period absent defaults to the just-closed month; present but not a real YYYY-MM (month 01-12), empty, or repeated is 400 invalid_period (never a silent fallback to the default month). |
POST |
/admin/v1/partner-payouts/approve |
Money gate. Body { period, partner_id }. Moves the partner's mature accruals → approved. 409 with code = the skip reason if the partner is not eligible; 400 invalid for a bad partner_id. |
POST |
/admin/v1/partner-payouts/unapprove |
Revert approved → mature (reversible before a batch exists). Body { period, partner_id }. |
POST |
/admin/v1/partner-payouts/generate |
Produce the pain.001 + one Gutschrift per approved, payable partner, atomically (gapless legal number allocation, rows → exported, batch recorded). Body { period }. Idempotent per period (a re-call returns the existing batch, byte-identical msg_id + XML). 409 empty if nothing is approved; 400 config if the debtor IBAN / buyer VAT id are unset. |
POST |
/admin/v1/partner-payouts/mark-exported |
Operator confirms the file was handed to the bank. Body { period }. generated → exported; must precede mark-paid. 404 if no batch. |
POST |
/admin/v1/partner-payouts/mark-paid |
Mark one partner paid (per-partner — a single rejected IBAN never marks the whole batch). Body { batch_id, partner_id }. Requires the batch to be exported (409 batch_not_exported); 409 no_exported_rows if that partner has nothing exported (already paid). |
GET |
/admin/v1/partner-payouts/pain001?period=YYYY-MM |
Download the SEPA pain.001 XML (attachment). 404 if no batch. |
GET |
/admin/v1/partner-payouts/batch/{id}/gutschriften |
List a batch's Gutschriften (metadata: number, VAT treatment, net/VAT/gross). |
GET |
/admin/v1/partner-payouts/gutschrift/{id} |
Download one Gutschrift e-invoice (UBL/XRechnung) XML (attachment). |
Accepted shape / what is rejected (trust boundary). period must match ^\d{4}-\d{2}$ with a real
month (01-12) — else 400 invalid_period; an empty or repeated period query parameter is rejected the same way. The query key is exactly period (case-sensitive); other or unknown query keys are ignored, so ?Period=... counts as absent (review: default month; pain001: 400). A request with more than 100 query arguments is rejected 400 invalid_period (the arguments past 100 cannot be inspected). partner_id/batch_id must be non-empty strings — else 400 invalid.
generate refuses (never emits a broken file) when: the debtor IBAN is unset or fails mod-97/SEPA
validation, the buyer VAT id is unset, the SEPA control sum ≠ Σ transaction amounts, or a partner's VAT
treatment cannot be determined (a missing/garbage vat_status/country, or an EU reverse-charge partner
with no VAT id → that partner is skipped with a reason, never issued a wrong document). A partner
whose destination IBAN changed < 7 days ago is held (iban_cooling_off) — the anti-ATO
cooling-off. A partner with an open dispute, on hold, without consent/IBAN, or below the payout threshold
is skipped-with-reason and carries forward to a later run. So is a partner whose postal address is
incomplete (no_address — street, postal code, city or country missing): a Gutschrift must carry the
supplier's full address, and the generator refuses to emit one without it rather than issue an
incomplete tax document.
approve, unapprove, mark-exported and mark-paid commit atomically with their audit rows; if
nothing was written the answer is 503 { "error": "temporarily unavailable; retry later" } (retry). The
accrual and close-month jobs likewise write each row together with its audit row and retry a refused
unit on the next tick.
A storage or generation fault on approve, unapprove, generate, mark-exported or
mark-paid after the write may have reached the server (a nothing-written fault is the 503 above) answers the sanitised 500 { "error": "internal error", "request_id": "…" } — no
detail field; the cause is logged under the request_id, never returned. A failed read — the
review, the batch list, a batch's file, its Gutschriften or one Gutschrift — answers
503 { "error": "temporarily unavailable; retry later" } (nothing written; retry).
Debtor / buyer configuration (platform settings, DB-backed, never env): partner_payout_debtor_iban
(required), partner_payout_debtor_bic, partner_payout_debtor_name, and the Gutschrift buyer party
partner_payout_buyer_name/_address/_city/_zip/_country/_vat_id (the buyer VAT id and the buyer street, postal code, city and country are required — §14 UStG needs both parties' full address on every Gutschrift, so a run with any of them unset is refused as a configuration error before any document is built).
Data protection
The partner row holds an email (PII), and the 1:1 partner_bank row holds financial PII
(IBAN, BIC, account-holder name, VAT ID, and the postal address — street, postal code, city; for a sole
trader that is a home address). Erasure (DELETE /admin/v1/partners/{id}/erase) runs in one
transaction: it purges the partner's one-time-passcode login rows, nulls every attribution
that references the partner (the referred tenant's attribution and referral timestamp, and the
attribution recorded on pending sign-ups), deletes the partner_bank row (all bank/tax PII), deletes
the partner row, and writes a counts-only partner.erased audit tombstone (no email/name/IBAN). The
partner_bank FK is also ON DELETE CASCADE, so the bank PII can never outlive the partner even by
accident. Suspending a partner (status='suspended') is a soft action that preserves history; only
erasure removes the PII.
Retention split (tax vs. PII). Once the payout ledger ships, executed
payouts are GoBD tax records retained ~10 years under the pseudonymous partner_id — the money
facts are kept while the contact + bank PII in the partner records is erased. The tax documents
themselves are the exception: an issued Gutschrift (self-billing credit note) carries the partner's name,
postal address, VAT ID and IBAN, and a SEPA batch file the name and IBAN, exactly as issued — they are kept
for the statutory retention period (§147 AO, §14b UStG; Art. 17(3)(b) GDPR) and are not altered by an
erasure. Erasing a partner therefore removes the live bank/contact detail, but not the issued tax documents
or the audited fact that a commission was paid. See
Data retention.
Numbers in partner API responses are written exactly as stored. If a response cannot be encoded, the endpoint answers 500 with { "error": "internal error", "code": "response_encode_failed" }; see Error codes.