Skip to content

Clearing an Invoice

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

Overview

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

Clearing an invoice means you are telling ZATCA an invoice is settled or paid.

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.clear_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
  cleared: true 
)

# TODO: Show response example

ZATCA Documentation

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

Clears a single Standard invoice, credit note, or debit note. Specifically, it accepts standard invoice, credit note, or debit note encoded in base64 and validates it to ensure the below. On successful validation, the API then signs the invoice, applies a QR code and returns back.

  • 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 (if any)
  • Cryptographical Stamp validation (if any)
  • Previous Invoice Hash Validation (PIH)