salix/modules/client/back/models/tpv-transaction.js

30 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

const crypto = require('crypto');
module.exports = Self => {
require('../methods/tpv-transaction/confirm')(Self);
require('../methods/tpv-transaction/start')(Self);
require('../methods/tpv-transaction/end')(Self);
Self.createSignature = function(orderId, secretKey, merchantParameters) {
secretKey = Buffer.from(secretKey, 'base64');
const iv = Buffer.alloc(8, 0);
const cipher = crypto.createCipheriv('des-ede3-cbc', secretKey, iv);
cipher.setAutoPadding(false);
const orderKey = Buffer.concat([
cipher.update(zeroPad(orderId, 8)),
cipher.final()
]);
return crypto.createHmac('sha256', orderKey)
.update(merchantParameters)
.digest('base64');
};
function zeroPad(buf, blocksize) {
const buffer = typeof buf === 'string' ? Buffer.from(buf, 'utf8') : buf;
const pad = Buffer.alloc((blocksize - (buffer.length % blocksize)) % blocksize, 0);
return Buffer.concat([buffer, pad]);
}
};