node-tra-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

TRA SDK for Node

The TRA SDK for Node.js makes it easy for developers to access TRA API in their Javascript code, and build robust applications.

This package implements TRA (Tanzania Revenue Authority) APIs currently supporting VFD API only

Documentation

Take a look at the API docs here.

Features

  • VFD API
  • TypeScript support
  • Latest Node.js support
  • Data Validation

🚀 Usage

Installation

via npm

npm install node-tra-sdk

via Yarn

yarn add node-tra-sdk

Load key certificate

Before calling any APIs, you will need to load your key certificate. You can use this helper function to do so.

import { loadKeyCertificate } from 'node-tra-sdk';

const { key } = await loadKeyCertificate('YOUR_KEY_FILE PATH', 'YOUR_KEY_PASSWORD');

Registration

To get details about your company you need to call registration API. You call this once. You can reuse the result in the next steps.

import { sendRegistrationRequest } from 'node-tra-sdk';

//test environment details
const hostname = 'virtual.tra.go.tz';
const path = '/efdmsRctApi/api/vfdRegReq';

const response = await sendRegistrationRequest({
  tin: 'YOUR TIN',
  certKey: 'YOUR CERT KEY',
  signKey: key, // key loaded from first step
  certSerial: 'YOUR CERT SERIAL',
  hostname: hostname,
  path: path,
});

//if successful, response.success == true
const { success, data } = response;

Token

To upload receipts/invoices you will need to provide a token to TRA API. To get the token call this helper function.

import { sendTokenRequest } from 'node-tra-sdk';

//test environment details
const hostname = 'virtual.tra.go.tz';
const path = '/efdmsRctApi/vfdtoken';

const response = await sendTokenRequest({
  username: 'USERNAME_FROM_REGISTRATION_API',
  password: 'PASSWORD_FROM_REGISTRATION_API',
  grantType: 'password',
  hostname: hostname,
  path: path,
});

// if successful, response.success == true
const { success, data } = response;

Upload invoice/receipt

import { sendUploadInvoiceRequest } from 'node-tra-sdk';

//test environment details
const hostname = 'virtual.tra.go.tz';
const path = '/efdmsRctApi/api/efdmsRctInfo';

const response = await sendUploadInvoiceRequest({
  tin: 'YOUR TIN',
  signKey: key, // key loaded from first step
  certSerial: 'YOUR CERT SERIAL',
  token: 'YOUR TOKEN',
  routingKey: 'ROUTING KEY FROM REGISTRATION API',
  hostname: hostname,
  path: path,
  date: '2021-02-03',
  time: '20:52:53',
  regId: 'REGID_FROM_REGISTRATION_API',
  efdSerial: 'EFDSERIAL_FROM_REGISTRATION_API',
  receiptCode: 'RECEIPTCODE_FROM_REGISTRATION_API',
  rctNum: '10103',
  zNum: '20210203',
  dc: '1',
  gc: '10103',
  customerId: '',
  customerIdType: '6',
  customerName: 'John Doe',
  mobileNumber: '255755123123',
  items: [
    {
      ID: 1,
      DESC: 'Product 1',
      QTY: 1,
      TAXCODE: 1,
      AMT: '118000.00',
    },
  ],
  totals: {
    TOTALTAXEXCL: '100000.00',
    TOTALTAXINCL: '118000.00',
    DISCOUNT: '0.00',
  },
  payments: {
    PMTTYPE: 'EMONEY',
    PMTAMOUNT: '118000.00',
  },
  vatTotals: {
    VATRATE: 'A',
    NETTAMOUNT: '100000.00',
    TAXAMOUNT: '18000.00',
  },
});

// If successful, response.success == true
const { success, data } = response;

📚 References

📝 License

This project is licensed under the MIT License.

🙌 Credits

Dependents (0)

Package Sidebar

Install

npm i node-tra-sdk

Weekly Downloads

6

Version

0.1.4

License

MIT

Unpacked Size

342 kB

Total Files

30

Last publish

Collaborators

  • alphao