Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .roave-backward-compatibility-check.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
<!-- Die Rector-Regeln erben von Rectors gescopter PHAR-Klasse, die BetterReflection nicht findet.
Sie sind Upgrade-Werkzeug, keine Laufzeit-API. -->
<ignored-regex>#"Rector\\Rector\\AbstractRector" could not be found in the located source#</ignored-regex>
<!-- Neue Felder generierter Models/Options landen vor den Schluss-Parametern `$extra` (Models) bzw.
`$items` (Create-Options). Das Tool vergleicht Parameter nach Position und meldet deshalb eine
Typänderung von `$extra`/`$items`. Die Reihenfolge der Konstruktor-Parameter ist laut
docs/concepts/backward-compatibility.md nicht Teil des Versprechens (benannte Argumente);
Name und Typ von `$extra`/`$items` selbst bleiben gleich. Freigegeben am 2026-11-22 (#102). -->
<ignored-regex>#\[BC\] CHANGED: (Default parameter value for parameter|The parameter) \$(extra|items) of Justpilot\\Billomat\\(Model|Api)\\\w+\#__construct\(\) changed from array#</ignored-regex>
</baseline>
</roave-bc-check>
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ When adding a new resource, add it as a lazy property hook on `BillomatClient` (

### Sub-resources

Items, payments, comments, tags, properties and property values hang off their parent `*Api` as lazy property hooks (`public private(set) CommentsApi $comments { get => $this->comments ??= new CommentsApi(...); }`), not on `BillomatClient`. They use one generic class per kind — `CommentsApi`, `TagsApi`, `ItemsApi`, `PaymentsApi`, `PropertiesApi`, `PropertyValuesApi` — extending `AbstractSubResourceApi`, which derives path, envelope keys and parent filter from the parent slug (`'credit-note'` → `/credit-note-comments`, `credit-note-comment`, `credit_note_id`). The property's `@var` carries the `@template` types; the constructor gets the hydrator, the expected `*CreateOptions` class (checked at runtime, the native type is only `WriteOptions`; `ItemsApi` also gets the `*ItemUpdateOptions` class for `update()`) for payments and property values the expected `*Filter` class and for comments the `*CommentActionKey` enum. Methods are uniform: `list()`/`listPage()`/`iterateAll()` take `int $parentId` (payments/property values: `?int $parentId = null`) plus `$filters` — the generated `*PaymentFilter`/`*PropertyValueFilter`, the handwritten `CommentFilter` (action keys, checked against the resource's `*CommentActionKey`), otherwise the handwritten `SubResourceFilter` (sorting and pagination only) — or an array; `create(int $parentId, $options)` adds the parent field to the payload (the parent ID is never a field of the create options); `get()`, `update()`, `delete(): void`. Sub-resources that don't fit (`ReminderItemsApi`, `RecurringEmailReceiversApi`) are small classes on the same base. `ContactsApi` (`$billomat->clients->contacts`) extends `AbstractApi` directly because Billomat's path is `/contacts`, not `/client-contacts`, but has the same signatures (`list(int $parentId, SubResourceFilter|array $filters)`, `create(int $parentId, ContactCreateOptions $options)`).
Items, payments, comments, tags, properties and property values hang off their parent `*Api` as lazy property hooks (`public private(set) CommentsApi $comments { get => $this->comments ??= new CommentsApi(...); }`), not on `BillomatClient`. They use one generic class per kind — `CommentsApi`, `TagsApi`, `ItemsApi`, `PaymentsApi`, `PropertiesApi`, `PropertyValuesApi` — extending `AbstractSubResourceApi`, which derives path, envelope keys and parent filter from the parent slug (`'credit-note'` → `/credit-note-comments`, `credit-note-comment`, `credit_note_id`). The property's `@var` carries the `@template` types; the constructor gets the hydrator, the expected `*CreateOptions` class (checked at runtime, the native type is only `WriteOptions`; `ItemsApi` also gets the `*ItemUpdateOptions` class for `update()`) for payments and property values the expected `*Filter` class and for comments the `*CommentActionKey` enum. Methods are uniform: `list()`/`listPage()`/`iterateAll()` take `int $parentId` (payments/property values: `?int $parentId = null`) plus `$filters` — the generated `*PaymentFilter`/`*PropertyValueFilter`, the handwritten `CommentFilter` (action keys, checked against the resource's `*CommentActionKey`), otherwise the handwritten `SubResourceFilter` (sorting and pagination only) — or an array; `create(int $parentId, $options)` adds the parent field to the payload (the parent ID is never a field of the create options); `get()`, `update()`, `delete(): void`. Sub-resources that don't fit (`ReminderItemsApi`, `RecurringEmailReceiversApi`) are small classes on the same base. `ContactsApi` (`$billomat->clients->contacts`) extends `AbstractApi` directly because Billomat's path is `/contacts`, not `/client-contacts`, but has the same signatures (`list(int $parentId, SubResourceFilter|array $filters)`, `create(int $parentId, ContactCreateOptions $options)`). `ClientDeliveryAddressesApi` (`$billomat->clients->deliveryAddresses`, `/client-delivery-addresses`) follows the same pattern.


### Generated code

Some model/options classes are generated by `tools/generate.php` from `docs/spec/billomat.json` plus a per-resource definition in `tools/codegen/definitions/` (currently Clients, Contacts, Suppliers, Articles, Taxes, Templates, Invoices, Offers, Credit Notes, Recurrings, Letters, Reminders, Delivery Notes, Confirmations and Incomings → `Client`, `Contact`, `Supplier`, `Article`, `TaxRate`, `Template`, `Invoice`, `Offer`, `CreditNote`, `Recurring`, `Letter`, `Reminder`, `DeliveryNote`, `Confirmation`, `Incoming` plus their `*CreateOptions`/`*UpdateOptions`; the five `*Property` definitions with the shared `PropertyCreateOptions`; `*Tag`, `*TagCloudEntry` and `*TagCreateOptions` for all twelve tag resources; `*Comment`, `*Payment`, `*PropertyValue` and the document `*Item` classes with their `*CreateOptions`; `RecurringEmailReceiver` with `RecurringEmailReceiverCreateOptions`; the typed list filters `ClientFilter`, the `*PaymentFilter` and `*PropertyValueFilter` of the sub-resources, `SupplierFilter`, `ArticleFilter`, `UserFilter`, `InvoiceFilter`, `OfferFilter`, `ConfirmationFilter`, `CreditNoteFilter`, `DeliveryNoteFilter`, `LetterFilter`, `ReminderFilter`, `IncomingFilter`, `RecurringFilter` and `TemplateFilter` (definition key `filter`; field types are derived from the spec's filter names and descriptions, enums come from the definition); the lookup models `Unit`, `FreeText`, `EmailTemplate`, `ReminderText` and `CountryTax` with their `*CreateOptions`/`*UpdateOptions`; and the read-only models `Country`, `Currency`, `User` and `IncomingCategory`). Their class docblock says "Generiert aus …". **Never edit these files by hand** — change the definition and run `composer generate`; CI runs `composer generate:check`. The definition holds field order, German docs, read-only response fields and BC overrides; the spec supplies types, defaults and enum values. Property names are the camelCase of the wire name; Billomat's one-word compounds (`actionkey`, `customfield`, `base64file`, `mimetype`, `filesize`) are split via `COMPOUND_WORDS` in `tools/generate.php` (`actionKey`, …) — add new ones there, and use the same names in handwritten classes. Fields Billomat always sends (`id`, item `unit_price`/`quantity`, payment `amount`, parent IDs, tag names, … — verify against `tests/Fixtures/Contract/` first) carry `'model' => ['required' => true]`: non-nullable, no constructor default, and `fromArray()` throws `UnexpectedResponseException` via `ScalarCaster::required()` when they are missing or empty. Every other field is nullable; there is no silent `0`/`''`/`false` fallback (`model.nonNull` was removed and aborts generation). Tests build minimal payloads with `Tests\Support\RequiredFields::of($class)` / `forHydrator()` / `::ANY` instead of hand-written required-field lists. Every generated model ends with `public array $extra = []`: `fromArray()` puts all keys not in its `FIELDS` constant there, `toArray()` spreads them first. A spec field missing from the definition aborts generation, and so does a spec field with a fixed value set (`enum` in the spec) whose definition has no `'enum' => 'SomeEnum'` (or `'enum' => false` to keep it a string on purpose). Comma-separated value lists (payment types) use `'enumList' => true` and become `list<Enum>`; objects of enum values (user rights, area → level) use `'type' => 'map', 'enum' => 'AccessLevel'` (read-only) and become `array<string, Enum>`, dropping empty and unknown values. `*Api` classes stay handwritten.
Some model/options classes are generated by `tools/generate.php` from `docs/spec/billomat.json` plus a per-resource definition in `tools/codegen/definitions/` (currently Clients, Contacts, Client Delivery Addresses, Suppliers, Articles, Taxes, Templates, Invoices, Offers, Credit Notes, Recurrings, Letters, Reminders, Delivery Notes, Confirmations and Incomings → `Client`, `Contact`, `ClientDeliveryAddress`, `Supplier`, `Article`, `TaxRate`, `Template`, `Invoice`, `Offer`, `CreditNote`, `Recurring`, `Letter`, `Reminder`, `DeliveryNote`, `Confirmation`, `Incoming` plus their `*CreateOptions`/`*UpdateOptions`; the five `*Property` definitions with the shared `PropertyCreateOptions`; `*Tag`, `*TagCloudEntry` and `*TagCreateOptions` for all twelve tag resources; `*Comment`, `*Payment`, `*PropertyValue` and the document `*Item` classes with their `*CreateOptions`; `RecurringEmailReceiver` with `RecurringEmailReceiverCreateOptions`; the typed list filters `ClientFilter`, the `*PaymentFilter` and `*PropertyValueFilter` of the sub-resources, `SupplierFilter`, `ArticleFilter`, `UserFilter`, `InvoiceFilter`, `OfferFilter`, `ConfirmationFilter`, `CreditNoteFilter`, `DeliveryNoteFilter`, `LetterFilter`, `ReminderFilter`, `IncomingFilter`, `RecurringFilter` and `TemplateFilter` (definition key `filter`; field types are derived from the spec's filter names and descriptions, enums come from the definition); the lookup models `Unit`, `FreeText`, `EmailTemplate`, `ReminderText` and `CountryTax` with their `*CreateOptions`/`*UpdateOptions`; and the read-only models `Country`, `Currency`, `User` and `IncomingCategory`). Their class docblock says "Generiert aus …". **Never edit these files by hand** — change the definition and run `composer generate`; CI runs `composer generate:check`. The definition holds field order, German docs, read-only response fields and BC overrides; the spec supplies types, defaults and enum values. Property names are the camelCase of the wire name; Billomat's one-word compounds (`actionkey`, `customfield`, `base64file`, `mimetype`, `filesize`) are split via `COMPOUND_WORDS` in `tools/generate.php` (`actionKey`, …) — add new ones there, and use the same names in handwritten classes. Fields Billomat always sends (`id`, item `unit_price`/`quantity`, payment `amount`, parent IDs, tag names, … — verify against `tests/Fixtures/Contract/` first) carry `'model' => ['required' => true]`: non-nullable, no constructor default, and `fromArray()` throws `UnexpectedResponseException` via `ScalarCaster::required()` when they are missing or empty. Every other field is nullable; there is no silent `0`/`''`/`false` fallback (`model.nonNull` was removed and aborts generation). Tests build minimal payloads with `Tests\Support\RequiredFields::of($class)` / `forHydrator()` / `::ANY` instead of hand-written required-field lists. Every generated model ends with `public array $extra = []`: `fromArray()` puts all keys not in its `FIELDS` constant there, `toArray()` spreads them first. A spec field missing from the definition aborts generation, and so does a spec field with a fixed value set (`enum` in the spec) whose definition has no `'enum' => 'SomeEnum'` (or `'enum' => false` to keep it a string on purpose). Comma-separated value lists (payment types) use `'enumList' => true` and become `list<Enum>`; objects of enum values (user rights, area → level) use `'type' => 'map', 'enum' => 'AccessLevel'` (read-only) and become `array<string, Enum>`, dropping empty and unknown values. `*Api` classes stay handwritten.

### HTTP layer

Expand Down Expand Up @@ -128,7 +128,7 @@ Billomat has no REST endpoint for webhook subscriptions (UI only) — never add
- Every list API has `list()`, `listPage()` and `iterateAll()` with the parameter name `$filters` (parent ID first for sub-resources). List methods take `XFilter|array $filters`; `AbstractApi::filterQuery()` turns a `ListFilter` into query parameters. Sorting goes through `OrderBy`, never a hand-written `'order_by' => 'date+DESC'` in SDK code.
- Amounts are `Model\Money` (exact decimal on `BcMath\Number`, `ext-bcmath`), never `float`. The generator maps `FLOAT` fields listed in `MONEY_FIELDS` (`tools/generate.php`) to `money`; add new amount fields there. Quantities, tax/discount rates and `quote` stay `float`. Document tax rows are `Model\TaxSummary` (`taxes` field type in the generator). Payloads and `toArray()` carry amounts as strings (`Money::toString()`). Fields with a fixed value set are enums from `src/Model/Enum/`; every enum uses the `FromApi` trait (`fromApi(?string): ?self`, `null`/`""`/unknown → `null`) — exceptions: `RecurringEmailReceiverType` (own case-insensitive `fromApi()`), `WebhookEvent`/`WebhookAction` (parsed strictly, unknown events throw `InvalidWebhookException`) and `Clear` (write-only marker, not backed); generated models hydrate with native `tryFrom()` (`model.fromApi` switches to `fromApi()` for enums with their own tolerance), and enum fields are never `required` (unknown values become `null`); keep `string` only for open sets (salutation, locale, currency code).
- All write options implement `WriteOptions` and are immutable: no property assignment, use named arguments or `with*()`. PHP-CS-Fixer is configured to write `clone($this, [...])` without a space.
- The BC promise (`docs/concepts/backward-compatibility.md`) covers everything public that isn't `@internal`, including parameter names. `AbstractApi`, `AbstractSubResourceApi`, all `*Api` constructors, the constructors of `Event\*`, `Page`/`PageInfo` and `HttpException`, `WebhookEvent::envelopeKey()`, `Internal\*`, the `FromApi` trait and `BillomatHttpClient`'s `$sleep` hook (last constructor parameter) are `@internal`; mark new SDK plumbing the same way. Exceptions below `BillomatException`/`HttpException` are `final`; new handwritten read models get `public array $extra = []` like the generated ones.
- The BC promise (`docs/concepts/backward-compatibility.md`) covers everything public that isn't `@internal`, including parameter names. Classes marked `@experimental` (endpoints Billomat still calls preliminary; definition key `experimental` in `tools/codegen/definitions/` adds the tag to generated classes) are excluded until the marker is dropped, see the "Experimental API" section there. `AbstractApi`, `AbstractSubResourceApi`, all `*Api` constructors, the constructors of `Event\*`, `Page`/`PageInfo` and `HttpException`, `WebhookEvent::envelopeKey()`, `Internal\*`, the `FromApi` trait and `BillomatHttpClient`'s `$sleep` hook (last constructor parameter) are `@internal`; mark new SDK plumbing the same way. Exceptions below `BillomatException`/`HttpException` are `final`; new handwritten read models get `public array $extra = []` like the generated ones.
- `new Foo()->bar` needs no parentheses (PHP 8.4+); don't write `(new Foo())->bar`.
- All API classes are `final`; models are `final readonly`.
- PSR-4: `Justpilot\Billomat\` → `src/`, `Justpilot\Billomat\Tests\` → `tests/`.
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve

## [Unreleased]

### Added
- Client delivery addresses (`/client-delivery-addresses`, new in Billomat's API docs): `$billomat->clients->deliveryAddresses` with `list()`/`listPage()`/`iterateAll()`, `get()`/`getOrFail()`, `create()`, `update()` and `delete()`, the read model `ClientDeliveryAddress` and `ClientDeliveryAddressCreateOptions`/`ClientDeliveryAddressUpdateOptions`. Marked `@experimental` until Billomat makes the endpoints binding (2027-01-01), see [Backward compatibility](docs/concepts/backward-compatibility.md#experimental-api) (#102).
- `clientDeliveryAddressId` on `Invoice`, `Recurring` and their create/update options (`client_delivery_address_id`) (#102).

### Changed
- `main` is the 4.x line now (`dev-main` is aliased to `4.x-dev`); security fixes for 3.x go to the `3.x` branch.

Expand Down
2 changes: 2 additions & 0 deletions docs/audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Legende: ✓ vorhanden · ✗ fehlt · — nicht erwartet
| `benutzer` | Benutzer | ✓ | ✓ | — | — | ✓ | Read-only; Billomat exponiert kein POST/PUT/DELETE für /users — Benutzerverwaltung ist UI-only. |
| `benutzerdefinierte-attribute-filtern` | Benutzerdefinierte Attribute filtern | — | — | — | — | — | Konzept-Doku, kein Api erwartet. |
| `briefe` | Briefe | ✓ | ✓ | ✓ | ✓ | ✓ | |
| `e-rechnungen` | E-Rechnungen | ✗ | ✗ | ✗ | ✗ | ✗ | Kein Mapping definiert – Audit-Skript erweitern. |
| `eingangsrechnungen` | Eingangsrechnungen | ✓ | ✓ | ✓ | ✓ | ✓ | |
| `eingangsrechnungen/attribute` | Attribute | ✓ | — | — | — | ✓ | |
| `eingangsrechnungen/inbox` | Inbox | ✓ | ✓ | ✓ | — | ✓ | |
Expand Down Expand Up @@ -67,6 +68,7 @@ Legende: ✓ vorhanden · ✗ fehlt · — nicht erwartet
| `kunden/kontakte` | Kontakte | ✓ | ✓ | ✓ | ✓ | ✓ | |
| `kunden/schlagworte` | Schlagworte | ✓ | ✓ | ✓ | — | ✓ | |
| `laender` | Länder | ✓ | ✓ | — | — | ✓ | |
| `lieferadressen` | Lieferadressen | ✓ | ✓ | ✓ | ✓ | ✓ | |
| `lieferanten` | Lieferanten | ✓ | ✓ | ✓ | ✓ | ✓ | |
| `lieferanten/attribute` | Attribute | ✓ | — | — | — | ✓ | |
| `lieferanten/schlagworte` | Schlagworte | ✓ | ✓ | ✓ | — | ✓ | |
Expand Down
11 changes: 11 additions & 0 deletions docs/concepts/backward-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ Everything public under `Justpilot\Billomat\` that is not marked `@internal`:
- **Additions**, which may come with any minor release: new classes, methods, optional parameters at the end of a method, read model properties, enum cases and keys in `$extra`. If you `match` over an SDK enum, add a `default` arm, because Billomat extends its value sets from time to time.
- **Message texts** of exceptions and log entries, and the order of log entries and events. Log levels only change in a minor release, with a CHANGELOG entry.
- **Billomat's behaviour.** If Billomat stops sending a field, the property stays but becomes `null`; fields Billomat drops for good are removed in the next major version.
- **`@experimental` code**, see below.

## Experimental API

Billomat sometimes publishes endpoints before they are final. The SDK supports them early, but marks the classes `@experimental` as long as Billomat calls them preliminary. Experimental classes may change in a minor release (renamed fields, changed types, removed methods) when Billomat changes the endpoint; each change gets a CHANGELOG entry. Once Billomat declares the endpoint final, a minor release drops the marker and the class falls under the promise above.

Currently experimental, because Billomat's documentation says the endpoints only become binding on 2027-01-01:

- [Client delivery addresses](../resources/client-delivery-addresses.md): `ClientsApi::$deliveryAddresses`, `ClientDeliveryAddressesApi`, `ClientDeliveryAddress`, `ClientDeliveryAddressCreateOptions`, `ClientDeliveryAddressUpdateOptions`.

The `clientDeliveryAddressId` field on invoices and recurring invoices is a plain ID and covered as usual.
Loading
Loading