# ERP Integration

> Integrate your ERP with mako over CloudEvents 1.0 webhooks, the Command API and typed BO4E market data — HMAC signatures, idempotency keys, topology.

Source: https://hupe1980.github.io/mako/docs/architecture/erp-integration/

`makod` handles EDIFACT, BDEW process rules, AS4 delivery and regulatory
deadlines; contract data, billing logic and master data live in the ERP. The
contract between them is **BO4E** — the ERP never sees EDIFACT format versions
or segment codes, so a new BDEW format version leaves its payloads unchanged.

```
ERP  ←─────────── BO4E JSON ───────────→  makod
                (ErpAdapter / POST /api/v1/commands)
                        ↕
              EDIFACT / AS4 / BDEW network
```

Outbound events are **[CloudEvents 1.0](https://cloudevents.io)**
structured-mode JSON, which SAP BTP, AWS EventBridge, Azure Event Grid, Google
Eventarc and Knative route natively. With [`marktd`](https://hupe1980.github.io/mako/docs/services/marktd/)
deployed, `makod` pushes its process events to `marktd`
(`POST /api/v1/events`) and `marktd` fans them out to registered ERP
subscribers, so no webhook needs configuring in `makod` itself.

---

## Quick-start: wire the ERP webhook in 5 minutes

`makod` POSTs an event to the ERP whenever a process reaches a significant
state (APERAK received, process completed, …).

**Step 1 — Generate a shared secret**

```bash
export MAKOD_ERP_WEBHOOK_SECRET="whsec_$(openssl rand -base64 32)"
```

**Step 2 — Start makod with the webhook configured**

```bash
makod \
  --config /etc/makod/makod.toml \
  --data-dir /var/lib/makod \
  --erp-webhook-url https://erp.example.com/mako/events
```

Give the ERP receiver the same secret. To configure makod with a mounted secret file instead, use

```toml
[erp]
webhook_url    = "https://erp.example.com/mako/events"
webhook_secret_file = "/run/secrets/erp-webhook"
```

**Step 3 — Implement the ERP endpoint**

Your ERP must accept `POST` requests at the configured URL:

```
POST /mako/events
Content-Type:      application/cloudevents+json
X-Idempotency-Key: 01932a4f-7b3e-4c5d-8f6a-9e0b1c2d3e4f   ← always sent
traceparent:       00-4bf92f…-00f067…-01                  ← when the inbound transport carried one
webhook-id:        01932a4f-7b3e-4c5d-8f6a-9e0b1c2d3e4f   ┐
webhook-timestamp: 1786012800                             ├ only when a secret is set
webhook-signature: v1,K5oT9r8GKYqrTwjUPD8ILPZIo2LaLaSw…   ┘
```

Body (CloudEvents 1.0 structured-mode JSON):

```json
{
  "specversion": "1.0",
  "id": "01932a4f-7b3e-4c5d-8f6a-9e0b1c2d3e4f",
  "source": "urn:mako:makod:tenant:9900357000004",
  "type": "de.mako.engine.aperak.accepted",
  "time": "2026-10-01T10:15:00+02:00",
  "subject": "018f3a2b-...",
  "dataschema": "https://raw.githubusercontent.com/BO4E/BO4E-Schemas/v202607.1.0/src/bo4e_schemas/bo/Marktlokation.json",
  "datacontenttype": "application/json",
  "makoconvid": "...",
  "makocausationid": "...",
  "makopid": 55001,
  "data": {
    "_typ": "MARKTLOKATION",
    "_version": "202501",
    "marktlokationsId": "51238696799",
    "sparte": "STROM",
    "bilanzierungsmethode": "SLP",
    "energierichtung": "VERBRAUCH",
    "netzbetreibercodenr": "9900357000004"
  }
}
```

`webhook-id`, `X-Idempotency-Key` and the CloudEvent `id` are the same value.
`webhook-id` is what the signature covers; `X-Idempotency-Key` is sent
unconditionally, for a deployment without a secret.

**Step 4 — Verify the signature**

Pass the raw HTTP body and headers to the [Standard Webhooks] SDK. It verifies
the signature and enforces a five-minute clock tolerance. Use the verified
`webhook-id` to deduplicate across retries. The [receiver examples](#receiving-cloudevents-erp-implementation-guide)
use the same `whsec_` credential at both ends. [Official SDKs](https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries)

For an unprefixed mako credential, its UTF-8 bytes are the signing key. To give
an SDK the equivalent portable credential, base64-encode those bytes and prepend
`whsec_`. A subscription signs with both active keys during rotation. The SDK
can verify the delivery using either key.

[Standard Webhooks]: https://www.standardwebhooks.com/

**Step 5 — Return `HTTP 200` for duplicates**

`makod` retries on `429`, `5xx` and network errors; any other `4xx` is
permanent and dead-letters the message. Persist the id and answer a duplicate
with `200 OK` without re-processing.

---

## Integration surfaces

| Direction | Mechanism | Description |
|-----------|-----------|-------------|
| makod → ERP | `--erp-webhook-url` / `WebhookErpAdapter` | POST BO4E JSON on every process event |
| ERP → makod | `POST /api/v1/commands` | Initiate a MaKo process (Lieferbeginn, Gerätewechsel, …) |
| ERP → makod | `PUT /admin/malo/{malo_id}` | Push MaLo master data to the local cache |
| ERP → makod | `PUT /admin/partners/{mp_id}` | Register or update a trading-partner endpoint |
| marktd → invoicd | `POST /webhook` CloudEvents | GPKE/WiM billing notifications for automatic plausibility check |
| invoicd → makod | `POST /api/v1/commands` | the answering PID's accept/reject command (`gpke.abrechnung.*`, `wim.rechnung.*`, `gabi.rechnung.*`, `invoic.*`) |
| invoicd → ERP | `de.mako.invoic.receipt.settled/disputed` CloudEvents | Durable at-least-once payment notifications |
| invoicd → ERP | `de.mako.invoic.payment.overdue` CloudEvents | Announced once per receipt when `pay_by` passes without `confirm-payment` |
| ERP → invoicd | `POST /api/v1/receipts/{id}/confirm-payment` | Close § 147 AO / GoBD payment audit trail when bank transfer confirmed |
| ERP → invoicd | `GET /api/v1/zahlungsstatus/{malo_id}` | AR reconciliation — settled / pending / overdue counts |
| edmd API → ERP | `GET /api/v1/deliveries/{malo_id}` | BO4E `Vec<Energiemenge>` — typed meter readings for billing import |
| edmd API → ERP | `GET /api/v1/lastgang/{malo_id}` | BO4E `Lastgang` — interval time series grouped by OBIS register |
| edmd API → ERP | `GET /api/v1/billing-period/{malo_id}` | `MeterBillingPeriod` — arbeitsmenge, spitzenleistung, brennwert |
| ERP → marktd | `PUT /api/v1/nb-contracts/{id}` | Upsert NB contract with full BO4E `Vertrag` payload |
| processd API → ERP | `GET /obs/kpis` | BNetzA KPI report — § 7a Abs. 5 EnWG Gleichbehandlung parity, STP rates, decision times |
| Sales front end → productd | `POST /api/v1/products/{lf}/endkunden-angebote` | The frozen offer an order cites; with `vertriebspreis` the front end's own Arbeits- and Grundpreis become the contract's price ([productd](https://hupe1980.github.io/mako/docs/services/productd/#a-front-end-s-own-price-vertriebspreis)) |
| Sales front end → marktd | `GET /api/v1/partners?marktrolle=LF&name=` | Supplier candidates for the previous supplier the customer names; the customer picks the MP-ID |
| Sales front end → vertragd | `POST /api/v1/bestellungen` | The order, against the frozen offer |
| vertragd → sales front end | `de.mako.vertrag.*` CloudEvents | Lieferbeginn confirmed or refused, the Kündigung beim Vorversorger answered, a new supplier's Kündigung arrived, the Zuordnung ended, an Ersatzversorgung began |

### Webhook subscriptions

`mako_service::subscriptions` is the shared subscription module: a service that
mounts it serves these routes on its own port, each documented in its OpenAPI
document and each behind the Cedar action `manage-subscription` (the feed:
`read-events`).

| Route | Does |
|---|---|
| `POST /api/v1/webhooks/endpoints` | register an `https` endpoint with `event_types` patterns (`de.mako.vertrag.*`) and extension equality (`marktsparte`); the answer shows its `whsec_` secret once |
| `GET`/`PUT`/`DELETE /api/v1/webhooks/endpoints/{id}` | read (with `ETag`), replace or delete under `If-Match`; deleting cancels its pending deliveries |
| `POST …/{id}/rotate-secret` | a new secret; the previous one keeps signing for `overlap_hours` (≤ 168) |
| `POST …/{id}/test` | send `de.mako.webhook.test` now, signed like a delivery |
| `GET …/{id}/deliveries` | the delivery log, `status`, `last_status`, `latency_ms`, keyset-paged |
| `POST …/{id}/replay` · `POST /api/v1/webhooks/deliveries/{id}/replay` | queue a time window (also events that never had a delivery to the endpoint) or one delivery again |
| `GET /api/v1/events` | the service's outbox as a feed, in commit order, `type` pattern, keyset-paged |

A delivery carries `webhook-id` (the CloudEvent `id`, the deduplication key),
a per-attempt `webhook-timestamp` and one `v1,` signature per active secret,
computed with the key the `whsec_` secret encodes, as every Standard Webhooks
library does. Deliveries of one ordering key — the event's `subject`, unless
the emitter names another — reach an endpoint in commit order; other keys
never wait, and a dead-lettered delivery stops holding its key back. A
`410 Gone` deactivates the endpoint. An API endpoint naming a loopback,
private or link-local address, as written or as resolved at delivery, is
refused with `endpoint_url_not_allowed`; redirects are failures. The URL the
service's config names is the endpoint `default`: listed, delivered to and
replayable, and refused for writes with `endpoint_config_owned`. An
in-cluster receiver — another mako service, whose private address the API
refuses — is a `[[subscriptions.endpoints]]` entry (`name`, `url`, `secret`,
which may be `env:VAR`, `event_types`, `extensions`), config-owned the same way
and deactivated once the config drops it; the receiver registers nothing. A partner
credential sees only its own endpoints, and they receive only events whose
`vertriebspartner` extension names it. Events stay replayable for
`[subscriptions] retention_days` (default 30); older is `outside_retention`,
naming `oldest_replayable`.

Every type is `de.mako.<domain>.<fact>`, and a pattern has to match at least
one of them. An API registration with a pattern that matches none is refused
with `event_type_pattern_matches_nothing`, naming the patterns in `muster`; a
config endpoint with one blocks the boot. A stored endpoint keeps a pattern
that matches nothing and receives nothing for it: its read lists such patterns
as `patterns_matching_nothing`, and the service logs them at startup.

Every list answers `{items, next_cursor, total_estimate?}`: `limit` defaults
to 50 and above 200 is refused with `limit_too_large`, and a cursor carried to
another filter is refused with `cursor_invalid`. The types and the schema of
each type's `data` are in the [event catalog](https://hupe1980.github.io/mako/docs/reference/events/).

### ERP-facing integration topology

The services an ERP integration touches directly; the full mesh is in
[Service topology](https://hupe1980.github.io/mako/docs/architecture/#service-topology).

```mermaid
graph TB
    ERP["ERP System<br/>(SAP / Powercloud / custom)"]
    makod["makod :8080 / :4080<br/>EDIFACT ↔ AS4 · SlateDB<br/>GPKE / WiM / GeLi Gas / MABIS"]
    marktd["marktd :8180 · PostgreSQL<br/>MaLo/MeLo/contracts · Vertrag<br/>typed rubo4e::current API<br/>durable fan-out"]
    invoicd["invoicd :8280 · PostgreSQL<br/>INVOIC plausibility · REMADV<br/>§ 147 AO / GoBD receipts"]
    edmd["edmd :8380 · PostgreSQL<br/>Vec<Energiemenge> deliveries<br/>Lastgang · MeterBillingPeriod"]
    processd["processd :8580 · PostgreSQL<br/>NB STP `mako-pruefung`<br/>LF answers 55007 / 55010<br/>process projections · BNetzA KPI reports"]
    billingd["billingd :9280 · PostgreSQL<br/>energy billing · EN 16931<br/>XRechnung CII / PEPPOL UBL"]
    outputd["outputd :9880<br/>template store · ZUGFeRD PDF/A-3<br/>Textform proofs"]
    accountingd["accountingd :9380 · PostgreSQL<br/>double-entry ledger · Kontokorrent<br/>SEPA pain.008 / camt.05x"]

    ERP -->|"PUT /api/v1/malos/{id}<br/>PUT /api/v1/nb-contracts/{id}<br/>(typed BO4E payload)"| marktd
    ERP -->|"POST /api/v1/commands<br/>(initiate Lieferbeginn, …)"| makod
    ERP -->|"POST /receipts/{id}/confirm-payment"| invoicd

    makod -->|"de.mako.engine.process.*<br/>HMAC-signed CloudEvents"| marktd
    marktd -->|"fan-out<br/>de.mako.engine.* + de.mako.markt.*"| ERP
    marktd -->|"de.mako.engine.process.initiated"| invoicd
    marktd -->|"de.mako.engine.*"| processd
    marktd -->|"de.mako.engine.*"| edmd

    invoicd -->|"de.mako.invoic.receipt.settled/disputed<br/>de.mako.invoic.payment.overdue"| ERP
    invoicd -->|"gpke.abrechnung.annehmen/.ablehnen"| makod
    processd -->|"gpke.lieferbeginn.bestaetigen/.ablehnen<br/>geli.lieferbeginn.anmelden"| makod

    ERP -->|"GET /api/v1/deliveries/{malo_id}<br/>(Vec<Energiemenge>)"| edmd
    ERP -.->|"GET /obs/kpis<br/>GET /obs/overdue"| processd

    billingd -->|"render · pin template hash"| outputd
    billingd -->|"de.mako.billing.rechnung.erstellt"| accountingd
    ERP -.->|"GET /api/v1/offene-posten<br/>GET /api/v1/trial-balance"| accountingd
```

`marktd`'s fan-out is persist-before-fan-out: an event lands in its
`event_outbox` with the write that caused it, and each per-endpoint delivery is
tracked, retried and dead-lettered by the [webhook module](#webhook-subscriptions);
the other services receive it as config-owned endpoints.

### Delivery pipeline

```mermaid
graph TB
    H["Workflow::handle()"] --> WO["WorkflowOutput<br/>events + outbox_messages"]
    WO --> WB{{"single atomic WriteBatch<br/>SSI-isolated"}}
    WB --> ES[("EventStore")]
    WB --> OS[("OutboxStore")]
    OS --> EW["OutboxErpWorker<br/>polls every 5 s"]
    OS --> AW["OutboxWorker<br/>polls every 5 s, separate"]
    EW -->|"CloudEvents 1.0<br/>application/cloudevents+json"| ERP["ERP webhook"]
    AW -->|"EDIFACT"| AS4["AS4 sender"]
    AS4 --> CP["BDEW counterparty"]
```

Events and outbox entries land in one `WriteBatch`, so there is no state with
one and not the other. The two workers are independent: an ERP that is down
cannot delay an APERAK, and an unreachable counterparty cannot stall the ERP
feed.

#### The payload-key seam

An EDIFACT outbox entry carries a typed payload from `mako_engine::payload`
(`AperakPayload`, `UtilmdPayload`, …), so producer and renderer share one
struct, and the struct refuses a key it does not declare. An **ERP notification** entry is still a `message_type` string plus
JSON: a workflow writes
`PendingOutbox::new("GabiFinalAllocationOverdue", recipient, json!({…}))` and
`map_message_type_to_erp_event` (`services/makod/src/core/erp_adapter.rs`) reads
the string back to pick an `ErpEventType`. Keys inside `data` — `gas_day`,
`tx_id`, `zustimmung` — are a convention between writer and consumer.

`every_enqueued_message_type_maps_to_a_cloud_event` asserts that every
`message_type` a workflow enqueues resolves, and
`the_gabi_overdue_notification_carries_the_alocat_missing_type` pins the mapping
an agent subscribes to by name. **When you add an ERP message type, add it to
that list** — an unmapped type is delivered to nobody.

### PID → event mapping

| PID family | Process | CloudEvents `type` sequence |
|---|---|---|
| GPKE 55001 | Lieferbeginn LF-AN | `de.mako.engine.process.initiated` → `de.mako.engine.aperak.accepted` → `de.mako.engine.process.completed` |
| GPKE 55004 | Lieferende / Abmeldung (LFN → NB) | same |
| GPKE 55016 | Kündigung Lieferbeginn (LFN → LFA) | same |
| GPKE 31001–31005 | Abrechnung INVOIC | `de.mako.engine.process.initiated` → `de.mako.engine.process.completed` + `de.mako.invoic.receipt.settled`/`disputed` |
| WiM 31009 | MSB-Rechnung (LF payer) | `de.mako.engine.process.initiated` → REMADV → `de.mako.invoic.receipt.settled`/`disputed` |
| WiM 55039, 55042, 55051, 55168 | Gerätewechsel / MSB-Wechsel | `de.mako.engine.process.initiated` → `de.mako.engine.aperak.accepted` → `de.mako.engine.process.completed` |
| WiM 21029, 21030/21031 | Ersteinbau iMS, sending gMSB | `de.mako.engine.process.initiated` → `de.mako.engine.process.answered` on A02/A03/A04 → `de.mako.engine.process.completed` when all LF/NB notices are queued. A01 completes on receipt. |
| WiM 21029 | Ersteinbau iMS, receiving wMSB | `de.mako.engine.process.initiated` on receipt → `de.mako.engine.process.completed` when the wMSB queues its answer. |
| WiM 21029 | Ersteinbau iMS, receiving LF or NB | `de.mako.engine.process.completed` on receipt with `data.answer_context = "informational"`. |
| WiM 55168 (Konfiguration confirmed) | Steuerungsauftrag positive Endantwort | `de.mako.engine.process.completed` + **`de.mako.vpp.dispatch.confirmed`** → auto-billing in `billingd` |
| GeLi Gas 44001–44006 | Lieferbeginn Gas (LFN-initiated) | `de.mako.engine.process.initiated` → `de.mako.engine.aperak.accepted` → `de.mako.engine.process.completed` |
| GeLi Gas 44016–44018 | Kündigung Lieferbeginn Gas (LFN ↔ LFA) | same |
| GeLi Gas 17103 | Gas Datenabruf (Brennwert/Zustandszahl) | `de.mako.engine.process.initiated` → `de.mako.engine.process.completed` |
| GeLi Gas 17115, 17117 | Sperr-/Entsperrauftrag Gas (LF-initiated) | `de.mako.engine.process.initiated` → `de.mako.engine.process.completed` or `de.mako.engine.process.failed` |
| MABIS 13003 | Bilanzkreisabrechnung Strom | `de.mako.engine.process.initiated` → `de.mako.engine.process.completed` or `de.mako.engine.process.failed` |

For the iMS Ersteinbau, `data.answer_context` identifies the perspective. The gMSB expects the answer. Only the addressed wMSB owes it, with a three-Werktage deadline measured from receipt. To answer through makod, take the `melo_id` and original `market_reference` (BGM, CNI, sender and receiver with roles, direction and PID) from the initiation event. `own_mp_id` identifies the addressed local party. WiM Strom Teil 1, Kap. 3.5.2 Nr. 1–4, pp. 61–64 and IFTSTA AHB 2.1, Kap. 6.7, pp. 32–34.

### `invoicd` payment CloudEvents

After each checked INVOIC, `invoicd` posts payment CloudEvents to the ERP when
`[erp] webhook_url` is set in `invoicd.toml`.

| Type | Trigger | Use case |
|---|---|---|
| `de.mako.invoic.receipt.settled` | Invoice accepted | Book received invoice |
| `de.mako.invoic.receipt.disputed` | Invoice rejected | Flag for manual review |

The `dispatched` field says whether the market answer went out — do not pay
against a settled invoice whose REMADV never left.

Payment events use `source: "urn:mako:invoicd:tenant:{tenant}"` and `subject: "{process_id}"`.

**Durable at-least-once.** The event is enqueued in `event_outbox` with the
receipt's dispatch stamp and delivered to the endpoint `default`
(`[erp] webhook_url`) and every other matching endpoint by the
[webhook module](#webhook-subscriptions); a dead-lettered delivery shows in
`GET /api/v1/webhooks/endpoints/{id}/deliveries?status=failed`.

**Request signing:** when `[erp] webhook_secret` or `webhook_secret_file` is configured, every POST includes
[Standard Webhooks] headers computed over `{webhook-id}.{webhook-timestamp}.{body}`.

### CloudEvents envelope schema

**Required CloudEvents attributes:**

| Attribute | Value | Notes |
|---|---|---|
| `specversion` | `"1.0"` | Always |
| `id` | `<idempotency_key>` | Stable dedup key — persist in ERP |
| `source` | `"urn:mako:makod:tenant:<tenant_id>"` | Operator MP-ID |
| `type` | `"de.mako.<domain>.<action>"` | See event type table below |
| `time` | RFC 3339 with timezone offset | Wall-clock time of domain event |
| `subject` | `<process_id>` UUID | The mako process that fired the event |

**Optional CloudEvents attributes:**

| Attribute | Value | Notes |
|---|---|---|
| `dataschema` | BO4E JSON Schema URL | Present when `data` carries a BO4E object |
| `datacontenttype` | `"application/json"` | Always present when `data` is non-null |

**mako extension attributes** (lowercase alphanumeric per CloudEvents spec §3.3):

| Extension | Type | Description |
|---|---|---|
| `makoconvid` | string | BDEW Vorgangsnummer |
| `makocausationid` | string | mako domain event UUID that caused this notification |
| `makopid` | integer | Prüfidentifikator |
| `makofailreason` | string | Only present on `de.mako.engine.process.failed` |
| `makoakteur` | string | The process's most human actor up to the causing event: `system`, `freigabe`, `freigabe-geaendert` or `person` — the class only, never the principal |

**`data` field:**

A BO4E object, or the notice's own fields where none applies (the APERAK, CONTRL and failure notices).

**Event type → CloudEvents `type` mapping:**

| CloudEvents `type` | Trigger | Primary BO4E payload |
|---|---|---|
| `de.mako.engine.process.initiated` | New inbound UTILMD received | `Marktlokation` |
| `de.mako.engine.aperak.accepted` | A counterparty's APERAK Anerkennungsmeldung arrived — written by the ingest door for every received APERAK; an APERAK carries no Prüfidentifikator and is never routed to a workflow, `pid` 29002 here only labels the Ausprägung | `{pid, message_ref, bezug_message_ref, sender, receiver, process_resolved}`; `bezug_message_ref` (`RFF+ACE`, else `RFF+ACW`) names our message. When `RFF+ACE`, `RFF+TN` or `RFF+ACW` is a correlation key of exactly one process, the event stands under that process (`process_resolved: true`); otherwise under a process id of its own |
| `de.mako.engine.aperak.rejected` | A counterparty's APERAK Fehlermeldung (29001, or one naming an `ERC`) arrived | as `aperak.accepted`, plus `error_code` (the first `ERC`, also in `makoerc`) |
| `de.mako.engine.antwortfrist.abgelaufen` | The counterparty let the business Antwortfrist lapse | `Marktlokation` |
| `de.mako.engine.contrl.received` | A counterparty's CONTRL arrived | `{message_ref, interchange_ref, accepted, action_code, sender, receiver, process_resolved}`; `accepted` is `UCI` DE 0083 = `7` „Übertragung bestätigt", `4` is the rejection (CONTRL MIG 2.0b, UCI); attached to a process as the APERAK is, from the `UCI` interchange reference or a `UCM` message reference |
| `de.mako.engine.process.answered` | The gMSB received a decision and still owes its LF/NB notices. | MeLo, peer MP-ID, `answer_context`, `antwortcode` and `codeliste`. [Event schema](https://hupe1980.github.io/mako/schemas/events/de.mako.engine.process.answered.json) |
| `de.mako.engine.process.completed` | A process ended on an answer — Bestätigung **or** Ablehnung. Read the verdict, never the type: `data.accepted`, `data.outcome` (`"accepted"` / `"rejected"`) and the response PID in `makopid` (`check-process-verdict` refuses a consumer that reads none). `data.antwortcode` / `data.codeliste` carry the answer's code | `Marktlokation` + `Vertrag` |
| `de.mako.engine.process.failed` | A Marktnachricht of the process was given up — its delivery budget ran out or the failure is permanent — so the counterparty never received it | `{reason, undelivered_message_id, undelivered_message_type, recipient, pid?}`; `reason` is also `makofailreason` |
| `de.mako.engine.malo.identified` | MaLo-ID lookup resolved | `Marktlokation` |
| `de.mako.engine.abmeldeanfrage.beantwortet` | The LFA answered the NB's Anfrage zur Beendigung der Zuordnung (55010/55011/55012), or its 09:00 window lapsed — a Zustimmung per GPKE Teil 2 Kap. 2.1.2 Nr. 4. `processd` resumes the Anmeldung decision on it | `{pid, malo_id, grid_operator, lfa_mp_id, anmeldung_process_id, zustimmung, fristablauf}` plus `antwortcode`, `grund` and `zuordnungsende` when the LFA named them |
| `de.mako.engine.dead-letter.recorded` | A message went to the dead-letter queue — an inbound one the door could not route or process, or an outbound one whose delivery budget ran out. Written in the same transaction as the record, so each record yields one; a notice that itself exhausts its budget is recorded without another | `{dead_letter_id, reason, detail, rejected_at}` plus `pid`, `message_ref`, `message_type`, `sender`, `receiver` where the message named them |
| `de.mako.vpp.dispatch.confirmed` | MSB positively confirmed a WiM Steuerungsauftrag (PID 55168) of type `Konfiguration` — triggers VPP auto-billing in `billingd` | `{tx_id, location_id, location_type, max_power_kw, execution_time_from, execution_time_until, command_type, sender_mp_id, produkt_code}` |
| `de.mako.gabi.alocat.missing` | The § 47 Ziffer 1 KoV XV final-allocation window (M+14 Werktage) closed with no final ALOCAT on file; open a Clearingfall with the FNB/MGV | `{gas_day, deadline_label, sender_eic, receiver_eic, pruefidentifikator}` |
| `de.mako.gabi.nomination.curtailed` | The FNB/MGV confirmed less than was nominated; the portfolio is short until the BKV re-nominates or buys the gap | `{gas_day, nominated_kwh, confirmed_kwh, curtailed_kwh, sender_eic, receiver_eic, pruefidentifikator, nomination_ref}` |
| `de.mako.gabi.nomination.rejected` | The FNB/MGV refused the nomination; nothing flows on it | `{gas_day, reason, nominated_kwh, sender_eic, receiver_eic, pruefidentifikator, nomination_ref}` |
| `de.mako.gabi.nomres.missing` | The KoV NOMRES window closed unanswered, so the nomination's status is unknown at gas-day start | `{gas_day, deadline_label, sender_eic, receiver_eic, pruefidentifikator, nomination_ref}` |

### Retry and back-off

`OutboxErpWorker` retries with exponential back-off:

| Attempt | Delay |
|---|---|
| 1st failure | 5 min |
| 2nd failure | 10 min |
| 3rd failure | 20 min |
| 4th failure | 40 min |
| 5th+ failure | 60 min (capped) |
| After 10 failures | Dead-lettered; `WARN` logged |

HTTP response codes:

| Code | Interpretation |
|---|---|
| `2xx` | Success — message acknowledged |
| `4xx` except `429` | Permanent error — message dead-lettered immediately |
| `429` | Transient — rescheduled with back-off |
| `5xx` | Transient — rescheduled with back-off |
| Network timeout / error | Transient — rescheduled with back-off |

### No-secret mode

Without `--erp-webhook-secret` all three Standard Webhooks headers are omitted
(`mako_service::webhook::headers` produces them as a set); dedup on
`X-Idempotency-Key`. Use this only in local development.

### `LogErpAdapter` (development / logging only)

Without `--erp-webhook-url`, `makod` uses `LogErpAdapter`, which logs every
event at `INFO`:

```
INFO mako::erp: ErpAdapter: event logged (no delivery configured)
    idempotency_key=01932a4f-...
    event_type=aperak_accepted   ← short label for structured logs/metrics
    process_id=018f3a2b-...
    tenant_id=9900357000004
    pid=55001
```

`event_type` is `ErpEventType::label()`, the snake_case key for logs and
metrics; the wire `type` is set only by `WebhookErpAdapter`.

---

## Inbound: ERP initiates a MaKo process

### REST (`POST /api/v1/commands`)

A **command envelope** carries the dotted command name, the issuing
Marktrolle and a command-specific `payload`; `makod` resolves the PID. Most
GPKE/GeLi commands need only the MaLo-ID and the process date — NB, MSB and
MeLo come from the master-data cache:

```http
POST /api/v1/commands
Content-Type: application/json
Idempotency-Key: erp-order-991234
Authorization: Bearer <token>

{
  "command": "gpke.lieferbeginn.anmelden",
  "marktrolle": "LF",
  "payload": {
    "malo_id":            "51238696799",
    "lieferbeginn_datum": "2026-10-01",
    "transaktionsgrund":  "E03",
    "bilanzkreis":        "11XBK-STD------Y",
    "haushaltskunde":     true,
    "enfg_grundlage":     "ZG1",
    "kunde": {
      "nachname": "Mustermann",
      "anschrift": { "strasse": "Hauptstraße", "hausnummer": "1",
                     "postleitzahl": "50667", "ort": "Köln", "landescode": "DE" }
    }
  }
}
```

The payload carries the facts of the Lieferant's contract the Anmeldung makes
Muss — for a 55001 the `SG4 STS+7` Transaktionsgrund, the Bilanzkreis and the
Kunde (UTILMD AHB Strom 2.2 Kap. 8.2); `makod` reads it as a typed body and
refuses a missing one or a key it does not declare.

`marktrolle` is required only for a command more than one role may issue (such
as `invoic.nne.stellen`, permitted for `NB` and `GNB`); for a single-role
command it is inferred from the name. Never include
`sender_party_id`, `receiver_party_id`, `pruefidentifikator` or `message_ref` —
those are engine-owned.

A **billing** command names the invoice by `invoice_ref` — the
`rechnungsnummer` the counterparty's REMADV correlates on — and carries the
BO4E `Rechnung` beside it:

```json
{
  "command": "invoic.nne.stellen",
  "marktrolle": "NB",
  "payload": {
    "invoice_ref":     "NN-2026-000123",
    "sender_mp_id":    "9900357000004",
    "recipient_mp_id": "9900357000011",
    "rechnung": {
      "_typ": "RECHNUNG",
      "_version": "202607.1.0",
      "rechnungsnummer": "NN-2026-000123",
      "gesamtnetto":  { "_typ": "BETRAG", "wert": "300.00", "waehrung": "EUR" },
      "gesamtsteuer": { "_typ": "BETRAG", "wert": "57.00",  "waehrung": "EUR" },
      "gesamtbrutto": { "_typ": "BETRAG", "wert": "357.00", "waehrung": "EUR" }
    }
  }
}
```

`_version` is optional and spelt without a `v` (`202607.1.0`); mako reads the
series (`202607`), so a producer one patch ahead is accepted.

**Response** — `202 Accepted`:

```json
{
  "idempotency_key": "erp-order-991234",
  "command": "gpke.lieferbeginn.anmelden",
  "marktrolle": "LF",
  "status": "accepted",
  "process_id": "018f3a2b-..."
}
```

#### What `Idempotency-Key` does

The header is **required** (`422 missing_idempotency_key` without it). Use one
stable value per business request — your ERP order or correlation ID. `makod`
stores the accepted response for **24 hours** and replays it verbatim on a
retry, with no second dispatch. The same key with a *different* command or
payload is `422 idempotency_key_reuse`.

```json
// 422 — the key already belongs to a different request.
{ "error": "Unprocessable Entity", "code": "idempotency_key_reuse", "detail": "…" }
```

A storage failure on the lookup is `503 idempotency_unavailable` — retry.

Beneath the key sits the business-level guard: a second `anmelden` while a
process is active for the same business key is `409 duplicate_process` even
under a fresh key, carrying the existing `process_id`. **Treat it as success**
and adopt the `process_id`. The other 409, `invalid_state`, is a real error and
carries none. Branch on `code`: `error` is the HTTP reason phrase.

```json
// 409 — your retry already succeeded. Adopt the process_id.
{ "error": "Conflict", "code": "duplicate_process", "detail": "…", "malo_id": "51238696799", "process_id": "018f3a2b-..." }

// 409 — genuine rejection. Do not retry.
{ "error": "Conflict", "code": "invalid_state", "detail": "cannot bestaetigen a process in state Abgeschlossen" }
```

The guard covers a **running** process of the same family only, decided from
the process's replayed state: a rejected Anmeldung does not block the corrected
one, an executed Sperrung does not block the Entsperrung, and a process of a
different family on the same MaLo is allowed. Derive keys from the business
event (MaLo *and* process date), not the MaLo alone.

The `command` name selects the process and its PID; a BO4E `_typ` in the
payload selects nothing.

---

## MaLo master data cache

`makod` answers `POST /maloId/request/v1` (BDEW API-Webdienste Strom) from a
local cache; the ERP is the authoritative master. The body wraps a BDEW
`MaloIdentResultPositive` (the `energy-api` model):

```http
PUT /admin/malo/51238696799
Authorization: Bearer <token>
Content-Type: application/json

{
  "result": { "dataMarketLocation": { "maloId": "51238696799", … }, … },
  "valid_from": "2026-10-01",
  "source": "erp-sync"
}
```

Push it on contract activation, address change, contract end and every grid
assignment change — a wrong grid operator is a common cause of APERAK
rejections.

### Cache admin

```http
GET    /admin/malo/stats            ← record count + last-upsert timestamp per tenant
DELETE /admin/malo/51238696799      ← remove on contract end
```

---

## Trading-partner directory

```http
PUT /admin/partners/9900000000001
Authorization: Bearer <token>
Content-Type: application/json

{
  "mp_id": "9900000000001",
  "display_name": "Stadtwerke Beispiel GmbH",
  "channels": [
    { "qualifier": "AK", "address": "https://partner.example/as4/inbox" }
  ],
  "roles": ["NB"]
}
```

Or bulk-import from a PARTIN EDIFACT interchange:

```http
POST /admin/partners/import
Authorization: Bearer <token>
Content-Type: text/plain; charset=utf-8

<raw PARTIN interchange>
```

---

## Receiving CloudEvents — ERP implementation guide

Verify the body before parsing it. Check that the authenticated message ID
equals the CloudEvent ID, then claim the ID and apply the event in one database
transaction. A duplicate returns success. A failed handler rolls back the claim
so makod can retry. For an external side effect, insert an outbox row in that
transaction and deliver it with the event ID as its idempotency key.

The examples use the [deduplication table](#idempotency-implementation-notes)
below. Supply your ERP's database pool and an `apply_event` or `applyEvent`
function that uses the supplied connection for all its writes. For example,
`de.mako.engine.process.completed` carries the supplier's decision in
`data.accepted`.

### Python (FastAPI)

Use `standardwebhooks`, FastAPI and an `asyncpg` pool. [Python SDK](https://pypi.org/project/standardwebhooks/)

```python
import os
from fastapi import FastAPI, HTTPException, Request
from standardwebhooks.webhooks import Webhook, WebhookVerificationError
from erp import apply_event, pool

app = FastAPI()
webhook = Webhook(os.environ["MAKOD_ERP_WEBHOOK_SECRET"])

@app.post("/mako/events")
async def receive(request: Request):
    body = await request.body()
    try:
        event = webhook.verify(body, dict(request.headers))
    except (WebhookVerificationError, ValueError):
        raise HTTPException(status_code=401, detail="Invalid webhook")

    msg_id = request.headers["webhook-id"]
    if (not isinstance(event, dict) or event.get("id") != msg_id
            or not isinstance(event.get("type"), str)):
        raise HTTPException(status_code=400, detail="Invalid CloudEvent")

    async with pool.acquire() as conn, conn.transaction():
        claimed = await conn.fetchval(
            "INSERT INTO mako_webhook_dedup (id, type) VALUES ($1, $2) "
            "ON CONFLICT (id) DO NOTHING RETURNING id", msg_id, event["type"]
        )
        if claimed is not None:
            await apply_event(conn, event)
    return {"ok": True}
```

### TypeScript / Node.js (Express)

Use `standardwebhooks`, Express 5 and a `pg` pool. Mount this route before any
JSON body parser. [JavaScript SDK](https://github.com/standard-webhooks/standard-webhooks/tree/main/libraries/javascript)

```typescript
import express from "express";
import { Webhook } from "standardwebhooks";
import { applyEvent, pool } from "./erp.js";

const app = express();
const webhook = new Webhook(process.env.MAKOD_ERP_WEBHOOK_SECRET!);

app.post("/mako/events", express.raw({ type: "application/cloudevents+json" }),
  async (req, res) => {
    const id = req.get("webhook-id") ?? "";
    let event: unknown;
    try {
      event = webhook.verify(req.body, {
        "webhook-id": id,
        "webhook-timestamp": req.get("webhook-timestamp") ?? "",
        "webhook-signature": req.get("webhook-signature") ?? "",
      });
    } catch {
      return res.sendStatus(401);
    }
    if (!event || typeof event !== "object" || !("id" in event) || event.id !== id
        || !("type" in event) || typeof event.type !== "string") {
      return res.sendStatus(400);
    }

    const conn = await pool.connect();
    try {
      await conn.query("BEGIN");
      const claim = await conn.query(
        "INSERT INTO mako_webhook_dedup (id, type) VALUES ($1, $2) " +
        "ON CONFLICT (id) DO NOTHING RETURNING id", [id, event.type]);
      if (claim.rowCount === 1) await applyEvent(conn, event);
      await conn.query("COMMIT");
    } catch (err) {
      await conn.query("ROLLBACK");
      throw err;
    } finally {
      conn.release();
    }
    return res.json({ ok: true });
  }
);
```

---

## Idempotency implementation notes

Create the receiver's table once. Keep its entries for the full period in
which an event can be replayed, including operator-triggered replays.

```sql
CREATE TABLE mako_webhook_dedup (
  id          TEXT PRIMARY KEY,
  type        TEXT NOT NULL,
  received_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
```

---

## Writing a custom `ErpAdapter`

For mTLS, a message-bus sink or an ERP SDK, implement the trait:

```rust
use mako_engine::erp::{ErpAdapter, ErpAdapterError, ErpEvent};

struct MySapAdapter { client: SapHttpClient }

impl ErpAdapter for MySapAdapter {
    async fn notify(&self, event: ErpEvent) -> Result<(), ErpAdapterError> {
        // event.payload contains the BO4E object (same as CloudEvents `data`).
        let malo: MyMalo = serde_json::from_value(event.payload)
            .map_err(ErpAdapterError::payload)?;

        // event.idempotency_key = CloudEvents `id` — use for dedup.
        self.client
            .post_event(&event.idempotency_key, malo.id, event.event_type.label())
            .await
            .map_err(|e| {
                if e.is_retryable() {
                    ErpAdapterError::transport(e)
                } else {
                    ErpAdapterError::permanent(e)
                }
            })
    }
}
```

Wire it in `services/makod/src/core/erp_adapter.rs` beside `WebhookErpAdapter`.

### Error classification contract

| Return | Worker behaviour |
|---|---|
| `Ok(())` | Acknowledged — removed from outbox |
| `Err(ErpAdapterError::Transport(_))` | Retried with exponential back-off |
| `Err(ErpAdapterError::Permanent(_))` | Dead-lettered immediately |
| `Err(ErpAdapterError::Payload(_))` | Dead-lettered immediately |

---

## Configuration reference

| CLI flag | Env var | TOML key | Default | Description |
|---|---|---|---|---|
| `--erp-webhook-url` | `MAKOD_ERP_WEBHOOK_URL` | `erp.webhook_url` | — | ERP endpoint URL (enables HTTP delivery) |
| `--erp-webhook-secret` | `MAKOD_ERP_WEBHOOK_SECRET` | `erp.webhook_secret` | — | HMAC-SHA256 signing key |

`makod.toml` example:

```toml
[erp]
webhook_url    = "https://erp.internal/mako/events"
webhook_secret_file = "/run/secrets/erp-webhook"
```

---

## Testing

`mako-engine`'s `testing` feature provides `NoopErpAdapter`, which succeeds
without delivering; `LogErpAdapter` (logs at `INFO`) is always available. After a `Process::run`,
assert on `InMemoryOutboxStore::pending_now` for the ERP-targeted entry.

---

## Why BO4E (not EDIFACT)

[BO4E](https://www.bo4e.de/) is the open German standard for energy-market
data models, with MIT-licensed implementations for Python, C#, Go, Kotlin,
TypeScript and PHP. `makod` absorbs EDIFACT format changes; the ERP receives
`Marktlokation.marktlokationsId` directly and dispatches on reverse-DNS
CloudEvents types. The BO4E schema tag is `v202607.1.0`; a payload's
`_version` is `202607.1.0` and dispatch keys on the series `202607`.

---

## The integration surface

| Component | Where | Role |
|---|---|---|
| `ErpAdapter` trait / `ErpEvent` | `mako-engine/src/erp.rs` | Outbound event contract |
| `ErpEventType` | `mako-engine/src/erp.rs` | Domain outcome with a stable log and metric label |
| `WebhookErpAdapter` (HMAC-SHA256 signed) | `makod/src/core/erp_adapter.rs` | Maps outcomes to `mako-events` types and sends signed SDK CloudEvents to the ERP webhook |
| `OutboxErpWorker` (exponential back-off) | `makod/src/core/erp_adapter.rs` | At-least-once delivery with retry + dead-letter |
| `POST /api/v1/commands` | `makod/src/orchestrator/commands_api/` | ERP-initiated process commands |
| `PUT /admin/malo/{malo_id}` · `PUT /admin/partners/{mp_id}` | `makod` | Master-data cache sync |
| BO4E typed model (`rubo4e`) | workspace dependency | `rubo4e = "0.15"`, BO4E schema v202607.1.0; typed BOs at every API boundary, strict-decoded on ingest (`Bo4eStrict::ensure_known_enums`) and checked against BO4E's own rules (`.validate()`) |

---

## Related documentation

| Topic | File |
|---|---|
| `makod` operator reference | [makod](https://hupe1980.github.io/mako/docs/services/makod/) |
| `marktd` operator reference | [marktd](https://hupe1980.github.io/mako/docs/services/marktd/) |
| `invoicd` operator guide | [invoicd](https://hupe1980.github.io/mako/docs/services/invoicd/) |
| `edmd` operator guide | [edmd](https://hupe1980.github.io/mako/docs/services/edmd/) |
| process read model (KPIs, § 7a Abs. 5 EnWG) | [processd](https://hupe1980.github.io/mako/docs/services/processd/#process-read-model) |
| Engine architecture | [Engine](https://hupe1980.github.io/mako/docs/architecture/engine/) |
| API-Webdienste Strom (MaLo-ID) | [API-Webdienste](https://hupe1980.github.io/mako/docs/architecture/api-webdienste/) |
| Annual release workflow | [Annual release workflow](https://hupe1980.github.io/mako/docs/compliance/annual-release-workflow/) |

---

## Automated Billing Settlement

[`invoicd`](https://hupe1980.github.io/mako/docs/services/invoicd/) checks every received INVOIC — ten
PIDs across four answer-command families: `gpke.abrechnung.*` (31001, 31002,
31005, 31006), `wim.rechnung.*` (31003, 31009), `gabi.rechnung.*` (31007,
31008), and `invoic.*` for the 31004 Stornorechnung and the 31011 Rechnung
sonstige Leistung. It subscribes to
`de.mako.engine.process.initiated` from `marktd`, runs `invoic-checker`, persists the
receipt (a Buchungsbeleg — § 147 Abs. 3 AO / § 14b UStG) and issues the
settlement command without ERP involvement.

### Full billing flow

```
NB (counterparty)
    │  INVOIC (one of the ten routed PIDs; 31001/31002/31005/31006 shown)
    │  AS4/EDIFACT push
    ▼
makod :8080
    │  GpkeAbrechnungWorkflow.handle(ReceiveInvoic)
    │  emits: de.mako.engine.process.initiated
    │  outbox: invoice_ref, Rechnung BO4E object
    ▼
marktd :8180
    │  fan-out to registered subscribers
    ▼
invoicd :8280
    │  InvoicCheckEngine::check(tariff_store, check_config, &rechnung)
    │  upsert_receipt(pool, row)  ← persist to PostgreSQL BEFORE dispatching
    │
    ├─ no dispute findings ──► POST /api/v1/commands
    │                              {"command": "gpke.abrechnung.annehmen",
    │                               "payload": {"invoice_ref": "..."}}
    │                              ↓  mark_dispatched(pool, process_id)
    │                          makod emits REMADV 33001 (Zahlungsavis)
    │                          AS4 → NB
    │
    └─ dispute findings ─────► POST /api/v1/commands
                                   {"command": "gpke.abrechnung.ablehnen",
                                    "payload": {"invoice_ref": "...",
                                                "ablehnungsgrund": "..."}}
                                   ↓  mark_dispatched(pool, process_id)
                               makod emits REMADV 33002 — or 33003/33004
                               when the tree answers positionsscharf
                               AS4 → NB
```

**Settlement is „ganz oder gar nicht".** REMADV AHB 1.0a Kap. 3 admits no
Teilzahlung: only **33001** confirms; 33002 refuses with one code (Kap. 3.1.1),
33003 („Abweisung Kopf und Summe") and 33004 („Abweisung Position") carry one
code per disputed position (Kap. 3.1.2). `RemadvAntwort::remadv_pid` picks from the
shape of the decision tree's answer.

COMDIS **29001** is the invoicer's refusal of a payer's REMADV (COMDIS AHB 1.0)
and not part of this flow; APERAK uses the same number for a different message.

### The plausibility pipeline

`InvoicCheckEngine::check` runs eight stages in a fixed order, plus one for a
single PID, each appending to one `Vec<Finding>`:

| # | Stage | What it verifies |
|---|---|---|
| 1 | Storno reference | `ist_storno = true` must name the original in `original_rechnungsnummer`. Source: INVOIC AHB 1.0b Kap. 3.1.2 (S. 29) — `SG1 RFF+OI` is Muss on the Stornorechnung 31004 |
| 2 | Period validity | `rechnungsperiode.startdatum` ≤ `enddatum`; line-item periods via `lieferungszeitraum` |
| 3 | Zahlungsziel | `faelligkeitsdatum` is not before `rechnungsdatum` (dispute); on PIDs 31001–31003 and 31009 with a fälliger Betrag ≥ 0 it lies at least 10 Werktage after the receipt (dispute, `E_0406` `A10`; GPKE Teil 2 Kap. 3.3.2 Nr. 1, S. 90; GeLi Gas 3.0 Kap. 4.5); the INVOIC AHB 1.0b bounds `[24]`/`[25]` as in [invoicd](https://hupe1980.github.io/mako/docs/services/invoicd/); `max_zahlungsziel_days` warns only when set |
| 3a | WiM 31003 send window | Strom equipment rental compares the Berlin date of the original receipt with the 20th Werktag after the billed period (WiM Teil 1 ch. 3.7.2 no. 1, pp. 80–81). A missing service trigger or sector produces a procedural warning. Both warnings carry the same weight at every invoice value |
| 4 | Currency agreement | Runs **before** the arithmetic, so a CHF `Betrag` is not compared as EUR |
| 5 | Position arithmetic | `position.positions_menge × einzelpreis` ≈ `gesamtpreis` (within `arithmetic_tolerance`) |
| 6 | Document total | Sum of `rechnungspositionen[*].gesamtpreis` ≈ `gesamtnetto` (within `total_tolerance`) |
| 7 | Umsatzsteuer | The per-rate `steuerbetraege` breakdown sums to `gesamtsteuer` — the figure the recipient's Vorsteuerabzug is computed from |
| 8 | Tariff match | Each position's unit price falls within the registered tariff band ± `tariff_tolerance`; a missing tariff entry for the MaLo + period is a finding whose severity follows `require_tariff` |

Stage 3 compares **calendar dates** in the offset the payload carries
(`rechnungsdatum_date()`, `faelligkeitsdatum_date()`), not timestamps. Stage 8
is skipped for a Stornorechnung, which carries negated amounts rather than
tariff positions. Beside the pipeline, `check_mmm_settlement` prices MMM
invoices (31005–31008) against the MMMA reference prices in `marktd`, and
`check_msb_rechnung` / `check_esa_rechnung` price a WiM or ESA invoice against
a `PreisblattMessung` or the accepted Angebot.

### Payment deadline tracking (`pay_by`)

`invoicd` extracts the `faelligkeitsdatum` from each `Rechnung` and stores it as
`pay_by TIMESTAMPTZ` in `invoic_receipts`.

**Approaching REMADV deadline** — `GET /api/v1/overdue-remadv` lists receipts
with `pay_by < now() + 3 days` and no REMADV dispatched:

```http
GET http://invoicd:8280/api/v1/overdue-remadv
Authorization: Bearer ${TOKEN}
```

**Overdue payment** — the `payment_overdue` worker (every 6 h) emits
`de.mako.invoic.payment.overdue` when `pay_by` passes without a payment
confirmation:

```json
{
  "type":    "de.mako.invoic.payment.overdue",
  "data":    { "receipt_id": "...", "malo_id": "...", "pay_by": "2026-10-15" }
}
```

**Payment confirmation** — when the bank transfer clears, POST to close the
§ 147 AO / GoBD audit trail:

```http
POST http://invoicd:8280/api/v1/receipts/{id}/confirm-payment
```

### Tariff seeding

Price sheets (`PreisblattNetznutzung`) live in `marktd`:

```bash
curl -X PUT http://marktd:8180/api/v1/preisblaetter/9904234560001 \
  -H "Authorization: Bearer ${TOKEN}" \
  -H "Content-Type: application/json" \
  -d @preisblatt_netznutzung.json   # rubo4e::current::PreisblattNetznutzung (BO4E v202607)
```

`invoicd` fetches it at check time (1-hour TTL cache, circuit breaker: 3
failures → 30 s open). The ERP's part is uploading price sheets when rates
change and consuming `de.mako.engine.process.completed` / `de.mako.engine.process.failed`;
the settlement decision needs no ERP response.
