1.0.8 • Published 6 months ago

fns-api v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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.

1.0.8

6 months ago

1.0.7

1 year ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.2

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago