Skip to main content

Issue Vietnamese e-invoices (hóa đơn điện tử) through an API

Ha Tang issues e-invoices under your tax code through your own account at your e-invoice provider (see the full guide for the supported providers). Connect the account once in Payments settings → Invoice providers, then either add an invoice block to a payment, so the invoice is issued once the order is paid, or create one on its own.

With the payment (issued when it is paid)

import { Hatang } from "@hatang/sdk";

const hatang = new Hatang(); // HATANG_API_KEY with payments:write

const { data: payment, error } = await hatang.payments.createOrder({
order_id: "SO-1002",
amount: 275_000,
ipn_url: "https://shop.example.com/api/hatang/ipn",
invoice: {
mode: "publish",
buyer: { name: "Nguyen Van Khach", tax_code: "0109876543", email: "[email protected]" },
items: [{ name: "September service plan", quantity: 1, unit_price: 250_000, vat_rate: 10 }],
},
});

The IPN and payments.get carry the invoice's status and number (payment.invoice).

On its own, for example for a bank transfer received without an order

const { data: invoice, error } = await hatang.einvoices.create({
mode: "publish",
transaction_id: "txn_123",
buyer: { name: "Nguyen Van Khach" },
items: [{ name: "Coffee beans 1 kg", quantity: 1, unit_price: 91_667, vat_rate: 8 }],
});

In development, connect the provider's demo account: the invoices are real sandbox invoices but never reach the tax office.

Go further​

View this page as Markdown