Install
npm install qiwi-shop
About
Qiwi shop rest api module (qiwi.com)
Example
const QiwiShop = require("qiwi-shop");
const express = require("express");
const app = express();
let projectId = "0000001";
let apiId = "0000000001";
let apiPassword = "api";
let notifyPassword = "notify";
const qiwi = new QiwiShop(projectId, apiId, apiPassword, notifyPassword);
qiwi.beforeCreateBill = function(billId, data) {
}
app.post('/payments/bill/create/', (req, res, next) => {
qiwi.createBill({
user: 'tel:+7910100100',
amount: '10',
ccy: 'RUB',
comment: 'recharge',
lifetime: new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 5).toISOString(),
pay_source: 'qw',
prv_name: 'example.com'
}).then((result) => {
if(!result || !result.response || result.response.result_code != 0) {
throw new Error('Qiwi bill creation fail');
}
res.redirect(qiwi.getPaymentUrl({ shop: qiwi.projectId, transaction: result.response.bill.bill_id }));
});
});
let successHandler = (data, callback) => {
};
let errorHandler = (err, meta) => {
};
let authenticationBySignature = false;
app.post('payments/notification/', qiwi.notify(successHandler, errorHandler, authenticationBySignature));
Description
You can write custom notification handler, but library version includes data/authentication validation and automatically send all headers in the necessary format
API
.constructor(projectId, apiId, apiPassword, notifyPassword)
all arguments you can find in your qiwi shop account
.getPaymentUrl([query])
returns qiwi bill creation url
.beforeCreateBill(billId, data)
called before bill creation request, but after bill hash creation
.createBill(data)
returns promise, create bill, data options must comply with documentation
.user and .amount is required
.getBillStatus(billId)
returns promise, get bill status
.cancelBill(billId)
returns promise, cancel bill
.refundBill(billId, data)
returns promise, refunds bill, data options must comply with documentation
.getRefundStatus(billId, refundId)
returns promise, gets bill refund status
.checkNotifyAuthBasic(req)
checks notification by basic authentication
.checkNotifyAuthSignature(req)
checks notification by signature
.createXml(code)
creates xml string for response
.notify(fn, onError, [checkSignature])
qiwi notification handler, it is "connect" middleware