2023-01-31 12:29:17 +00:00
|
|
|
const crypto = require('crypto');
|
|
|
|
|
2023-01-30 11:39:47 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
require('../methods/tpv-transaction/confirm')(Self);
|
2023-01-31 12:29:17 +00:00
|
|
|
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]);
|
|
|
|
}
|
2023-01-30 11:39:47 +00:00
|
|
|
};
|