
A few months after the release of the updated Yandex.Cashy API, the first integration solutions began to appear on new technologies. One of the pioneers of integration was the company Lodoss Team , which developed the SDK library for working with Kasse under Node.js.
Nobody will tell about the project better than its author. Therefore, I give the floor to Anton , the technical ideologist of the Lodoss Team , who will talk about why the choice fell on Kass and how it all works now.
My name is Anton, I am the Technical Director of Lodoss Team. We are engaged in web development since 2008. Technology stack - Javascript: Node.js, Angular, React. Major customers are from America and Europe.
To date, my team has completed more than 400 commercial projects. Among them are related to payment systems.
In this article I want to share the experience of integrating the payment system into applications for the Russian market and tell you why we chose Yandex.Kassa, wrote the SDK library for Node.js, how it simplifies the implementation of the payment system and helps in development.
My team has never had problems with the integration of payment systems for foreign customers. But a year ago we decided to work in the domestic market in order to create complex products for our own. We chose the payment system, agreed and implemented the basic functionality of working with it. But they did not take into account one important detail that they learned about 2 weeks before the release: this payment system does not work with companies from Russia. We have only one way out: to replace the payment system as soon as possible. With colleagues, we analyzed the payment services market and settled on Yandex.Kassa.
We chose according to the parameters that fit both us and the client:
Someone may not be familiar with the last item. 54- - federal law on the use of cash equipment. In 2017, he survived the reform: from now on, all cash offices in Russia must be connected to the Internet and send electronic checks to the tax office. Online ticket offices should be installed by anyone who has an online store, who owns a business and sells goods or provides paid services.
Yandex.Kassa is engaged in acquiring and offers a convenient solution for work on 54- online services and online stores. The client connects the online cash register, and the service helps to work with it: sends the check data, checks the submission to the tax, conducts the transaction. If you do not use Yandex.Cash, but, for example, enter into an agreement on acquiring with the bank, the store will have to carry out all operations with electronic checks on its own.
My team started implementing the payment system using the first version of the Yandex.Cash API. But this version had flaws: complex, confusing documentation, disconnected payment protocols. The process of working with the API was structured in such a way that in order to implement many things, it was necessary to get a bonus and contact the support department, write applications, leave applications. All this took a lot of time.
In the documentation for the updated version, we saw that the information was “closer” to the developer. The guys from Yandeks.Kassy combined payment protocols with common logic and description, made it more convenient interface for developers. Now the process of integrating payment systems hardly differed from the well-known foreign counterparts that I encountered in my work, such as Stripe and Braintree.
The team backlog still had a large number of tasks related to the payment functionality. And I thought about switching to a new version of the API, because it solved some problems better and faster than the previous one.
In the new Yandex Yandex.Cash API, developers have optimized such specific things as asynchrony and idempotency. It has also become more convenient to work with data. This team told Yandeks.Kassy .
The team liked the new approach Yandex. Cash: they really care about the developers. But for the new version of the Yandex API. The Kassa did not provide a box for working with Node.js out of the box — namely, we wrote a project on it. And I will say this: there are no such libraries on the market at all. But our guys thought and collected their OpenSource library to work with the Yandex.Money API .
As a result, the library simplifies and optimizes development, it can be integrated for custom and e-commerce solutions. The NPM module helps to create e-commerce payment modules and introduce payment options for goods and services into the application. For example, you can use the SDK if you need to add to the site a payment for booking or buying a ticket.
When developing the SDK for Yandex.Cash, we were inspired by examples of payment systems Stripe and Braintree and tried to implement the library in a similar style: the tools of these foreign guys are really convenient for developers. Let's look at an example of how to integrate a payment system into a project in several steps.
First of all, you need to install the library itself through the NPM package manager: in the near future we will also post on Yarn.
npm install yandex-checkout Import the library by specifying shopId and secretKey:
const yandexCheckout = require('yandex-checkout')('shopId', 'secretKey'); To authenticate requests, use basic Basic auth :
You can release the secret key in your Yandex.Cash account in the “ Settings ” section.
When connecting a library, you can transfer not only text parameters, but also a configuration object:
const yandexCheckout = require('yandex-checkout')({ shopId: ' ', secretKey: ' c ', timeout: 20000, // 120000 debug: false, // FALSE host: '', // https://payment.yandex.net path: '', // '/api/v3/' }); At this integration process is over. Now you can use the library.
To create a payment you need to specify the idempotency key. In API documentation, Yandex recommends using UUID V4. If the function does not transmit the idempotency key, the library will generate a new key each time using the recommended algorithm.
For ease of use, we wrapped all the methods in Promise, so the result of the functions is a promise, and we can use then, catch:
const yandexCheckout = require('yandex-checkout')('shopId', 'secretKey'); const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; yandexCheckout.createPayment({ 'amount':{ 'value': '2.00', 'currency': 'RUB', }, 'payment_method_data':{ 'type': 'bank_card', }, 'confirmation':{ 'type': 'redirect', 'return_url': 'https://www.merchant-website.com/return_url', } }, idempotenceKey) .then((result) => { console.log({payment: result}); }) .catch( err => console.log(err)); Yandex.Kassa supports idempotency 24 hours after the request. After this time, the second request will be processed as a new one.
To get information about the payment, you need to use the getPaymentInfo function and pass the payment ID parameters to it:
const yandexCheckout = require('yandex-checkout')('shopId', 'secretKey'); const paymentId = '21966b95-000f-50bf-b000-0d78983bb5bc'; yandexCheckout.getPaymentInfo(paymentId) .then((result) => { console.log({payment: result}); }) .catch( err => console.log(err)); }); The library supports all available methods described in the documentation .
Although the Russian IT market for e-commerce is lagging behind the western one, there are positive trends. Development methods are gradually improved with an eye on the real consumer. In the case of Kasse, this consumer is a programmer from the field of e-commerce, and the new Yandex Yandex.Cash API was developed specifically for this audience.
The development of our NPM-module can also be considered as a demonstration of the simplicity and clarity of the new API of the Cashier - the architecture and the basic principles of the module could be laid literally in one day.
I described the main points that my team encountered in integrating the payment system and creating the NPM module. Perhaps I missed something - ask in the comments.
Source: https://habr.com/ru/post/348070/
All Articles