Skip to content

Invoice payload ​

The same payload format is used by Zatca::b2c(), Zatca::b2b(), corrections and the HTTP API. Keys are snake_case. Amounts are decimal strings (numbers are accepted); prices exclude VAT.

Device, workflow and notes are not payload fields

  • Device: passed separately: issue($payload, ['device' => $id]) in PHP, or X-Zatca-Device / "device" in the HTTP API. The seller (name, VAT number, address) comes from the device.
  • B2C or B2B: chosen by the call (Zatca::b2c() / Zatca::b2b(), or /b2c/invoices / /b2b/invoices), not by a type code in the payload.
  • Credit / debit notes and cancellation: separate calls on the original invoice, see Credit and debit notes and Cancelling invoices.
  • VAT category per line: see Lines and VAT exemption codes.

Minimal B2C invoice ​

php
[
    'invoice_number' => 'POS-000123',
    'lines' => [
        ['name' => 'Coffee', 'quantity' => '2', 'unit_price' => '12.50', 'vat_category' => 'S', 'vat_rate' => '15'],
    ],
]

Minimal B2B invoice ​

php
[
    'invoice_number' => 'INV-2026-0042',
    'supply_date' => '2026-11-01',
    'buyer' => [
        'name' => 'Fatoora Samples LTD',
        'vat_number' => '399999999800003',
        'address' => [
            'street' => 'Salah Al-Din', 'building_number' => '1111', 'district' => 'Al-Murooj',
            'city' => 'Riyadh', 'postal_code' => '12222', 'country' => 'SA',
        ],
    ],
    'lines' => [
        ['name' => 'Consulting', 'quantity' => '10', 'unit_price' => '500.00', 'unit_code' => 'HUR', 'vat_category' => 'S', 'vat_rate' => '15'],
    ],
]

Document fields ​

FieldRequiredDescription
invoice_numberYesYour invoice number (IRN). Also the default idempotency key
external_invoice_idNoIdempotency key if different from invoice_number (max 191 characters)
typeNoinvoice (default, 388), credit_note (381), debit_note (383). Use the notes API for notes
issued_atNoISO 8601 date-time. Without an offset it is read as Asia/Riyadh time. Default: now. Must not be in the future
currencyNoSAR (only SAR is supported)
payment_means_codeNoUNTDID 4461 code: 10 cash (default), 30 credit, 42 bank transfer, 48 card
supply_dateB2B: recommendedActual delivery date (YYYY-MM-DD)
supply_end_dateNoEnd of the supply period. Requires supply_date
subtypeNoFlags: third_party, nominal, export, summary, self_billed (true/false)
notesNoList of free-text notes
billing_referenceNotes onlyOriginal invoice number. Set automatically by creditNote() / debitNote()
reasonNotes onlyReason for the note (KSA-10). Set automatically by the notes API
sellerIgnoredAlways taken from the device's registered taxpayer
uuid, icv, counter, pih, invoice_hash, qrIgnoredAssigned by the package

Buyer ​

Optional for B2C, required for B2B.

FieldDescription
nameBuyer name (B2B: required)
vat_number15 digits, starting and ending with 3. Must differ from the seller's
identification.scheme / identification.valueOther buyer ID when there is no VAT number
address.street, building_number, district, city, postal_code, countrySaudi address: building number 4 digits, postal code 5 digits. country is ISO alpha-2

Buyer ID schemes: TIN (tax ID), CRN (commercial registration), MOM (MOMRAH licence), MLS (MHRSD licence), 700 (700 number), SAG (MISA licence), NAT (national ID), GCC (GCC ID), IQA (Iqama), PAS (passport), OTH (other).

For B2B the buyer needs a VAT number or another ID (rule BR-KSA-81). ZATCA treats a missing ID as a warning; the package rejects it before signing by default (zatca.b2b.require_buyer_identification).

Lines ​

FieldRequiredDescription
nameYesItem name
quantityYesPositive decimal
unit_priceYesNet unit price, excluding VAT
unit_codeNoUN/ECE rec 20 unit, default PCE (piece). Examples: HUR hour, KGM kilogram
item_code / skuNoYour item code (stored in the lines table; not sent to ZATCA)
discountNoDiscount per unit (price discount, BT-147). Net unit price = unit_price − discount
discountsNoLine discounts as totals for the line (one or more): see Discounts
vat_categoryYesS standard, Z zero-rated, E exempt, O out of scope
vat_rateYesPercentage: 15 (not 0.15). 0 for Z, E and O
exemption_reason_codeZ, E, OVATEX-… code (see below)
exemption_reasonZ, E, OReason text

VAT exemption codes ​

CategoryAllowed codes
Z zero-ratedVATEX-SA-32, VATEX-SA-33, VATEX-SA-34-1 … VATEX-SA-34-5, VATEX-SA-35, VATEX-SA-36, VATEX-SA-EDU, VATEX-SA-HEA, VATEX-SA-MLTRY
E exemptVATEX-SA-29, VATEX-SA-29-7, VATEX-SA-30
O out of scopeVATEX-SA-OOS

VATEX-SA-EDU and VATEX-SA-HEA on a simplified invoice require the buyer's national ID (identification.scheme = NAT).

Missing VAT category ​

If vat_category is missing and vat_rate is 15, S is assumed and a warning INFERRED is returned (zatca.b2c.infer_standard_vat_category). A missing category with rate 0 is always an error, because 0 % can mean zero-rated, exempt or out of scope.

Discounts ​

There are three kinds. All of them can be combined on one invoice.

KindWhereMeaningXML
Unit discountlines[].discountAmount off each unitcac:Price/cac:AllowanceCharge (BT-147)
Line discountlines[].discounts[]Amount or % off the line totalcac:InvoiceLine/cac:AllowanceCharge (BG-27)
Header discountallowances[]Amount or % off the whole invoice (per VAT group)cac:AllowanceCharge (BG-20)

Line discounts ​

php
'lines' => [[
    'name' => 'Shirt', 'quantity' => '3', 'unit_price' => '100.00', 'vat_category' => 'S', 'vat_rate' => '15',
    'discounts' => [
        ['amount' => '20.00', 'reason' => 'Promotion'],
        ['percent' => '10', 'reason' => 'Member discount', 'reason_code' => '95'],
    ],
]],

Each entry has amount or percent (0–100, up to 2 decimals), and a reason and/or reason_code (UNTDID 5189, e.g. 95 discount). A percentage is calculated from the line amount (quantity × net unit price) unless you send base_amount. If you send both percent and amount, the amount must equal base × percent (rule BR-KSA-EN16931-03). The discounts of a line may not exceed the line amount.

The discounts shape is the one used by the zatca-xml-js library, so payloads built for it can be sent as they are. Unlike that library, the package writes them as line allowances (what the ZATCA standard defines for line-total discounts) and rounds half-up instead of truncating.

Header (document) discounts and charges ​

php
'allowances' => [
    ['amount' => '5.00', 'reason' => 'Loyalty discount', 'vat_category' => 'S', 'vat_rate' => '15'],
    ['percent' => '2.5', 'reason' => 'Early payment', 'vat_category' => 'S', 'vat_rate' => '15'],
],
'charges' => [
    ['amount' => '10.00', 'reason' => 'Delivery', 'reason_code' => 'FC', 'vat_category' => 'S', 'vat_rate' => '15'],
],

Each needs amount or percent, a reason or reason_code, and the VAT category and rate it applies to. A percent without base_amount is calculated from the net total of the lines in that VAT group.

Mixed VAT rates. ZATCA needs each document allowance to belong to one VAT group. If your discount is for the whole basket, send 'distribute' => true instead of vat_category/vat_rate: the package splits it over the VAT groups in proportion to their net amounts (an amount is split pro rata with the last halala on the last group; a percentage is applied to each group). This produces one allowance per group.

php
'allowances' => [['amount' => '33.33', 'reason' => 'Voucher', 'distribute' => true]],

How totals are calculated ​

  • All arithmetic is exact decimal arithmetic (no floating point), rounded half-up to 2 decimals.
  • Line amount = quantity × (unit price − unit discount), rounded; line net = line amount − line discounts.
  • Invoice net = sum of line nets − header allowances + header charges.
  • VAT is calculated per VAT group (category + rate + exemption code) on the group total, and a VAT breakdown is always written.
  • The totals you see in the response and in the database (total_excl_vat, vat_total, total_incl_vat) are the ones in the signed XML.

Not supported yet ​

  • prepaid_amount (advance payment adjustments) is rejected with code UNSUPPORTED.
  • Currencies other than SAR.

Validation ​

All problems are reported at once, each with the field path and the ZATCA rule ID where one applies:

json
{
  "status": false,
  "message": "validation failed",
  "errors": [
    {"field": "lines.0.vat_category", "code": "BR-KSA-CL-04", "message": "Category Z requires an exemption reason code (VATEX-SA-32, ...)."},
    {"field": "buyer.address.postal_code", "code": "BR-KSA-67", "message": "Saudi postal codes have exactly 5 digits."}
  ]
}

To validate without creating anything:

php
$result = Zatca::b2c()->validate($payload);
$result->isValid();
$result->errors();
$result->warnings();

See the full list in Validation rules.

Not affiliated with or endorsed by ZATCA. Verify regulatory requirements with ZATCA and your tax advisor.