Skip to content

[US-9.2] CFDI XML Generation & Certificate Service#68

Merged
dacanetdev merged 1 commit intomainfrom
feature/US-9.2-cfdi-xml-signature
Apr 5, 2026
Merged

[US-9.2] CFDI XML Generation & Certificate Service#68
dacanetdev merged 1 commit intomainfrom
feature/US-9.2-cfdi-xml-signature

Conversation

@dacanetdev
Copy link
Copy Markdown
Owner

Summary

  • ICertificateService + DatabaseCertificateService — stores PFX bytes in TenantConfiguration.CfdiCertificateData, loads via X509CertificateLoader.LoadPkcs12 (.NET 10)
  • ICfdiXmlGenerator + CfdiXmlGenerator — builds CFDI 4.0 XML with SAT namespace, computes original chain (InvariantCulture), signs with RSA SHA256
  • GenerateInvoiceCommand + handler — creates Draft invoice from completed sale, validates issuer config + customer RFC, assigns folio F-NNNNN
  • ITenantConfigurationRepository extended with GetByTenantIdAsync + Update
  • Both DI overloads updated

Design decisions

  • Certificate storage: DB-based (no Azure Key Vault needed)
  • XML generator uses System.Xml.Linq with proper SAT namespace http://www.sat.gob.mx/cfd/4

Test plan

  • dotnet build — 0 warnings, 0 errors
  • dotnet test tests/Corelio.Application.Tests — 150/150 passing

🤖 Generated with Claude Code

- ICertificateService interface (Application layer):
  LoadCertificateAsync, UploadCertificateAsync, GetExpiryAsync
- DatabaseCertificateService (Infrastructure):
  Stores PFX bytes + password in TenantConfiguration.CfdiCertificateData
  Uses X509CertificateLoader.LoadPkcs12 (.NET 10 API)
- ICfdiXmlGenerator interface (Application layer)
- CfdiXmlGenerator (Infrastructure):
  Builds SAT CFDI 4.0 XML with proper namespaces via System.Xml.Linq
  Computes cadena original (pipe-delimited, InvariantCulture)
  Signs with RSA SHA256 (Pkcs1 padding) from CSD certificate
- GenerateInvoiceCommand + handler:
  Creates Draft invoice from completed sale + customer RFC validation
  Assigns folio F-NNNNN, increments CfdiNextFolio on TenantConfiguration
  Maps SaleItems → InvoiceItems with SAT product/unit codes
- ITenantConfigurationRepository: added GetByTenantIdAsync + Update methods
- DI: ICertificateService + ICfdiXmlGenerator registered in both overloads
- 0 warnings, 0 errors, 150/150 tests passing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dacanetdev dacanetdev merged commit b3b9dbe into main Apr 5, 2026
8 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant