1.0.0-beta • Published 5 years ago

nav-client-node v1.0.0-beta

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

nav-client-node

Node.js client module which provides an interface for communicating with ANGRO NAV CLOUD invoice services.

This module was developed in order to satisfy the following specification:
Online invoice interface specification

Installation

Tested with version 12.13.1 of Node.js.

$ npm install @angro/nav-client-node

Example

const ApiClient = require("@angro/nav-client-node");

/* Your credentials */
const userId = "cc869f48-5f47-466c-ac8d-d1c015bab80c";
const secretToken = "eb19924b-0c15-4a1b-b301-ef178796f399";

/* Create the node client interface. */

const apiClient = new ApiClient(userId, secretToken);

const taxNumber = "12345676";
const taxPayerInfo = await apiClient.getTaxpayer({ taxNumber });

if (taxPayerInfo.errors.length) {
  //error
} else {
  //ok
}

API

ApiClient

Class representing the implementation of the ANGRO NAV cloud client

/**
 *
 * @param {string} userId - ID of your user
 * @param {string} secretToken - Corresponding secret token
 * @param {number} [params.timeout=70000] Axios default timeout integer in milliseconds.
 */
const apiClient = new ApiClient(userId, secretToken);

Set different axios timeout if needed

const apiClient = new ApiClient(userId, secretToken, 70000);

apiClient.getTaxpayer()

Method to get taxpayer information by tax number.
It resolves to an object containing taxpayerValidity and taxpayerData properties.

/**
 * Send request to ANGRO NAV CLOUD to return taxpayer information
 * @async
 * @param {Object} params Function params.
 * @param {string} params.taxNumber Taxpayer tax number to get information for.
 * @returns {Promise<Object>} Taxpayer information.
 */
const taxPayerInfo = await apiClient.getTaxpayer({ taxNumber });

apiClient.getInvoices()

Get all invoices associated with the user. It resolves to an object containing invoices and their invoice items if needed.

/**
 * Send request to ANGRO NAV CLOUD to return invoices information
 * @async
 * @param {Object} params Function params.
 * @param {boolean} [params.requestItems=false] If true, associated items will be returned with invoices
 * @returns {Promise<Object>} All invoices
 */
const invoices = await apiClient.getInvoices();

apiClient.getInvoice()

Get a specific invoice associated with the user. It resolves to an object containing the invoice and it's invoice items and data from NAV if needed

/**
 * Send request to ANGRO NAV CLOUD to return specific invoice information
 * @async
 * @param {Object} params Function params.
 * @param {string} params.id The id of the invoice
 * @param {boolean} [params.requestNavData=false] If true invoice data from NAV will be returned
 * @returns {Promise<Object>} Invoice information
 */

const id = "d70c7ff5-2d9a-41ce-8b14-d9cefed21bb7";
const invoice = await apiClient.getInvoice({ id });

apiClient.createInvoice()

Method to create an invoice. The method returns the id of the operation which can be used later to get the invoice of this request.

/**
 * Send request to create an invoice
 * @async
 * @param {Object} params Function params
 * @param {Invoice} params.invoice Invoice class instance
 * @returns {Promise<string>} Invoice id
 */

const invoice = await apiClient.createInvoice(newInvoice);

Example for invoice parameter:

const spinfo = {
  taxpayerId: "68845007",
  vatCode: "2",
  countyCode: "41",
  name: "ANGRO Kft.",
  countryCode: "HU",
  postalCode: "5600",
  city: "Békéscsaba",
  streetName: "Kétegyházi",
  publicPlaceCategory: "út.",
  number: "7"
};

const csinfo = {
  taxpayerId: "12345676",
  vatCode: "1",
  countyCode: "31",
  name: "Vevő Kft.",
  countryCode: "HU",
  postalCode: "5600",
  city: "Békéscsaba",
  streetName: "Tompa",
  publicPlaceCategory: "u.",
  number: "7"
};

const invoiceData = {
  invoiceNumber: "INV-201901",
  invoiceCategory: "NORMAL",
  invoiceIssueDate: "2019-11-12",
  invoiceDeliveryDate: "2019-11-12",
  currencyCode: "HUF",
  exchangeRate: 1,
  paymentMethod: "TRANSFER",
  paymentDate: "2019-11-12",
  invoiceAppearance: "PAPER"
};
const invoiceLine = {
  lineNumber: 1,
  lineExpressionIndicator: true,
  lineDescription: "BOMBA TOP",
  quantity: 1.2,
  unitOfMeasure: "PIECE",
  unitPrice: 121.12,
  discountValue: 7.26,
  discountRate: 0.05,
  lineNetAmount: 138.12,
  vatPercentage: 0.27
};

const validData = {
  supplierInfo: new Info(spinfo),
  customerInfo: new Info(csinfo),
  invoiceData: new InvoiceData(invoiceData),
  invoiceLines: [new InvoiceLine(invoiceLine)]
};

const newInvoice = new Invoice(validData);

apiClient.stornoInvoice()

Method to storno an invoice. The method returns the id of the operation which can be used later to get the invoice of this request.

/**
 * Send request to storno an invoice
 * @async
 * @param {Object} params Function params
 * @param {string} id the id of the invoice
 * @param {Invoice} params.invoice Invoice class instance
 * @returns {Promise<string>} Invoice id
 */

const stornoInvoice = await apiClient.stornoInvoice({id, newInvoice});

Example for storno invoice parameter:

const spinfo = {
  taxpayerId: "68845007",
  vatCode: "2",
  countyCode: "41",
  name: "ANGRO Kft.",
  countryCode: "HU",
  postalCode: "5600",
  city: "Békéscsaba",
  streetName: "Kétegyházi",
  publicPlaceCategory: "út.",
  number: "7"
};

const csinfo = {
  taxpayerId: "12345676",
  vatCode: "1",
  countyCode: "31",
  name: "Vevő Kft.",
  countryCode: "HU",
  postalCode: "5600",
  city: "Békéscsaba",
  streetName: "Tompa",
  publicPlaceCategory: "u.",
  number: "7"
};

const invoiceData = {
  invoiceNumber: "INV-201901",
};

const validData = {
  supplierInfo: new Info(spinfo),
  customerInfo: new Info(csinfo),
  invoiceData: new InvoiceData(invoiceData)
};

const newInvoice = new Invoice(validData);

Error handling

All methods returns an object with an errors array, if it's not empty that means an errror occured.

const taxPayerInfo = await apiClient.getTaxpayer({ taxNumber });

if (taxPayerInfo.errors.length) {
  //handle errors, more info about them is stored inside the array
} else {
  //everything is fine, you can continue
}

Tests

$ npm run test

Maintainers

This repository is maintained by ANGRO Nagykereskedelmi Kft.

License

GPL-3.0

1.0.0-beta

5 years ago