Skip to content

ZeroOneStudio/node-yandex-kassa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#node-yandex-kassa

NPM Version Build Status

by Zero One

JavaScript utilities to integrate Yandex.Kassa payment API with your app

Installation

npm install --save node-yandex-kassa

Usage

Example usage with Express in route handler:

import { checkMD5, buildResponse } from 'node-yandex-kassa';
const { KASSA_SHOP_PASSWORD } = process.env;

app.post('/payments/check_order', (req, res, next) => {
  const { body } = req;
  const { invoiceId, shopId } = body;

  if (!checkMD5(body, KASSA_SHOP_PASSWORD)) {
  	return res.status(400).send('Validation of MD5 failed');
  }

  // ...
  // Here you might validate request params (for example, `orderNumber` or
  // `customerNumber`) if these parameters were passed to payment form
  // ...

  res.set('Content-Type', 'text/xml');
  res.send(buildResponse('checkOrder', 0, shopId, invoiceId));
});

Functions

checkMD5(requestBody, shopPassword)

Returns boolean.

Checks request body for valid md5 param.

Requests are being made by Yandex.Kassa service and have standart format (with sample data):

Key Value
requestDatetime 2011-05-04T20:38:00.000+04:00
action checkOrder
md5 8256D2A032A35709EAF156270C9EFE2E
shopId 13
shopArticleId 456
invoiceId 1234567
customerNumber 8123294469
orderCreatedDatetime 2011-05-04T20:38:00.000+04:00
orderSumAmount 87.10
orderSumCurrencyPaycash 643
orderSumBankPaycash 1001
shopSumAmount 86.23
shopSumCurrencyPaycash 643
shopSumBankPaycash 1001
paymentPayerCode 42007148320
paymentType AC

buildResponse(action, statusCode, shopId, invoiceId, message = null)

Returns string.

Generates string with valid XML required by Yandex.Kassa API.

Available status codes:

Code Status
0 Success
1 Authorization error
100 Transaction denied (only for checkOrder action)
200 Parse error

Successful response example

buildResponse('paymentAviso', 0, 13, 1234567);
<?xml version="1.0" encoding="UTF-8"?>
<paymentAvisoResponse performedDatetime="2011-05-04T20:38:01.000+04:00"
code="0" invoiceId="1234567"
shopId="13"/>

Response with error example

buildResponse('checkOrder', 100, 13, 1234567, 'Given customerNumber does not exist');
<?xml version="1.0" encoding="UTF-8"?>
<checkOrderResponse performedDatetime="2011-05-04T20:38:01.000+04:00"
code="100" invoiceId="1234567"
shopId="13"
message="Given customerNumber does not exist"/>

More docs coming soon

For now, for more info on usage and itegration refer to official integration guide and API spec.

License

This project rocks and uses MIT License

Copyright (c) 2015 Zero One

About

Node.js utilities to integrate Yandex.Kassa with your app

Resources

License

Stars

Watchers

Forks

Packages

No packages published