Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signing simplified invoices #18

Open
sevaske opened this issue Feb 27, 2025 · 4 comments
Open

Signing simplified invoices #18

sevaske opened this issue Feb 27, 2025 · 4 comments

Comments

@sevaske
Copy link
Contributor

sevaske commented Feb 27, 2025

By some reason, when I sign a simplified invoice, I get errors:

category : QR_CODE_ERROR
code :hashedXml
message : hashedXml does not match with qr code hashedXml or the hashedXml is missing 
--
category : SIGNATURE_ERROR
code :invoiceSignedDataDigestValue
message : wrong invoice hashing
--
category : SIGNATURE_ERROR
code :X509IssuerName
message : wrong X509IssuerName  
--
category : SIGNATURE_ERROR
code :X509SerialNumber
message : wrong X509SerialNumber  
--
category : SIGNATURE_ERROR
code :signatureValue
message : wrong signature Value

But when I set "Standard" as the invoice type - there are no errors. Is the signing of simplified invoices done differently?

The invoice

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2">
  <ext:UBLExtensions><ext:UBLExtension>
    <ext:ExtensionURI>urn:oasis:names:specification:ubl:dsig:enveloped:xades</ext:ExtensionURI>
    <ext:ExtensionContent>
        <sig:UBLDocumentSignatures xmlns:sig="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2" xmlns:sac="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2" xmlns:sbc="urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2">
            <sac:SignatureInformation>
                <cbc:ID>urn:oasis:names:specification:ubl:signature:1</cbc:ID>
                <sbc:ReferencedSignatureID>urn:oasis:names:specification:ubl:signature:Invoice</sbc:ReferencedSignatureID>
                <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="signature">
                    <ds:SignedInfo>
                        <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2006/12/xml-c14n11"/>
                        <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"/>
                        <ds:Reference Id="invoiceSignedData" URI="">
                            <ds:Transforms>
                                <ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
                                    <ds:XPath>not(//ancestor-or-self::ext:UBLExtensions)</ds:XPath>
                                </ds:Transform>
                                <ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
                                    <ds:XPath>not(//ancestor-or-self::cac:Signature)</ds:XPath>
                                </ds:Transform>
                                <ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
                                    <ds:XPath>not(//ancestor-or-self::cac:AdditionalDocumentReference[cbc:ID='QR'])</ds:XPath>
                                </ds:Transform>
                                <ds:Transform Algorithm="http://www.w3.org/2006/12/xml-c14n11"/>
                            </ds:Transforms>
                            <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
                            <ds:DigestValue>/DiLhcInApY9XbJ61SzDFOQWU7368gv93F3BfiknsVg=</ds:DigestValue>
                        </ds:Reference>
                        <ds:Reference Type="http://www.w3.org/2000/09/xmldsig#SignatureProperties" URI="#xadesSignedProperties">
                            <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
                            <ds:DigestValue>Y2RiZGQwOGY0NzY5ZWI5OWQyZGQwOTRmYzhkMDY4OTBiOWY4YTE0YWEzNDE2MGFkMjcxNDM5MzllYjY2NWIyNw==</ds:DigestValue>
                        </ds:Reference>
                    </ds:SignedInfo>
                    <ds:SignatureValue>MEQCIEV241OZRsw66OUXokZhEiViAJ0OuIa6N0P/OC5s8BEHAiB7fnEGB5ve1BlENvEwq2SDx9qr8Mi0DvIiqMQVgaxd1A==</ds:SignatureValue>
                    <ds:KeyInfo>
                        <ds:X509Data>
                            <ds:X509Certificate>MIICIjCCAcigAwIBAgIGAZVDG6DKMAoGCCqGSM49BAMCMBUxEzARBgNVBAMMCmVJbnZvaWNpbmcwHhcNMjUwMjI2MTYzMzUzWhcNMzAwMjI1MjEwMDAwWjBzMRkwFwYDVQQDDBBCRVRUIEFMLUhBUkFGSU9OMTQwMgYDVQQKDCtCRVRUIEFMLUhBUkFGSU9OIEZvciBJbmZvcm1hdGlvbiBUZWNobm9sb2d5MRMwEQYDVQQLDAozMTA5NjY5NDk4MQswCQYDVQQGEwJTQTBWMBAGByqGSM49AgEGBSuBBAAKA0IABIkeXELCDB/hcbVq4SerRhUQyjJWg+8ljTcexgUwxIZ0PwbYa2dVyqwcpXRKTUWgGDnjcpTn9zr9WBRUyGnsnJ6jgagwgaUwDAYDVR0TAQH/BAIwADCBlAYDVR0RBIGMMIGJpIGGMIGDMR0wGwYDVQQEDBQxLWdhc2FibGV8Mi1hcGl8My12MTEfMB0GCgmSJomT8ixkAQEMDzMxMDk2Njk0OTgwMDAwMzENMAsGA1UEDAwEMTEwMDERMA8GA1UEGgwIUkhZQTgzMDQxHzAdBgNVBA8MFkluZm9ybWF0aW9uIFRlY2hub2xvZ3kwCgYIKoZIzj0EAwIDSAAwRQIgLQtDqleZnPnVqF6ZODwodVuZ8miMcXYvCKwrC+xaGqoCIQDRU5LJgEvcubFsy21Oce627K0jidzI/j6O6YuyAfQjKA==</ds:X509Certificate>
                        </ds:X509Data>
                    </ds:KeyInfo>
                    <ds:Object>
                        <xades:QualifyingProperties xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" Target="signature">
                            <xades:SignedProperties Id="xadesSignedProperties">
                                <xades:SignedSignatureProperties>
                                    <xades:SigningTime>2025-02-27T18:55:00</xades:SigningTime>
                                    <xades:SigningCertificate>
                                        <xades:Cert>
                                            <xades:CertDigest>
                                                <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
                                                <ds:DigestValue>OTJjNzQ4MjU2ZjViNjAwYmIxMzcwYTNlMDNiZDkzZTNkYjBmNjY3ZGQ4M2I0MTY2YmMzYWJhNzBmMWIyMjFlYg==</ds:DigestValue>
                                            </xades:CertDigest>
                                            <xades:IssuerSerial>
                                                <ds:X509IssuerName>CN=eInvoicing</ds:X509IssuerName>
                                                <ds:X509SerialNumber>1740587638986</ds:X509SerialNumber>
                                            </xades:IssuerSerial>
                                        </xades:Cert>
                                    </xades:SigningCertificate>
                                </xades:SignedSignatureProperties>
                            </xades:SignedProperties>
                        </xades:QualifyingProperties>
                    </ds:Object>
                </ds:Signature>
            </sac:SignatureInformation>
        </sig:UBLDocumentSignatures>
    </ext:ExtensionContent>
</ext:UBLExtension>
</ext:UBLExtensions>
    <cbc:ProfileID>reporting:1.0</cbc:ProfileID>
  <cbc:ID>35417</cbc:ID>
  <cbc:UUID>3555377b-97e0-476a-b382-a20c944432bc</cbc:UUID>
  <cbc:IssueDate>2025-02-27</cbc:IssueDate>
  <cbc:IssueTime>18:55:00</cbc:IssueTime>
  <cbc:InvoiceTypeCode name="0200000">388</cbc:InvoiceTypeCode>
  <cbc:DocumentCurrencyCode>SAR</cbc:DocumentCurrencyCode>
  <cbc:TaxCurrencyCode>SAR</cbc:TaxCurrencyCode>
  <cac:AdditionalDocumentReference>
    <cbc:ID>ICV</cbc:ID>
    <cbc:UUID>1</cbc:UUID>
  </cac:AdditionalDocumentReference>
  <cac:AdditionalDocumentReference>
    <cbc:ID>PIH</cbc:ID>
    <cac:Attachment>
      <cbc:EmbeddedDocumentBinaryObject mimeCode="text/plain" filename="base64">MA==</cbc:EmbeddedDocumentBinaryObject>
    </cac:Attachment>
  </cac:AdditionalDocumentReference>
  <cac:AdditionalDocumentReference>
        <cbc:ID>QR</cbc:ID>
        <cac:Attachment>
            <cbc:EmbeddedDocumentBinaryObject mimeCode="text/plain">AStCRVRUIEFMLUhBUkFGSU9OIEZvciBJbmZvcm1hdGlvbiBUZWNobm9sb2d5Ag8zMTA5NjY5NDk4MDAwMDMDFDIwMjUtMDItMjdUMTg6NTU6MDBaBAY0MDAuMDAFAzAuMAYsL0RpTGhjSW5BcFk5WGJKNjFTekRGT1FXVTczNjhndjkzRjNCZmlrbnNWZz0HYE1FUUNJRVYyNDFPWlJzdzY2T1VYb2taaEVpVmlBSjBPdUlhNk4wUC9PQzVzOEJFSEFpQjdmbkVHQjV2ZTFCbEVOdkV3cTJTRHg5cXI4TWkwRHZJaXFNUVZnYXhkMUE9PQhYMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEiR5cQsIMH+FxtWrhJ6tGFRDKMlaD7yWNNx7GBTDEhnQ/BthrZ1XKrByldEpNRaAYOeNylOf3Ov1YFFTIaeycnglHMEUCIC0LQ6pXmZz51ahemTg8KHVbmfJojHF2LwisKwvsWhqqAiEA0VOSyYBL3LmxbMttTnHutuytI4ncyP4+jumLsgH0Iyg=</cbc:EmbeddedDocumentBinaryObject>
        </cac:Attachment>
    </cac:AdditionalDocumentReference>
    <cac:Signature>
        <cbc:ID>urn:oasis:names:specification:ubl:signature:Invoice</cbc:ID>
        <cbc:SignatureMethod>urn:oasis:names:specification:ubl:dsig:enveloped:xades</cbc:SignatureMethod>
    </cac:Signature>
    <cac:AccountingSupplierParty>
    <cac:Party>
      <cac:PartyIdentification>
        <cbc:ID schemeID="CRN">310333333333333</cbc:ID>
      </cac:PartyIdentification>
      <cac:PostalAddress>
        <cbc:StreetName>Street Name</cbc:StreetName>
        <cbc:BuildingNumber>4180</cbc:BuildingNumber>
        <cbc:CitySubdivisionName>Almasiaf</cbc:CitySubdivisionName>
        <cbc:CityName>Riyadh</cbc:CityName>
        <cbc:PostalZone>12466</cbc:PostalZone>
        <cac:Country>
          <cbc:IdentificationCode>SA</cbc:IdentificationCode>
        </cac:Country>
      </cac:PostalAddress>
      <cac:PartyTaxScheme>
        <cbc:CompanyID>310333333333333</cbc:CompanyID>
        <cac:TaxScheme>
          <cbc:ID>VAT</cbc:ID>
        </cac:TaxScheme>
      </cac:PartyTaxScheme>
      <cac:PartyLegalEntity>
        <cbc:RegistrationName>Company Name</cbc:RegistrationName>
      </cac:PartyLegalEntity>
    </cac:Party>
  </cac:AccountingSupplierParty>
  <cac:AccountingCustomerParty>
    <cac:Party>
      <cac:PartyTaxScheme>
        <cac:TaxScheme>
          <cbc:ID>VAT</cbc:ID>
        </cac:TaxScheme>
      </cac:PartyTaxScheme>
    </cac:Party>
  </cac:AccountingCustomerParty>
  <cac:Delivery>
    <cbc:ActualDeliveryDate>2021-02-14</cbc:ActualDeliveryDate>
  </cac:Delivery>
  <cac:AllowanceCharge>
    <cbc:ChargeIndicator>false</cbc:ChargeIndicator>
    <cbc:AllowanceChargeReason>discount</cbc:AllowanceChargeReason>
    <cbc:Amount currencyID="SAR">0.00</cbc:Amount>
    <cac:TaxCategory>
      <cbc:ID schemeID="UN/ECE 5305" schemeAgencyID="6">S</cbc:ID>
      <cbc:Percent>15</cbc:Percent>
      <cac:TaxScheme>
        <cbc:ID schemeID="UN/ECE 5153" schemeAgencyID="6">VAT</cbc:ID>
      </cac:TaxScheme>
    </cac:TaxCategory>
  </cac:AllowanceCharge>
  <cac:TaxTotal>
    <cbc:TaxAmount currencyID="SAR">0.0</cbc:TaxAmount>
  </cac:TaxTotal>
  <cac:TaxTotal>
    <cbc:TaxAmount currencyID="SAR">0.00</cbc:TaxAmount>
    <cac:TaxSubtotal>
      <cbc:TaxableAmount currencyID="SAR">0.00</cbc:TaxableAmount>
      <cbc:TaxAmount currencyID="SAR">0.00</cbc:TaxAmount>
      <cac:TaxCategory>
        <cbc:ID schemeID="UN/ECE 5305" schemeAgencyID="6">S</cbc:ID>
        <cbc:Percent>15</cbc:Percent>
        <cac:TaxScheme>
          <cbc:ID schemeID="UN/ECE 5153" schemeAgencyID="6">VAT</cbc:ID>
        </cac:TaxScheme>
      </cac:TaxCategory>
    </cac:TaxSubtotal>
  </cac:TaxTotal>
  <cac:LegalMonetaryTotal>
    <cbc:LineExtensionAmount currencyID="SAR">400.00</cbc:LineExtensionAmount>
    <cbc:TaxExclusiveAmount currencyID="SAR">400.00</cbc:TaxExclusiveAmount>
    <cbc:TaxInclusiveAmount currencyID="SAR">400.00</cbc:TaxInclusiveAmount>
    <cbc:AllowanceTotalAmount currencyID="SAR">0.00</cbc:AllowanceTotalAmount>
    <cbc:ChargeTotalAmount currencyID="SAR">0.00</cbc:ChargeTotalAmount>
    <cbc:PrepaidAmount currencyID="SAR">0.00</cbc:PrepaidAmount>
    <cbc:PayableAmount currencyID="SAR">400.00</cbc:PayableAmount>
  </cac:LegalMonetaryTotal>
  <cac:InvoiceLine>
    <cbc:ID>1</cbc:ID>
    <cbc:InvoicedQuantity unitCode="PCE">1.000000</cbc:InvoicedQuantity>
    <cbc:LineExtensionAmount currencyID="SAR">400.00</cbc:LineExtensionAmount>
    <cac:TaxTotal>
      <cbc:TaxAmount currencyID="SAR">0.00</cbc:TaxAmount>
      <cbc:RoundingAmount currencyID="SAR">400.00</cbc:RoundingAmount>
    </cac:TaxTotal>
    <cac:Item>
      <cbc:Name>Product Name</cbc:Name>
      <cac:ClassifiedTaxCategory>
        <cbc:ID>Z</cbc:ID>
        <cbc:Percent>0.00</cbc:Percent>
        <cac:TaxScheme>
          <cbc:ID>VAT</cbc:ID>
        </cac:TaxScheme>
      </cac:ClassifiedTaxCategory>
    </cac:Item>
    <cac:Price>
      <cbc:PriceAmount currencyID="SAR">400.0000</cbc:PriceAmount>
      <cac:AllowanceCharge>
        <cbc:ChargeIndicator>true</cbc:ChargeIndicator>
        <cbc:AllowanceChargeReason>discount</cbc:AllowanceChargeReason>
        <cbc:Amount currencyID="SAR">0.00</cbc:Amount>
      </cac:AllowanceCharge>
    </cac:Price>
  </cac:InvoiceLine>
</Invoice>
@Saleh7
Copy link
Owner

Saleh7 commented Feb 27, 2025

Hi @sevaske

I'm working on it.

Wait a little while and I'll adjust everything. 👍🏽

@sevaske
Copy link
Contributor Author

sevaske commented Feb 27, 2025

Hi @Saleh7 thanks for your response.

Seems I missed this part in the documentation:

        ->setInvoiceType(1100)// # Four digits, each digit acting as a bool. The order is as follows: Standard Invoice, Simplified, future use, future use 

Does it mean that I need to generate an another one certificate for simplified invoices? Maybe it's the reason.

@Saleh7
Copy link
Owner

Saleh7 commented Feb 27, 2025

"1100" means that the certificate supports both standard and simplified invoices.

Maybe it's the reason.

No

Try changing the supplier and customer name and making it short

@sevaske
Copy link
Contributor Author

sevaske commented Mar 3, 2025

Hi @Saleh7
I see you did some changes there. Just tested simplified invoices from array and the invoice is valid. Well done 👍
Do you have any remaining things before releasing the new version, or is it ready to be used?

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

No branches or pull requests

2 participants