Skip to content
/ taxapi Public

a nodej interface for iranian tax api service.

License

Notifications You must be signed in to change notification settings

arna051/taxapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Iranian Tax Api (Version 1 only)

MIT License

INstall:

npm i taxapi

or use yarn:

yarn add taxapi

Table of contents

  1. Introduction
  2. What you need?
  3. Get Token
  4. Get Server Information
  5. Send Invoices
  6. Inquire Invoices
  7. Inquire Client Economic Code
  8. Inquire Fiscal ID
  9. Utils
  10. 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?

  1. Fiscal ID
  2. Private key
  3. 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

License

MIT

About

a nodej interface for iranian tax api service.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published