Skip to content

API overview

This page is a hand-curated overview of the public types in xrechnung-kit-core. It is intentionally narrative: which types belong together, which constructors enforce what, where the Internal namespace begins.

For the per-class auto-generated reference produced by phpDocumentor, see Generated API reference - it is regenerated on every push to main. Anything under XrechnungKit\Internal\ is implementation detail and is not covered by SemVer; everything else is part of the public contract.

At a glance

SurfaceNamespacePurpose
Mapping value objectsXrechnungKit\MappingThe single public input contract. See MappingData.
Document classesXrechnungKitUNTDID code enums driving document-class selection.
BuilderXrechnungKit\Builder\XRechnungBuilderBridges MappingData to the lifted entity pipeline.
GeneratorXrechnungKit\XRechnungGeneratorRenders the entity into UBL XML and validates atomically.
ValidatorXrechnungKit\XRechnungValidatorStandalone UBL XSD and (optionally) KoSIT Schematron passes.

Mapping value objects

MappingData

Namespace: XrechnungKit\Mapping\MappingData

The root of the public input contract. Construct via one of five named constructors; never via new.

php
MappingData::standardInvoice(
    DocumentMeta $meta,
    Party $seller,
    Party $buyer,
    /** @var LineItem[] */ array $lines,
    /** @var TaxBreakdown[] */ array $taxes,
    /** @var PaymentMeans[] */ array $payment,
    DocumentTotals $totals,
    ?BillingReference $billingReference = null,
    ?DeliveryInfo $delivery = null,
): self;

MappingData::partialInvoice(/* same shape */): self;
MappingData::cautionInvoice(/* same shape */): self;
MappingData::creditNote(/* same shape, plus required prior-invoice ref */): self;
MappingData::depositCancellation(/* same shape, plus required prior-invoice ref */): self;

Constructors validate at the point of construction: missing required fields, currency mismatches between line items and totals, and inconsistent tax breakdowns all throw \InvalidArgumentException synchronously.

See Mapping data contract for the full per-field semantics.

Field-level value objects

ClassRequired fieldsNotes
DocumentMetainvoiceNumber, type, issueDate, currencydueDate, buyerReference, note, purchaseOrderRef are optional.
Partyconstructed via Party::business() or Party::publicAdministration()Public administration variant requires leitwegId.
Addressstreet, city, zip, countryCodeadditionalStreet, additionalCityInfo are optional.
Contactnone requiredEmail, phone, name are all optional but at least one should be set.
LineItemid, description, quantity, unitCode, unitPrice, lineTotal, taxCategory, taxPercentname, sellerItemId, buyerItemId, period are optional.
Moneyconstructed via Money::eur(string $amount) for EUROther currencies via new Money(string $amount, string $currency). Amounts are decimal strings, never floats.
TaxBreakdowncategory, percent, taxableAmount, taxAmountOne per (category, percent) combination.
PaymentMeansconstructed via static factories: sepaCreditTransfer(), sepaDirectDebit(), wireTransfer(), etc.Seven payment-code variants supported.
TaxIdconstructed via TaxId::vatId('DE...') or TaxId::companyId('...')Maps to UBL <PartyTaxScheme>.
DocumentTotalslineNet, taxableAmount, taxAmount, payableCurrencies must match DocumentMeta::currency.
BillingReferenceinvoiceNumber, issueDateRequired on credit notes and deposit cancellations.
DeliveryInfoactualDeliveryDate or periodOptional.

Document classes

XRechnungInvoiceTypeCode

Namespace: XrechnungKit\XRechnungInvoiceTypeCode

Backed PHP 8.1 enum mapping document classes to UNTDID codes.

CaseUNTDID codeUsed by
COMMERCIAL_INVOICE380MappingData::standardInvoice()
PARTIAL_INVOICE326MappingData::partialInvoice(), MappingData::cautionInvoice()
CREDIT_NOTE381MappingData::creditNote(), MappingData::depositCancellation()
REQUEST_FOR_PAYMENT71reserved

XRechnungTaxCategory

Namespace: XrechnungKit\XRechnungTaxCategory

CaseUBL codeDescription
STANDARD_RATESStandard German VAT (typically 19%)
REDUCED_RATEAAReduced rate (typically 7%)
ZERO_RATED_GOODSZZero-rated supply
EXEMPTEVAT exempt
REVERSE_CHARGEAEReverse charge applies
INTRA_COMMUNITYKIntra-Community supply
EXPORTGExport outside the EU
NOT_SUBJECT_TO_TAXOServices outside scope

Builder

XRechnungBuilder::buildEntity()

Namespace: XrechnungKit\Builder\XRechnungBuilder

php
public static function buildEntity(MappingData $mapping): XRechnungEntity;

Pure transformation: a MappingData in, an XRechnungEntity out. The entity is the type the generator's UBL template expects. No I/O, no globals, no logging. Safe to call inside a tight loop.

If the mapping is internally inconsistent (currency mismatches, tax breakdown sums that disagree with the line totals, etc.), the builder throws \InvalidArgumentException.

Generator

XRechnungGenerator

Namespace: XrechnungKit\XRechnungGenerator

php
public function __construct(XRechnungEntity $entity);

public function generateXRechnung(string $targetPath): string;

Renders the entity into UBL XML, runs UBL XSD validation in memory, then writes atomically:

  • On success: writes to $targetPath. Returns $targetPath.
  • On failure: writes to ${dirname}/${basename}_invalid.${ext} instead. Returns that path.

Atomic write means: write to ${path}.tmp, fsync, rename to final path. The opposite-sibling file (the _invalid if you just wrote a valid one, or vice versa) is removed in the same atomic operation. You cannot end up with both a valid.xml and a valid_invalid.xml for the same invoice number.

Validator

XRechnungValidator

Namespace: XrechnungKit\XRechnungValidator

php
public function __construct(?LoggerInterface $logger = null);

public function validate(string $path): bool;
public function validateSchematron(string $path): bool;
public function getErrors(): array;

validate() runs UBL XSD validation against the bundled UBL Invoice 2.4 / CreditNote 2.4 schemas. Returns true on pass.

validateSchematron() runs the optional KoSIT Schematron pass. Requires vineethkrishnan/xrechnung-kit-kosit-bundle to be installed and Java 17+ to be available at validation time. Returns true on pass.

getErrors() returns structured error messages from the most recent validation. Format is suitable for direct display to operators.

Internal types

Anything under XrechnungKit\Internal\ is implementation detail. Specifically XRechnungEntity, Internal\AtomicWriter, Internal\AlertGate, and the lifted L3 entity classes are not part of the public contract and may move freely between minor releases.

If you need to subclass or replace one of those, open an issue describing the use case and we will lift it into the public surface intentionally.

Released under the MIT License. xrechnung-kit is an independent open source library and is neither affiliated with nor endorsed by KoSIT or any German government agency.