npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-orangedata

v1.2.8

Published

Node.js integration for OrangeData service

Downloads

176

Readme

Note: this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Возможности

  • [x] Взаимодействие с онлайн-кассой по защищенному каналу связи (SSL)
  • [x] SHA256-RSA подпись сообщений приватным ключом отправителя
  • [x] Создание чека, соответствующего протоколу ОранжДата
  • [x] Получение статуса ранее отправленного чека
  • [X] Создание чека коррекции
  • [X] Проверка контрольной марки

Установка

Для работы с данной библиотекой требуется Node.js версии 8.9.2 (LTS) или выше.

Используя yarn:

$ yarn add node-orangedata

Используя npm:

$ npm install --save node-orangedata

Использование

Используйте команду npm test, чтобы запустить выполнение примера в вашей консоли.

  1. Подключите библиотеку в вашем коде:

    const { OrangeData, Order } = require('node-orangedata');
  2. Передайте параметры для установления защищенного соединения в конструктор класса OrangeData:

    
    const cert = fs.readFileSync('./keys/client.crt');
    const key = fs.readFileSync('./keys/client.key');
    const passphrase = '1234';
    const ca = fs.readFileSync('./keys/cacert.pem');
    const privateKey = fs.readFileSync('./keys/private_key.pem');
    const apiUrl = 'https://apip.orangedata.ru:2443/api/v2';
    
    const agent = new OrangeData({ apiUrl, cert, key, passphrase, ca, privateKey });
  3. Создайте экземпляр класса Order и заполните документ данными соответствующими протоколу:

    const order = new Order({
      id: '123',
      inn: '7725713770',
      group: 'Main',
      type: 1, // Приход
      customerContact: '+79991234567',
      customer: 'покупатель',
      customerINN: '7725713770',
      taxationSystem: 1, // Общая
    });
    
    order
      .addPosition({
        text: 'Тестовый товар',
        quantity: 5,
        price: 10,
        tax: 1,
        paymentMethodType: 1,
        paymentSubjectType: 1,
        nomenclatureCode: 'igQVAAADMTIzNDU2Nzg5MDEyMwAAAQ==',
        supplierINN: '3123011520',
        supplierInfo: { phoneNumbers: ['+79998887766'], name: 'Наименование поставщика' },
      })
      .addPayment({ type: 1, amount: 10 })
      .addPayment({ type: 2, amount: 40 })
      .addAgent({
        agentType: 127,
        paymentTransferOperatorPhoneNumbers: ['+79998887766'],
        paymentAgentOperation: 'Операция агента',
        paymentAgentPhoneNumbers: ['+79998887766'],
        paymentOperatorPhoneNumbers: ['+79998887766'],
        paymentOperatorName: 'Наименование оператора перевода',
        paymentOperatorAddress: 'Адрес оператора перевода',
        paymentOperatorINN: '3123011520',
        supplierPhoneNumbers: ['+79998887766'],
      })
      .addUserAttribute({
        name: 'citation',
        value: 'В здоровом теле здоровый дух, этот лозунг еще не потух!',
      });
    
  4. Используйте агента, чтобы отправить сформированный документ:

    const { OrangeDataError } = require('node-orangedata/lib/errors');
    
    try {
      agent.sendOrder(order);
    } catch (error) {
      if (error instanceof OrangeDataError) {
        // OrangeData errors contains additional info in `errors` property of type Array
        console.log(error.message, error.errors);
      }
      // general errors handling
    }
    
  5. Используйте агента для получения статусов по ранее отправленным документам:

    try {
      const status = agent.getOrderStatus(inn, id);
      if (status) {
        // Документ успешно обработан, status содержит данные документа
      } else {
        // Документ создан и добавлен в очередь на обработку, но еще не обработан
      }
    } catch (error) {
      if (error instanceof OrangeDataError) {
        // OrangeData errors contains additional info in `errors` property of type Array
        console.log(error.message, error.errors);
      }
      // general errors handling
    }
    

Troubleshooting

  • Ошибка error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag означает неправильный pem формат приватного ключа.

    Если вы воспользовались советом из протокола и сконвертировали xml в pem с помощью онлайн-конвертора, то попробуйте изменить заголовок и окончание ключа. Укажите -----BEGIN PRIVATE KEY----- вместо -----BEGIN RSA PRIVATE KEY-----.

License

This project is licensed under the MIT license, copyright (c) 2017 АО "Оранж Дата".