npm i taxapi
or use yarn:
yarn add taxapi
- Introduction
- What you need?
- Get Token
- Get Server Information
- Send Invoices
- Inquire Invoices
- Inquire Client Economic Code
- Inquire Fiscal ID
- Utils
- Types
you need to read the full documentry of the "Modian" version 1 tax Api PDF. the pdf is available from intamedia.ir
- Fiscal ID
- Private key
- Economic ID
also make sure that you have access to tax api from iranian ip address
import { TaxApiV1 } from "./v1";
const api = new TaxApiV1(
'[pem file path or content]',
'[fiscal id]',
'[economic id]',
'self-tsp'
);
const tokenResponse = await api.getToken();
const {expiresIn, token} = tokenResponse.result.data
import { TaxApiV1 } from "./v1";
const api = new TaxApiV1('[pem file path or content]', '[fiscal id]', '[economic id]', 'self-tsp');
const serverInformation = await api.getServerInformation();
const {publicKeys} = serverInformation.result.data;
const publicKey = publicKeys[0]
import { TaxApiV1 } from "./v1";
const api = new TaxApiV1('[pem file path or content]', '[fiscal id]', '[economic id]', 'self-tsp');
const response = await api.sendInvoiceNormal({
invoices: {
'[invoice-1-uid]': { ...},
'[invoice-2-uid]': { ...},
'[invoice-3-uid]': { ...},
...
},
publicKey,
token
retry: ['uid-of-retrying-invoice', ...],
});
response.result.forEach(invoiceResult => {
const uid = invoiceResult.uid;
// update invocie properties by uid
})
import { TaxApiV1 } from "./v1";
const api = new TaxApiV1('[pem file path or content]', '[fiscal id]', '[economic id]', 'self-tsp');
const response = await api.inquireByUID(token, ['uid-1', 'uid-2', ...]);
response.result.data.forEach(item => {
const status = item.status // SUCCESS | FAILED | PENDING | IN_PROGRESS
if(status === "FAILED") {
const errors: {code: string, message: string}[] = item.data.error
}
const uid = item.uid;
//update invoices in database
})
import { TaxApiV1 } from "./v1";
const api = new TaxApiV1('[pem file path or content]', '[fiscal id]', '[economic id]', 'self-tsp');
// no token needed
const response = await api.inquiryEconomicCode()
const {nameTrade, nationalId, taxpayerStatus} = response
import { TaxApiV1 } from "./v1";
const api = new TaxApiV1('[pem file path or content]', '[fiscal id]', '[economic id]', 'self-tsp');
const response = await api.getFiscalId(token)
const {economicCode, fiscalStatus, nameTrade, saleThreshold} = response.result.data
import { generateTaxId, getRandomSerialDecimal } from "taxapi";
// if your client doesn't provide initial serial number
const initialSerialNumber = getRandomSerialDecimal();
//replace new Date() with date object of invoice date
const taxid = generateTaxId('fiscalId', new Date(), initialSerialNumber)
//convert serial to taxApi serial
const inno = initialSerialNumber.toString(16).padStart(10, '0')
import { Version1, TaxApi_v1_InvoiceBody, TaxApi_v1_InvoiceHeader, TaxApi_v1_InvoicePayment } from "taxapi";
const header: TaxApi_v1_InvoiceHeader = {}
const body: TaxApi_v1_InvoiceBody = []
const payments: TaxApi_v1_InvoicePayment = []
const fullInvoice: Version1.TaxApiInvoice = {
header,
body,
payments: []
}
call us if you want to donate or need help:
09038719255