@axenda/zatca

中文文档
1.0.4发布于 2021/11/20MITTypeScriptCommonJS近 30 天下载 1.5万

NPM

原始使用文档
文档目录13 节
  1. Installation
  2. Usage
  3. Summary
  4. Import
  5. Representing an invoice QR code
  6. Generate TLV
  7. Generate Base64
  8. Render QR code
  9. Use QR code image data
  10. Tests
  11. Package roadmap
  12. Contributing
  13. License

ZATCA (Fatoorah) QR-Code Implementation

NPM

GitHub Workflow Status (branch) codecov GitHub License

An unofficial package to help developers implement ZATCA (Fatoora) QR code easily which is required for e-invoicing in Saudi Arabia.

✨ You could use it in both frontend and backend Nodejs projects.

✅ Validated to have the same output as ZATCA's SDK as of 18 November 2021.

Installation

To get started, install the package:

npm i --save @axenda/zatca

Usage

Summary

Simple, all you need to generate a QR code is:

import { Invoice } from '@axenda/zatca';

const invoice = new Invoice({
    sellerName: 'Axenda',
    vatRegistrationNumber: '1234567891',
    invoiceTimestamp: '2021-12-04T00:00:00Z',
    invoiceTotal: '100.00',
    invoiceVatTotal: '15.00',
});

const imageData = await invoice.render();

// Read the following sections for more details.

Import

First, import Invoice class or Tag class to represent an invoice QR code:

import { Invoice } from '@axenda/zatca';
// or
import { Tag } from '@axenda/zatca';

Representing an invoice QR code

Second, create an instance of Invoice or an array of Tag class:

const invoice = new Invoice({
    sellerName: 'Axenda',
    vatRegistrationNumber: '1234567891',
    invoiceTimestamp: '2021-12-04T00:00:00Z',
    invoiceTotal: '100.00',
    invoiceVatTotal: '15.00',
});
// or
const tags: Tag[] = [
    new Tag(1, 'Axenda'),
    new Tag(2, '1234567891'),
    new Tag(3, '2021-12-04T00:00:00Z'),
    new Tag(4, '100.00'),
    new Tag(5, '15.00'),
];

Generate TLV

Now you can generate TLV string from the invoice or from the tags array:

invoice.toTlv();

// or using tags array

import { toTlv } from '@axenda/zatca';

toTlv(tags)

Generate Base64

You cloud generate Base64 string from the invoice or from the tags array:

invoice.toBase64();

// or using tags array

import { tagsToBase64 } from '@axenda/zatca';

tagsToBase64(tags);

Render QR code

You can generate image data (png) from base64 string and render it in browser:

await invoice.render();

// or using tags array

import { renderTags } from '@axenda/zatca';

await renderTags(tags);

Use QR code image data

Use the image data to display the QR code in browser:

<!-- For React -->
<img src={imageData} alt="Invoice QR Code">
<!-- For Angular -->
<img [src]="imageData"/>
<!-- Just use the imageData variable no matter what framework you use  -->

Tests

To run test suites, first install dependencies, then run npm test:

npm install
npm test

Package roadmap

  • Support ZATCA invoice QR code phase 1
  • Review package API consistency
  • Support ZATCA invoice QR code phase 2

Contributing

We welcome contributions of all kinds from anyone. Please take a moment to review the guidelines for contributing.

License

The MIT License (MIT). Please see License File for more information.

版本与发布记录

@axenda/zatca 共发布 5 个版本,首次发布于 2021/11/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.4latest2021/11/204 年前
1.0.32021/11/204 年前
1.0.22021/11/204 年前
1.0.12021/11/194 年前
1.0.02021/11/194 年前

关于 @axenda/zatca 的常见问题

如何安装 @axenda/zatca?

在项目目录运行 npm install @axenda/zatca,或使用 pnpm add / yarn add / bun add。

@axenda/zatca 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@axenda/zatca 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@axenda/zatca 可以商用吗?

@axenda/zatca 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@axenda/zatca 的下载量有多少?

根据 npm 官方下载统计,@axenda/zatca 在 2026/10/08 – 2026/11/06 这 30 天内被下载 15,202 次,日均约 507 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@axenda/zatca 还在维护吗?

最新版本 1.0.4 发布于 2021/11/20(4 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/11/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。