PHP code example of stann / factur-x

1. Go to this page and download the library: Download stann/factur-x library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stann / factur-x example snippets




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,
);

$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',
);

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



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);