How to create invoice hash dose invalid request refers to

How can i create the invoice hash also i built a xml payload when i submit it i get invalid request

builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
  xml.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'
  ) do
    xml['cbc'].ProfileID 'reporting:1.0'
    xml['cbc'].ID '2021/02/12/1230'
    xml['cbc'].UUID '3cf5ee18-ee25-44ea-a444-2c37ba7f28be'
    xml['cbc'].IssueDate '2021-02-25'
    xml['cbc'].IssueTime '16:55:24'
    xml['cbc'].InvoiceTypeCode '380'
    xml['cbc'].InvoiceTypeCode('010100', name: '010100')
    xml['cbc'].Note 'Unstructured text'
    xml['cbc'].DocumentCurrencyCode 'SAR'
    xml['cbc'].TaxCurrencyCode 'SAR'
    
    xml['cac'].OrderReference do
      xml['cbc'].ID '161313031'
    end
    
    xml['cac'].BillingReference do
      xml['cac'].InvoiceDocumentReference do
        xml['cbc'].ID '156166151'
      end
    end
    
    xml['cac'].ContractDocumentReference do
      xml['cbc'].ID '161313031'
    end
    
    xml['cac'].AdditionalDocumentReference do
      xml['cbc'].ID 'ICV'
      xml['cbc'].UUID '46531'
    end
    
    xml['cac'].AdditionalDocumentReference do
      xml['cbc'].ID 'PIH'
      xml['cac'].Attachment do
        xml['cbc'].EmbeddedDocumentBinaryObject(
          'NWZlY2ViNjZmZmM4NmYzOGQ5NTI3ODZjNmQ2OTZjNzljMmRiYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2ZiNTdlOQ==',
          mimeCode: 'text/plain'
        )
      end
    end
    
    xml['cac'].AccountingSupplierParty do
      xml['cac'].Party do
        xml['cac'].PartyIdentification do
          xml['cbc'].ID('456789123', schemeID: 'CRN')
        end
        xml['cac'].PostalAddress do
          xml['cbc'].StreetName 'Main street 1'
          xml['cbc'].CityName 'Riyadh'
          xml['cbc'].PostalZone '72415'
          xml['cbc'].CountrySubentity 'Riyadh Region'
          xml['cbc'].CitySubdivisionName 'District A'
          xml['cac'].Country do
            xml['cbc'].IdentificationCode 'SA'
          end
        end
        xml['cac'].PartyTaxScheme do
          xml['cbc'].CompanyID '3xxxxxxxxx00003'
          xml['cac'].TaxScheme do
            xml['cbc'].ID 'VAT'
          end
        end
        xml['cac'].PartyLegalEntity do
          xml['cbc'].RegistrationName 'SELLER SA'
        end
      end
    end
    
    xml['cac'].AccountingCustomerParty do
      xml['cac'].Party do
        xml['cac'].PartyIdentification do
          xml['cbc'].ID('456789123', schemeID: 'CRN')
        end
        xml['cac'].PostalAddress do
          xml['cbc'].StreetName 'Main street 1'
          xml['cbc'].AdditionalStreetName 'PO Box 14'
          xml['cbc'].CityName 'Riyadh'
          xml['cbc'].CountrySubentity 'Riyadh Region'
          xml['cbc'].CitySubdivisionName 'District B'
          xml['cac'].Country do
            xml['cbc'].IdentificationCode 'SA'
          end
        end
        xml['cac'].PartyTaxScheme do
          xml['cbc'].CompanyID '3xxxxxxxxx00003'
          xml['cac'].TaxScheme do
            xml['cbc'].ID 'VAT'
          end
        end
        xml['cac'].PartyLegalEntity do
          xml['cbc'].RegistrationName 'BUYER SA'
        end
      end
    end
    
    xml['cac'].Delivery do
      xml['cbc'].ActualDeliveryDate '2021-02-26'
      xml['cbc'].LatestDeliveryDate '2021-02-26'
    end
    
    xml['cac'].PaymentMeans do
      xml['cbc'].PaymentMeansCode '30'
      xml['cbc'].InstructionNote 'Cancellation or suspension of the supplies after its occurrence either wholly or partially'
      xml['cac'].PayeeFinancialAccount do
        xml['cbc'].ID 'SA000000000000001'
        xml['cbc'].PaymentNote 'Payment by credit'
      end
    end
    
    xml['cac'].AllowanceCharge do
      xml['cbc'].ChargeIndicator 'false'
      xml['cbc'].MultiplierFactorNumeric '20'
      xml['cbc'].Amount '24', currencyID: 'SAR'
      xml['cbc'].BaseAmount '120', currencyID: 'SAR'
      xml['cac'].TaxCategory do
        xml['cbc'].ID 'S'
        xml['cbc'].Percent '20'
        xml['cac'].TaxScheme do
          xml['cbc'].ID 'VAT'
        end
      end
    end
    
    xml['cac'].TaxTotal do
      xml['cbc'].TaxAmount '800.00', currencyID: 'SAR'
      xml['cac'].TaxSubtotal do
        xml['cbc'].TaxableAmount '200', currencyID: 'SAR'
        xml['cbc'].TaxAmount '40', currencyID: 'SAR'
        xml['cac'].TaxCategory do
          xml['cbc'].ID 'S'
          xml['cbc'].Percent '20.00'
          xml['cbc'].TaxExemptionReason 'Exemption reason'
          xml['cac'].TaxScheme do
            xml['cbc'].ID 'VAT'
          end
        end
      end
    end
    
    xml['cac'].LegalMonetaryTotal do
      xml['cbc'].LineExtensionAmount '4200.00', currencyID: 'SAR'
      xml['cbc'].TaxExclusiveAmount '4000.00', currencyID: 'SAR'
      xml['cbc'].TaxInclusiveAmount '4800.00', currencyID: 'SAR'
      xml['cbc'].AllowanceTotalAmount '300', currencyID: 'SAR'
      xml['cbc'].PrepaidAmount '100', currencyID: 'SAR'
      xml['cbc'].PayableAmount '4701.52', currencyID: 'SAR'
    end
    
    xml['cac'].InvoiceLine do
      xml['cbc'].ID '1'
      xml['cbc'].InvoicedQuantity '4', unitCode: 'PCE'
      xml['cbc'].LineExtensionAmount '2000', currencyID: 'SAR'
      xml['cac'].AllowanceCharge do
        xml['cbc'].ChargeIndicator 'false'
        xml['cbc'].MultiplierFactorNumeric '20.000000'
        xml['cbc'].Amount '24.34', currencyID: 'SAR'
        xml['cbc'].BaseAmount '120.34', currencyID: 'SAR'
      end
      xml['cac'].TaxTotal do
        xml['cbc'].TaxAmount '20.04', currencyID: 'SAR'
        xml['cbc'].RoundingAmount '20.04', currencyID: 'SAR'
      end
      xml['cac'].Item do
        xml['cbc'].Name 'Item name'
        xml['cac'].BuyersItemIdentification do
          xml['cbc'].ID '1234567'
        end
        xml['cac'].SellersItemIdentification do
          xml['cbc'].ID '123456'
        end
        xml['cac'].StandardItemIdentification do
          xml['cbc'].ID '1234567891234'
        end
        xml['cac'].ClassifiedTaxCategory do
          xml['cbc'].ID 'S'
          xml['cbc'].Percent '20'
          xml['cac'].TaxScheme do
            xml['cbc'].ID 'VAT'
          end
        end
      end
      xml['cac'].Price do
        xml['cbc'].PriceAmount '50.24', currencyID: 'SAR'
        xml['cbc'].BaseQuantity '1', unitCode: 'PCE'
        xml['cac'].AllowanceCharge do
          xml['cbc'].ChargeIndicator 'false'
          xml['cbc'].Amount '10', currencyID: 'SAR'
          xml['cbc'].BaseAmount '60.25', currencyID: 'SAR'
        end
      end
    end
  end
end

Dear @test97 ,

Thank you for reaching out and welcome to our community.

Kindly note that for standards invoices, you can create the hash using ZATCA’s SDK by running the following command:

Java SDK: Fatoora -generateHash -invoice “invoice.xml path"
.Net SDK: Fatooranet generateHash -invoice “invoice.xml path”

Moreover, for simplified invoices, the singing process will generate the invoice hash, you can sign your invoices using the SDK by running the below command:

Java SDK: Fatoora -sign -invoice “invoice.xml path”
.Net SDK: Fatooranet sign -invoice “invoice.xml path”

Thanks,

Hey Lalomar
Thank you for your assistance,
iam using sandbox in order to integrate with ZATCA
is there any way to create the invoice hash without using the SDK?

Are you using Sandbox to obtain the certificate? kindly note that the sandbox is meant to be used for testing purposes only, and the Data in the sandbox portal is dummy data that should be used to understand the steps that need to be followed to ensure a successful onboarding. Therefore, you need to obtain your own certificate, you can use the simulation environment to obtain your own certificate and test your solution before integrating it with the production environment.