Bien démarrer avec FactoorSharp
Avec FactoorSharp, vous créez, lisez et validez des factures électroniques (ZUGFeRD, XRechnung, EN16931) en quelques minutes.
Ce guide vous accompagne pas à pas jusqu'à votre première facture fonctionnelle.
À l'issue de ce guide de démarrage rapide, vous saurez :
- créer une facture en C#
- l'exporter au format XML EN16931 / ZUGFeRD
- l'intégrer, en option, dans un PDF/A‑3
- valider le résultat
Installation
Installez FactoorSharp via NuGet :
dotnet add package FactoorSharp.FacturX
Ou via le Gestionnaire de package :
Install-Package FactoorSharp
La bibliothèque prend en charge : .NET 6+, .NET Framework 4.6, .NET Framework 4.8 (selon la plateforme cible)
Obtenir une licence
TODO : inscription et récupération
Créer votre première facture
Dans l'exemple suivant, vous créez une facture minimale conforme EN16931.
Commençons par les données d'en-tête de la facture avec l'identification du vendeur et de l'acheteur. Cela inclut également les informations de livraison :
FacturXInvoice.SetLicense("...");
var invoice = FacturXInvoice.CreateInvoice("Invoice-01",
new DateTime(2025,09,03),
Currency.EUR)
// BG-14
.SetSeller(name: "BikeTech GmbH",
postcode: "10115",
city: "Berlin",
street: "Radweg 12",
country: CountryCodes.DE,
id: String.Empty,
globalID: new GlobalID(GlobalIDSchemeIdentifiers.GLN, "4000001123452"),
legalOrganization: new LegalOrganization(GlobalIDSchemeIdentifiers.GLN, "4000001123452", "BikeTech GmbH"))
// BG-7
.SetBuyer(name: "CityRider AG",
postcode: "20457",
city: "Hamburg",
street: "Hafenstraße 45",
country: CountryCodes.DE,
id: "DE987654321");
// BT-31
invoice.AddSellerTaxRegistration("201/113/40209", TaxRegistrationSchemeID.FC);
// BT-72 - ActualDeliverySupplyChainEvent
invoice.ActualDeliveryDate = DateTime.Today;
// alternative : période de facturation (BG-14)
// invoice.SetBillingPeriod(
// billingPeriodStart: DateTime.Today.AddDays(-7),
// billingPeriodEnd: DateTime.Today);
FacturXInvoice.SetLicense("...")
Dim invoice = FacturXInvoice.CreateInvoice("Invoice-01",
New DateTime(2025, 9, 3),
Currency.EUR) _
.SetSeller(name:="BikeTech GmbH",
postcode:="10115",
city:="Berlin",
street:="Radweg 12",
country:=CountryCodes.DE,
id:=String.Empty,
globalID:=New GlobalID(GlobalIDSchemeIdentifiers.GLN, "4000001123452"),
legalOrganization:=New LegalOrganization(GlobalIDSchemeIdentifiers.GLN, "4000001123452", "BikeTech GmbH")) _
.SetBuyer(name:="CityRider AG",
postcode:="20457",
city:="Hamburg",
street:="Hafenstraße 45",
country:=CountryCodes.DE,
id:="DE987654321")
' BT-31
invoice.AddSellerTaxRegistration("201/113/40209", TaxRegistrationSchemeID.FC)
' BT-72 - ActualDeliverySupplyChainEvent
invoice.ActualDeliveryDate = DateTime.Today
' alternative : période de facturation (BG-14)
' invoice.SetBillingPeriod(
' billingPeriodStart:=DateTime.Today.AddDays(-7),
' billingPeriodEnd:=DateTime.Today)
Ajoutons ensuite une position :
invoice.AddTradeLineItem(name: "Vélo de trekking",
netUnitPrice: 799.0m,
unitCode: QuantityCodes.C62,
grossUnitPrice: 799.0m,
billedQuantity: 1,
taxType: TaxTypes.VAT,
categoryCode: TaxCategoryCodes.S,
taxPercent: 19,
sellerAssignedID: "BIKE-1");
invoice.AddTradeLineItem(name:="Vélo de trekking",
netUnitPrice:=799.0D,
unitCode:=QuantityCodes.C62,
grossUnitPrice:=799.0D,
billedQuantity:=1,
taxType:=TaxTypes.VAT,
categoryCode:=TaxCategoryCodes.S,
taxPercent:=19,
sellerAssignedID:="BIKE-1")
Et le bloc des totaux, avec les conditions de paiement :
decimal taxTotalAmount = 799.0m / 100m * 19m;
invoice.AddApplicableTradeTax(basisAmount: 799.0m,
percent: 19m,
taxAmount: taxTotalAmount,
typeCode: TaxTypes.VAT,
categoryCode: TaxCategoryCodes.S);
invoice.PaymentTerms.Add(new PaymentTerms() // BT-20
{
DueDate = DateTime.Today.AddDays(14)
});
invoice.SetTotals(lineTotalAmount: 799.0m,
taxBasisAmount: 799.0m,
taxTotalAmount: taxTotalAmount,
grandTotalAmount: 799.0m + taxTotalAmount,
duePayableAmount: 799.0m + taxTotalAmount);
invoice.Save("e:\\factur-x.xml",
version: ZUGFeRDVersion.Version23,
profile: Profile.Extended);
Dim taxTotalAmount As Decimal = 799.0D / 100D * 19D
invoice.AddApplicableTradeTax(basisAmount:=799.0D,
percent:=19D,
taxAmount:=taxTotalAmount,
typeCode:=TaxTypes.VAT,
categoryCode:=TaxCategoryCodes.S)
invoice.PaymentTerms.Add(New PaymentTerms() With ' BT-20
{
.DueDate = DateTime.Today.AddDays(14)
})
invoice.SetTotals(lineTotalAmount:=799.0D,
taxBasisAmount:=799.0D,
taxTotalAmount:=taxTotalAmount,
grandTotalAmount:=799.0D + taxTotalAmount,
duePayableAmount:=799.0D + taxTotalAmount)
invoice.Save("e:\factur-x.xml",
version:=ZUGFeRDVersion.Version23,
profile:=Profile.Extended)
Export au format XML (EN16931 / XRechnung / ZUGFeRD)
Une fois votre facture construite, vous pouvez l'exporter au format XML :
invoice.Save("factur-x.xml",
version: ZUGFeRDVersion.Version23,
profile: Profile.Extended);
invoice.Save("factur-x.xml",
version:=ZUGFeRDVersion.Version23,
profile:=Profile.Extended)
Les profils habituellement utilisés pour ZUGFeRD sont :
- Comfort/ EN16931
- Norme pour l'UE
- Extended
- Le profil le plus détaillé et le plus utilisé en Allemagne
Valider une facture
Pour vous assurer que toutes les informations nécessaires sont présentes, vous pouvez valider votre facture avec l'outil de validation de l'espace client sur factoorsharp.de.
Cela permet aux destinataires de la facture de la traiter sans difficulté.
Créer un PDF/A‑3 avec facture intégrée (ZUGFeRD)
Si vous disposez déjà d'un fichier PDF, par exemple issu d'un générateur de rapports ou de votre ERP, vous pouvez intégrer directement les informations ZUGFeRD dans ce PDF :
await FacturXInvoicePdfProcessor.SaveToPdfAsync(
"FacturX-facture.pdf",
ZUGFeRDVersion.Version23,
Profile.Extended,
ZUGFeRDFormats.CII,
"Facture-PDF-classique.pdf");
Await FacturXInvoicePdfProcessor.SaveToPdfAsync(
"FacturX-facture.pdf",
ZUGFeRDVersion.Version23,
Profile.Extended,
ZUGFeRDFormats.CII,
"Facture-PDF-classique.pdf")
Résultat : un PDF lisible visuellement au format PDF/A‑3, contenant également le fichier XML lisible par machine intégré au document PDF.
Lire des factures existantes
FactoorSharp peut également analyser des factures existantes, que vous lisiez un fichier XML :
var invoice = FacturXInvoice.CreateInvoice("Invoice-01",
new DateTime(2025,09,03),
Currency.EUR)
.SetSeller("BikeTech GmbH", "10115", "Berlin", ...)
.SetBuyer("City Bikes AG", "20457", "Hamburg", ...);
invoice.AddTradeLineItem("Vélo de trekking",
799.0m,
QuantityCodes.C62,
1);
invoice.Save("factur-x.xml",
version: ZUGFeRDVersion.Version23,
profile: Profile.Extended);
Dim invoice = FacturXInvoice.CreateInvoice("Invoice-01",
New DateTime(2025, 9, 3),
Currency.EUR) _
.SetSeller("BikeTech GmbH", "10115", "Berlin", ...) _
.SetBuyer("City Bikes AG", "20457", "Hamburg", ...)
invoice.AddTradeLineItem("Vélo de trekking",
799.0D,
QuantityCodes.C62,
1)
invoice.Save("factur-x.xml",
version:=ZUGFeRDVersion.Version23,
profile:=Profile.Extended)
ou que vous deviez extraire le fichier XML d'un fichier PDF :
var invoice = FacturXInvoice.CreateInvoice("Invoice-01",
new DateTime(2025,09,03),
Currency.EUR)
.SetSeller("BikeTech GmbH", "10115", "Berlin", ...)
.SetBuyer("City Bikes AG", "20457", "Hamburg", ...);
invoice.AddTradeLineItem("Vélo de trekking",
799.0m,
QuantityCodes.C62,
1);
invoice.Save("factur-x.xml",
version: ZUGFeRDVersion.Version23,
profile: Profile.Extended);
Dim invoice = FacturXInvoice.CreateInvoice("Invoice-01",
New DateTime(2025, 9, 3),
Currency.EUR) _
.SetSeller("BikeTech GmbH", "10115", "Berlin", ...) _
.SetBuyer("City Bikes AG", "20457", "Hamburg", ...)
invoice.AddTradeLineItem("Vélo de trekking",
799.0D,
QuantityCodes.C62,
1)
invoice.Save("factur-x.xml",
version:=ZUGFeRDVersion.Version23,
profile:=Profile.Extended)
Migration depuis ZUGFeRD-csharp
FactoorSharp est le successeur de ZUGFeRD-csharp.
Si vous travaillez déjà avec :
- L'API a volontairement été conservée similaire
- Votre logique existante peut généralement être reprise telle quelle
- Remplacez InvoiceDescriptor par FacturXInvoice, et InvoicePdfProcessor par FacturXInvoicePdfProcessor. C'est tout.
- Nouveautés : meilleure validation, nouvelles fonctionnalités