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");
/* Import classes if needed for invoice management */
const {
Info,
InvoiceDetail,
InvoiceLine,
InvoiceReference,
Invoice
} = require("@angro/nav-client-node").util;
/* 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/status from NAV if needed You can only specify requestNavData or requestNavStatus to be true but not both
/**
* 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
* @param {boolean} [params.requestNavStatus=false] If true invoice status 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.payload Invoice payload
* @returns {Promise<string>} Invoice id
*/
const invoice = await apiClient.createInvoice(payload);
Example for payload 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 invoiceDetail = {
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 payload = {
supplierInfo: spInfo,
customerInfo: csinfo,
invoiceDetail: invoiceDetail,
invoiceLines: [invoiceLine],
invoiceNumber: "INV-2020-K",
invoiceIssueDate: "2020-11-12",
completenessIndicator: false | true,
mergedItemIndicator: false | true
};
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.payload Invoice payload
* @returns {Promise<string>} Invoice id
*/
const stornoInvoice = await apiClient.stornoInvoice({id, payload});
Example for payload 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 payload = {
supplierInfo: spinfo,
customerInfo: csinfo,
};
apiClient.modifyInvoice()
Method to modify 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 modify an invoice
* @async
* @param {Object} params Function params
* @param {string} id the id of the invoice
* @param {Invoice} params.payload Invoice payload
* @returns {Promise<string>} Invoice id
*/
const modifyInvoice = await apiClient.modifyInvoice({id, payload});
Example for modify 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 invoiceLine = {
lineExpressionIndicator: true,
lineDescription: "HELL 250ML",
quantity: 10,
unitOfMeasure: "PIECE",
unitPrice: 100,
discountValue: 10,
discountRate: 10,
lineNetAmount: 900,
lineNetAmountHUF: 900,
vatPercentage: 0.27,
};
const payload = {
supplierInfo: spInfo,
customerInfo: csinfo,
invoiceLines: [invoiceLine],
};
apiClient.annulInvoice()
Method for invoice annulment. The method returns the id of the operation which can be used later to get the annulment of this request.
/**
* Send request for invoice annulment
* @async
* @param {Object} params Function params
* @param {string} id the id of the invoice
* @param {Annulment} params.payload Annulment class instance
* @returns {Promise<string>} Annulment id
*/
const annulInvoice = await apiClient.annulInvoice({id, payload});
Example for annul parameter:
const payload = {
annulmentCode: "ERRATIC_DATA",
annulmentReason: "test"
};
apiClient.resendInvoice()
Method for resending invoices in case of errors. The method returns the id of the operation which can be used later to get the invoice of this request.
/**
* @async
* @param {string} id the id of the invoice
* @param {Invoice} params.payload Invoice customerInfo and supplierInfo payload
* @returns {Promise<string>} Invoice id
*/
const resentInvoice = await apiClient.resendInvoice({id,payload});
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.