stann/factur-x 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

stann/factur-x

Composer 安装命令:

composer require stann/factur-x

包简介

README 文档

README

A modern PHP 8.1+ library for creating Factur-X electronic invoices, compatible with Chorus Pro. Uses mPDF to generate PDF/A-3 documents.

  • Create a Factur-X document
  • Validate against official XSD schemas
  • Read a Factur-X document (coming soon)

Installation

composer require stann/factur-x

Usage

Create a Factur-X document

Using the builder (recommended):

<?php

use Stann\FacturX\AppendixParts\ExchangedDocument;
use Stann\FacturX\AppendixParts\MonetarySummation;
use Stann\FacturX\AppendixParts\TradeParty;
use Stann\FacturX\AppendixParts\TypeCode;
use Stann\FacturX\CrossIndustryInvoiceBuilder;
use Stann\FacturX\FacturX;
use Stann\FacturX\ValueObjects\CountryCode;
use Stann\FacturX\ValueObjects\VATNumber;

$invoice = CrossIndustryInvoiceBuilder::minimum()
    ->withDocument(new ExchangedDocument('F0003', TypeCode::INVOICE, new DateTimeImmutable()))
    ->withSeller(new TradeParty('Stann', '34261828837536', CountryCode::FRANCE, new VATNumber('FR520000000')))
    ->withBuyer(new TradeParty('Mairie de Toulouse', '10881392400937', CountryCode::FRANCE, new VATNumber('FR980000000')))
    ->withAmounts(new MonetarySummation('EUR', 100.00, 120.00, 120.00))
    ->withBuyerReference('1004')        // Optional, for Chorus Pro "Service Exécutant"
    ->withBuyerOrderReference('BDC001') // Optional, for Chorus Pro "Engagement Juridique"
    ->build();

$facturX = (new FacturX())->createFile(
    fopen(__DIR__ . '/assets/facture.pdf', 'rb'),
    $invoice,
);

Or using the constructor directly:

$invoice = new CrossIndustryInvoice(
    document: new ExchangedDocument('F0003', TypeCode::INVOICE, new DateTimeImmutable()),
    sellerTradeParty: new TradeParty('Stann', '34261828837536', CountryCode::FRANCE, new VATNumber('FR520000000')),
    buyerTradeParty: new TradeParty('Mairie de Toulouse', '10881392400937', CountryCode::FRANCE, new VATNumber('FR980000000')),
    monetarySummation: new MonetarySummation('EUR', 100.00, 120.00, 120.00),
    buyerReference: '1004',
    buyerOrderReference: 'BDC001',
);

Available profiles

The builder provides factory methods for each Factur-X profile:

CrossIndustryInvoiceBuilder::minimum();   // Simplest profile
CrossIndustryInvoiceBuilder::basicWL();   // Basic Without Lines
CrossIndustryInvoiceBuilder::basic();     // With invoice lines
CrossIndustryInvoiceBuilder::en16931();   // European standard
CrossIndustryInvoiceBuilder::extended();  // Full features

Note: withBuyerContractReference() is only available for BASIC_WL and higher profiles.

Validation

Validate your document against official XSD schemas:

<?php

use Stann\FacturX\FacturX;
use Stann\FacturX\Schema;

$facturX = new FacturX();

// Throws InvalidXMLSchema with LibXMLError[] on failure
$facturX->validate($invoice->toXml(), Schema::MINIMUM);

// Returns boolean
$facturX->isValid($invoice->toXml(), Schema::MINIMUM);

// Returns LibXMLError[]
$errors = $facturX->getValidationErrors($invoice->toXml(), Schema::MINIMUM);

Available schemas

  • Schema::MINIMUM
  • Schema::BASIC_WL
  • Schema::BASIC
  • Schema::EN16931
  • Schema::EXTENDED

stann/factur-x 适用场景与选型建议

stann/factur-x 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.13k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 12 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 stann/factur-x 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 stann/factur-x 我们能提供哪些服务?
定制开发 / 二次开发

基于 stann/factur-x 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.13k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-12-23