taxapi
v1.1.0
Published
A Node.js module for Iranian tax API (سامانه مودیان مالیاتی)
Downloads
12
Maintainers
Readme
Iranian Tax Api (Version 1 only)
INstall:
npm i taxapi
or use yarn:
yarn add taxapi
Table of contents
- Introduction
- What you need?
- Get Token
- Get Server Information
- Send Invoices
- Inquire Invoices
- Inquire Client Economic Code
- Inquire Fiscal ID
- Utils
- Types
Introduction
you need to read the full documentry of the "Modian" version 1 tax Api PDF. the pdf is available from intamedia.ir
this package is only for Nodejs not Browser.
What you need?
- Fiscal ID
- Private key
- Economic ID
also make sure that you have access to tax api from iranian ip address
Get Token
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
Get Server Information
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]
Send Invoices
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
})
Inquire Invoices
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
})
Inquire Client Economic Code
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
Inquire Fiscal ID
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
Utils
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')
Types
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: []
}
Need Help? or want to donate?
call us if you want to donate or need help:
09038719255