Replies: 2 comments 2 replies
-
i am using sandbox sdk certificates. here is my test_construct_invoice.rb code require 'zatca' puts "zatca construct invoice started" 1. Setup the Invoice Values#=============================================================================== invoice_subtype = ZATCA::UBL::InvoiceSubtypeBuilder.build( payment_means_code = ZATCA::UBL::Invoice::PAYMENT_MEANS[:bank_card] # => "48" invoice_counter_value = "10" #=============================================================================== 2. Setup the Invoice's Nested Properties#=============================================================================== Create the supplier party (the party issuing the invoice, e.g. the seller)accounting_supplier_party = ZATCA::UBL::CommonAggregateComponents::Party.new( party_tax_scheme: ZATCA::UBL::CommonAggregateComponents::PartyTaxScheme.new( party_legal_entity: ZATCA::UBL::CommonAggregateComponents::PartyLegalEntity.new( Create the customer party (the party receiving the invoice, e.g. the buyer)accounting_customer_party = ZATCA::UBL::CommonAggregateComponents::Party.new( party_identification: ZATCA::UBL::CommonAggregateComponents::PartyIdentification.new(id: "2345",scheme_id: "NAT"),party_identification: nil, party_tax_scheme: ZATCA::UBL::CommonAggregateComponents::PartyTaxScheme.new, Create the (optional) delivery object (detailing the delivery date and time)delivery = ZATCA::UBL::CommonAggregateComponents::Delivery.new(actual_delivery_date: "2022-03-13",latest_delivery_date: "2022-03-15")delivery = nil Create the allowance charges (e.g. discounts) for the invoiceallowance_charges = [ Create the tax totals for the invoiceZATCA's official valid sample has two of these, not sure whytax_totals = [ Create the legal monetary total for the invoicelegal_monetary_total = ZATCA::UBL::CommonAggregateComponents::LegalMonetaryTotal.new( Create the invoice lines for the invoice (the list of items that were sold)invoice_lines = [ BookZATCA::UBL::CommonAggregateComponents::InvoiceLine.new(
), PenZATCA::UBL::CommonAggregateComponents::InvoiceLine.new( #=============================================================================== 3. Construct the Invoice#=============================================================================== Construct the invoice using all of the aboveinvoice = ZATCA::UBL::Invoice.new( NOTE: For credit or debit notes you must also fill outinvoice.instruction_note with an explanation on whythis note was issued.#=============================================================================== 4. Sign the Invoice (ONLY FOR SIMPLIFIED INVOICES)#=============================================================================== Must not be encoded in Base64 and must have header blocksprivate_key_path = "ec-secp256k1-priv-key.pem" Must be in pem format with header blockscertificate_path = "cert.pem" You can omit this if you don't need to customize it,the default value is the same as you see here.signing_time = Time.now.utc.strftime("#{invoice.issue_date}T#{invoice.issue_time}") Sign the invoice (this adds a couple of new elements to the invoice)invoice.sign( See the section under this code block if you need morecontrol over the signing process.#=============================================================================== 5. Create the QR Code (ONLY FOR SIMPLIFIED INVOICES)#=============================================================================== Setup values used in tagsinvoice_hash = invoice.generate_hash Create the tagstags = ZATCA::Tags.new({
Turn the tags to TLV and then encode that TLV to base64invoice.qr_code = tags.to_base64 File.write("signed_invoice.xml", invoice.to_xml) puts "finish" |
Beta Was this translation helpful? Give feedback.
-
i copied the code from here: https://github.com/mrsool/zatca/wiki/Constructing-a-Simplified-Invoice here is command to validate file. gem code is generating wrong values, or might be i am doing somthing wrong. |
Beta Was this translation helpful? Give feedback.
-
getting this errors: fatoora -validate -invoice signed_invoice.xml
********** Welcome to ZATCA E-Invoice Java SDK 3.3.3 *********************
This SDK uses Java to call the SDK (jar) passing it an invoice XML file.
It can take a Standard or Simplified XML, Credit Note, or Debit Note.
It returns if the validation is successful or shows errors where the XML validation fails.
It checks for syntax and content as well.
You can use the command (fatoora -help) for more information.
2024-07-10 16:05:39,798 [ERROR] XsdValidator - Schema validation failed due to SAXParseException
2024-07-10 16:05:39,804 [INFO] ValidationProcessorImpl - [XSD] validation result : FAILED
2024-07-10 16:05:39,804 [ERROR] ValidationProcessorImpl - xsd validation errors :
2024-07-10 16:05:39,804 [ERROR] ValidationProcessorImpl - CODE : SAXParseException, MESSAGE : Schema validation failed; XML does not comply with UBL 2.1 standards in line with ZATCA specifications. ERROR 1: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 7; cvc-elt.1.a: Cannot find the declaration of element 'root'.
2024-07-10 16:05:40,701 [INFO] ValidationProcessorImpl - [EN] validation result : PASSED
2024-07-10 16:05:40,702 [ERROR] ValidationProcessorImpl - en validation warnings :
2024-07-10 16:05:40,702 [WARN] ValidationProcessorImpl - CODE : BR-CO-13, MESSAGE : [BR-CO-13]-Invoice total amount without VAT (BT-109) = Σ Invoice line net amount (BT-131) - Sum of allowances on document level (BT-107) + Sum of charges on document level (BT-108).
2024-07-10 16:05:41,052 [INFO] ValidationProcessorImpl - [KSA] validation result : PASSED
2024-07-10 16:05:41,100 [ERROR] QrGenerationService - failed to generate qr [unable to get seller name from invoice]
2024-07-10 16:05:41,101 [INFO] ValidationProcessorImpl - [QR] validation result : FAILED
2024-07-10 16:05:41,101 [ERROR] ValidationProcessorImpl - qr validation errors :
2024-07-10 16:05:41,101 [ERROR] ValidationProcessorImpl - CODE : QRCODE_INVALID, MESSAGE : Invalid QR code format, Please follow the ZATCA QR code specifications
2024-07-10 16:05:41,558 [ERROR] SignatureValidator - Error : null
2024-07-10 16:05:41,558 [INFO] ValidationProcessorImpl - [SIGNATURE] validation result : FAILED
2024-07-10 16:05:41,558 [ERROR] ValidationProcessorImpl - signature validation errors :
2024-07-10 16:05:41,558 [ERROR] ValidationProcessorImpl - CODE : invoiceSignedDataDigestValue, MESSAGE : wrong invoice hashing
2024-07-10 16:05:41,558 [ERROR] ValidationProcessorImpl - CODE : NullPointerException, MESSAGE : null
2024-07-10 16:05:41,558 [ERROR] ValidationProcessorImpl - CODE : signatureValue, MESSAGE : wrong signature Value
2024-07-10 16:05:41,563 [INFO] ValidationProcessorImpl - [PIH] validation result : FAILED
2024-07-10 16:05:41,563 [ERROR] ValidationProcessorImpl - pih validation errors :
2024-07-10 16:05:41,563 [ERROR] ValidationProcessorImpl - CODE : KSA-13, MESSAGE : PIH is inValid
2024-07-10 16:05:41,563 [INFO] InvoiceValidationService - *** GLOBAL VALIDATION RESULT = FAILED
Beta Was this translation helpful? Give feedback.
All reactions