Skip to content

Reporting an Invoice

Omar Bahareth edited this page Oct 16, 2023 · 3 revisions

Overview

NOTE: The credentials you should use in this API call are the ones you got from generating a certificate.

Reporting an invoice means you are uploading it to ZATCA as an actual invoice that your business has issued.

Example

# 1. Construct the client
username = "your_binary_security_token"
password = "your_secret"

# Make sure to set environment to either :production, :simulation, or :sandbox accordingly
client = ZATCA::Client.new(username: username, password: password, environment: :simulation)

# 2. Send the invoice to ZATCA
# Assuming you have already constructed a ZATCA::UBL::Invoice
response = client.report_invoice(
  invoice: invoice.to_base64,
  invoice_hash: invoice.generate_hash,
  uuid: invoice.uuid,

  # This can be true or false, I'm not sure what it means but I think it means whether it's signed or not
  cleared: true 
)

# TODO: Show response example

ZATCA Documentation

Here's how ZATCA's documentation describes this action:

Reports a single SIMPLIFIED invoice, credit note, or debit note. Specifically, it accepts simplified invoice, credit note, or debit note encoded in base64 and validates it to ensure:

  • Compliance to the UBL2 XSD.
  • EN 16931 Rules set.
  • KSA Specific Rules set.
  • KSA Rules set will override EN 16931 Rules set in case the same rule exists in both sets. QR Code validation
  • Cryptographical Stamp validation
  • Previous Invoice Hash Validation (PIH)