@vita-mojo/fiscalization-sdk
v0.1.22-VMOS-13419-a4f5676-404-rc.0
Published
This package serves as a wrapper for integrating with various fiscalization providers. As of now, the SDK only supports [Fiskaltrust][1].
Keywords
Readme
fiscalization-sdk
This package serves as a wrapper for integrating with various fiscalization providers. As of now, the SDK only supports Fiskaltrust.
Using the SDK
Run npm i @vita-mojo/fiscalization-sdk to install this package.
You must first initialise the SDK with the provider name and other required parameters.
import { fiscalizationSdk } from '@vita-mojo/fiscalization-sdk';
const options = {
apiKey: 'provider_api_key',
settings: {}, // 'fiscalization.integration' tenant/store level setting
terminalId: 'pos_terminal_id',
logger: {}, // optional logger
};
const fiskalProvider = fiskalizationSdk('fiskaltrust', options);Once initialised, the SDK returns an object containing several methods, each of which correspond to a fiscalization action.
const { generateBill } = fiskalProvider;
const order = {}; // vita-mojo order
const bill = await generateBill(order);
console.log(bill);Here's a list of supported actions:
| Method | Parameters | Return Type |
| ------------------------- | ------------------------------ | ----------------------------------------------------------------------------- |
| generateBill | VM Order | FiscalResponse |
| generateTicket | VM Order | FiscalResponse |
| generateDuplicateTicket | VM Order, reason(string) | FiscalResponse |
| eventLog | EventPayload | IReceipt |
| healthCheck | - | boolean |
| cashDeposit | amount(number), reason(string) | FiscalResponse |
| payout | amount(number), reason(string) | FiscalResponse |
| refundTicket | VM Order | FiscalResponse |
| dailyClosingFlow | | { zeroReceipt: FiscalResponse; dailyReceipt: FiscalResponse; } |
| monthlyClosingFlow | | { monthlyReceipt: FiscalResponse; monthlyArchive: FiscalResponse; } |
| yearlyReceipt | | FiscalResponse |
Settings
The settings option for initialising the SDK should come from the fiscalization.integration tenants-management setting. It can be defined on tenant or store level. An example configuration may look like this:
{
"name": "fiskaltrust",
"commonFields": {
"apiUrl": "https://fiscal_provider.url"
},
"fiskaltrust": {
"cashbox": "cashbox_id",
"posSystem": "pos_system_id",
"receiptCase": {
"bill": "5067112530745229320",
"ticket": "5067112530745229313",
"eventLog": "5067112530745229330",
"cashDeposit": "5067112530745229322",
"payout": "5067112530745229323",
"copy": "5067112530745229334",
"void": "262144",
"zeroReceipt": "5067112530745229327",
"dailyReceipt": "5067112530745229317",
"monthlyReceipt": "5067112530745229318",
"yearlyReceipt": "5067112530745229319",
},
"chargeItemCase": {
"unknown": "5067112530745229312"
},
"payItemCase": {
"default": "5067112530745229312",
"cashPayment": "5067112530745229313",
"internalConsumption": "5067112530745229329"
}
}
}Logger
You may provide an additional logger object while initialising the SDK. The logger should specify a log level and, optionally, logger method overrides for different log levels. Here's an example logger configuration:
import { LogLevels } from '@vita-mojo/fiscalization-sdk';
const logger = {
logLevel: LogLevels.debug, // Supported levels: none, error, info, debug
debug: (...messages) => {
/* debug loggger */
},
info: (...messages) => {
/* info logger */
},
};The log level defaults to error if not provided.
Building and Running Locally
Run npm run build:sdk to build the SDK.
To build the SDK in watch mode, run npm run build:sdk:w.
Running unit tests
Run npm run test:sdk to run unit tests via Jest.
