# Commerce Assistant Pro — Document Extension API Integrator guide, Pro 0.14.3 Stable candidate with Free 0.12.10 / Core API 1.9.0. Existing interface version 1.0.0 is unchanged; this release does not invent a new API or promise a broader compatibility policy. This is an installed, trusted-PHP extension API, not an HTTP service. It does not register fiscal documents or create an ERP connection. ## Two different integration surfaces | Interface | Integrator | Authentication | Output | | --- | --- | --- | --- | | Document Extension API | An installed WordPress add-on | Trusted local PHP; Pro entitlement gates registration | Selected typed values in templates | | Fiscal / ERP REST v1 | A remote ERP/POS developer | Dedicated WP user, Application Password, capability and provider allowlist | Register an external reference or PDF against a sealed snapshot | ## Start here 1. On an isolated test store, enable Pro with the contract-production grant. Registration runs on the action below only in the entitled runtime. 2. Create a small separate add-on using the example. Do not edit Free, Pro or order data. Add-ons must be bounded, read-only and must not send mail or perform remote requests while resolving fields. 3. Open Commerce Assistant → Additional fields. A successfully registered field appears with its localized label and phase. If no add-on registers anything, the empty state is normal. 4. Customize a template copy. Insert the field from its picker, preview, then publish and activate. Registration by itself changes no document. 5. Create a synthetic test order. Contract-phase values are frozen before snapshot seal. Read the original PDF again after changing the provider: its bytes must not change. ## Working minimal add-on ```php 'Referenca', 'hr'=>'Referenca', 'sr'=>'Referenca', 'en'=>'Reference'], ['bs'=>'Referenca pri kupovini', 'hr'=>'Referenca pri kupnji', 'sr'=>'Referenca pri kupovini', 'en'=>'Reference at purchase'], 'text', 'FORMATION_SNAPSHOT', ['contract'], 'customer-visible', static function (\Leanmerce\CommerceCompliance\Pro\DocumentExtension\OrderProjection $order) { return $order->public_number; } ); $registry->register_field($field); }); ``` The actual token is `{{EXT:example.store.reference}}`. Use `register_block()` and a `structured_block` definition for structured rows; its token is `{{EXT_BLOCK:example.store.rows}}`. Do not return arbitrary HTML, callbacks, serialized objects or legal clauses. ## Inline example and verification recipe No separate full sample plugin is included with this installer or the matching corrected distribution bundle. Use the complete minimal add-on shown above: create a separate plugin file on an isolated store, review it and activate it. It needs no ERP, API password or remote resource. Do not enable a synthetic example on a real store. That inline example registers the text field `example.store.reference` for `FORMATION_SNAPSHOT`; its resolver returns the read-only public order number. It does not register the additional demonstration types or a throwing resolver. Every definition must still provide the required four-language labels/help and API/provider versions. In Additional fields, verify the example label and phase. Insert `{{EXT:example.store.reference}}` into a new template draft using the picker, preview, then publish/activate only after reviewing the synthetic result. Create a synthetic checkout order and record the sealed value and original PDF SHA-256. Change or disable the example add-on, then retrieve that existing original again: its frozen value and bytes must remain unchanged. No callback may fetch remote data, write an order or send an email. To test another type or a `POST_ORDER_CURRENT` field, the integrating developer must register a separate valid definition using the API below. Such a current field is not part of the supplied inline example and must not be selected for a contract. The separate operational current-document API is described at the end of this guide. Do not infer a supplied sample directory or public download URL. ## Types, phases and privacy The following type shapes are literal API inputs, not arbitrary HTML: ```php // Each is a resolver return value for its declared type. $text = 'SAMPLE-ČĆĐŠŽ'; $date = '2026-10-18'; $money = ['amount'=>'12.34', 'currency'=>'BAM']; $list = ['first', 'second']; $rows = [['label'=>'SAMPLE', 'text'=>'synthetic', 'url'=>'https://example.test/synthetic']]; ``` The API contract and inline quickstart remain bundled and downloadable from the plugin without depending on a website. The type shapes above illustrate resolver return values; they are not a claim that a separate multi-field sample package is supplied. `FieldDefinition` receives ID, API version, provider version, four-language labels and help, type, phase, supported document types, sensitivity, typed resolver and optional metadata-key allowlist. IDs are namespaced and collision-safe. Duplicate registrations return false, retaining the existing definition. Supported API versions have major 1. Resolvers receive a read-only `OrderProjection`, not `WC_Order`. It contains order ID/public number/currency/locale/items and explicitly declared metadata, not automatic buyer address, payment or licence secrets. HPOS/legacy data is projected through Woo CRUD. Declared metadata is bounded: at most 16 keys per definition, 64 keys/64 KiB aggregate, depth 8, 256 nodes and 16 KiB per value. Item projections have a 200-item/64 KiB bound and `items_complete`; reject incomplete projections if exhaustive items are required. Mandatory contract items are not truncated by these API limits. | Phase / document | Meaning | | --- | --- | | FORMATION_SNAPSHOT / contract | Customer-visible selected value is frozen with provider version, locale label, capture time and hash before seal. Original reads never call the provider again. | | POST_ORDER_CURRENT / operational | Later data is read only in the separately labelled current operational preview, with order capability and entitlement. It never rewrites R1/R2. | Sensitivity is `customer-visible`, `merchant-private` or `restricted`. Only customer-visible, contract-phase definitions are selectable in contracts. Supported types: `text`, `integer`, `decimal`, `money`, `date`, `url`, `list`, `structured_block`. Text is UTF-8 up to 2,048 bytes; lists up to 20 text values; blocks up to 20 label/text/optional HTTPS-link rows and 16 KiB. Money is canonical decimal `amount` plus a three-letter uppercase `currency`; dates are ISO dates. URLs must be credential-free HTTPS. Total captured selected values are bounded to 64 KiB. ## Validation and failure Labels and help must contain BS/HR/SR Latin/EN. Invalid registration yields `unknown_provider` or `unsupported_document_phase`. Unknown tokens, unavailable definitions or invalid phase selections block publication with an actionable message. Resolver failures and wrong return types produce unavailable records without exposing exception contents; no fallback may silently replace a mandatory legal section. Optional absent values do not grant permissions. Local installed PHP is trusted code, not a sandbox. A readonly projection cannot prevent a malicious callback from calling arbitrary WP/SQL APIs. There is no hard synchronous-PHP timeout. Keep callbacks short and side-effect-free; do not use network access or writes. This guide does not claim otherwise. ## Compatibility Minor additions within API major 1 are backwards-compatible. Breaking changes require a new major and explicit migration; historical frozen records are not reinterpreted. This API does not add late tracking or fiscal data to a sealed contract, issue a fiscal receipt, change an order, or automatically send mail. The Fiscal / ERP guide describes the separate remote interface. ## Operational full-document bridge (current Pro 0.14.3 companion) The current companion is Free 0.12.10 / Core API 1.9.0, exposing Operational PDF Extension API 1.0.0. See the Free package's `docs/PDF-EXTENSION-DEVELOPER-API.md` for the complete current-document contract, limits, privacy, positions, real HTTPS annotations, whole-order preview and separately opt-in customer delivery. Core publishes an open lazy registry, field definitions, DTOs, validators and read-only guard; definition-registration callbacks do not require Pro or a licence and do not resolve data or insert output. Existing Core `PdfExtension\Access`, `Settings` and `Projection` PHP signatures remain compatibility facades, delegating advanced work to this separate Pro package. Pro owns the operational resolver, configuration/UI, preview/diagnostics and optional account/email current-PDF delivery implementation in `Leanmerce\CommerceCompliance\Pro\OperationalPdf`; those features require its loaded runtime and existing signed entitlement. Pro attaches that implementation to the neutral `leanmerce_commerce_assistant_current_document_v1($current, $order, $audience)` hook. The required companion capability is `BasicPdfService::CURRENT_DOCUMENT_FILTER_API = '1.0.0'`, distinct from the unchanged package label. The hook itself has no licence prerequisite; the Pro implementation applies its own authorization and privacy checks. Free contains no paid operational implementation. Pro also supplies safe styles and four-language custom labels. The entitled bridge imports existing v1 POST_ORDER_CURRENT / operational fields into the single Core registry. The old single-field preview is still available; the Additional fields button opens the Pro whole-order configuration. FORMATION_SNAPSHOT definitions, EXT/EXT_BLOCK tokens, immutable capture and historic contract output are unchanged. Do not re-register an ID in both APIs or change a formation field into a current field. Existing Fiscal/ERP REST, licences and WOFF2 are unchanged.