New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

fns-api

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fns-api

Methods of working with FNS API

latest
Source
npmnpm
Version
1.0.8
Version published
Maintainers
1
Created
Source

fns-api npm version npm version

Methods of working with FNS API.

Installation

npm install fns-api axios

Usage

// App.js
import axios from 'axios';
import * as fns from 'fns-api';

const axiosInstance = axios.create({
  baseURL: fns.BASE_URL,
  headers: fns.defaultHeaders
});
const receiptApi = new fns.ReceiptApi(axiosInstance, '<your session id>');

receiptApi
  .addReceiptQR({ qr: '<your qr data scanned from the receipt>' })
  .then((response) => console.log(response.data))
  .catch((e) => console.error(e));

Example

Create LoginApi instance to work with login

import axios from 'axios';
import * as fns from 'fns-api';

const axiosInstance = axios.create({
  baseURL: fns.BASE_URL,
  headers: fns.defaultHeaders
});
const loginApi = new fns.LoginApi(axiosInstance);

Create ReceiptApi instance to work with receipts

import axios from 'axios';
import * as fns from 'fns-api';

// Get session id from login response
const sessionId = '<your session id>';

const axiosInstance = axios.create({
  baseURL: fns.BASE_URL,
  headers: fns.defaultHeaders
});
const receiptApi = new fns.ReceiptApi(axiosInstance, sessionId);

Session id you will receive after logging in any chosen way.

Login with the same credentials as on the site lkfl2.nalog.ru

// Your INN from https://lkfl2.nalog.ru
const inn = '<your inn>';
// Your password from https://lkfl2.nalog.ru
const password = '<your password>';
// Client secret
const clientSecret = '<client secret>';

loginApi
  .loginLKFL({ inn, password, client_secret: clientSecret })
  .then((response) => console.log(response.data))
  .catch((e) => console.error(e));

To get information about a receipt, you must first add it

// Your receipt data
const fiscalData: fns.FiscalData = {
  date: '2021-06-14T14:32',
  operationType: 1,
  sum: 43600,
  fsId: '9982450301247855',
  documentId: 65724,
  fiscalSign: '7634185632'
};

receiptApi
  .addReceipt({ fiscalData, sendToEmail: false })
  .then((response) => console.log(response.data))
  .catch((e) => console.error(e));

A receipt can be added according to the data from the QR-code

// QR-data string from the receipt
const qr = '<your qr data scanned from the receipt>';

receiptApi
  .addReceiptQR({ qr })
  .then((response) => console.log(response.data))
  .catch((e) => console.error(e));

After adding, we can get detailed information about the receipt

// Get receipt id after call add receipt api
const receiptId = '<your receipt id>';

// Periodically make requests,
// until you get the ReceiptStatus.NPD_FOUND or ReceiptStatus.HAVE_COPY status.
receiptApi
  .getReceipt(receiptId)
  .then((response) => console.log(response.data))
  .catch((e) => console.error(e));

More information about receipt status.

Get a list of all added receipts

receiptApi
  .getReceipts()
  .then((response) => console.log(response.data))
  .catch((e) => console.error(e));

Remove a receipt from the list of added

// Receipt id
const receiptId = '<your receipt id>';

receiptApi
  .removeReceipt(receiptId)
  .then((response) => console.log(response.status))
  .catch((e) => console.error(e));

Refresh session id and refresh token

// Get refresh token from login response
const refreshToken = '<your refresh token>';
// Client secret
const clientSecret = '<client secret>';

loginApi
  .refreshTokens({ refresh_token: refreshToken, client_secret: clientSecret })
  .then((response) => console.log(response.data))
  .catch((e) => console.error(e));

API Specification

Read API specification for full information.

Translations:

License

Licensed under the MIT License.

Keywords

fns

FAQs

Package last updated on 21 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts