santiperez / node-redsys-api Goto Github PK
View Code? Open in Web Editor NEWRedsys nodejs api implementation with new the key-hashed message autentication code (HMAC) SH256.
License: MIT License
Redsys nodejs api implementation with new the key-hashed message autentication code (HMAC) SH256.
License: MIT License
As it comes, it is not possible to consume REST API.
To solve this problem you have to make a small correction.
decodeMerchantParameters(data) {
const decodedData = JSON.parse(base64url.decode(data, 'utf8'));
const res = {};
Object.keys(decodedData).forEach((param) => {
res[decodeURIComponent(param)] = decodeURIComponent(decodedData[param]);
});
return res;
}
decodeMerchantParameters(data) {
return this.parmsToObject(JSON.parse(base64url.decode(data, 'utf8')));
}
parmsToObject(data)
{
const res = {};
Object.keys(data).forEach((param) => {
const decode = decodeURIComponent(data[param]);
if (decode == "[object Object]")
res[decodeURIComponent(param)] = this.parmsToObject(data[param]);
else
res[decodeURIComponent(param)] = decode;
});
return res;
}
Hi, I had some problems generating the signature, as it seems to be wrong.
I've compared the result of the Ds_Signature and Ds_MerchantParams with a PHP Redsys Api which was working correctly. Finally I found the problem is how the signature is generate, in particular in the 3Des encryption step.
In the PHP API the result of the encryption is cropped by a multiplier (I don't know why).
protected static function encrypt3DESOpenSSL($message, $key)
{
$l = ceil(strlen($message) / 8) * 8;
$message = $message.str_repeat("\0", $l - strlen($message));
return substr(openssl_encrypt($message, 'des-ede3-cbc', $key, OPENSSL_RAW_DATA, "\0\0\0\0\0\0\0\0"), 0, $l);
}
Changing the 3Des encyption method in the node api finanly I get redsys working.
encrypt3DES(str, key) {
const secretKey = Buffer.from(key, 'base64');
const iv = Buffer.alloc(8, 0);
const cipher = crypto.createCipheriv('des-ede3-cbc', secretKey, iv);
cipher.setAutoPadding(false);
const en_key = cipher.update(zeroPad(str, 8), 'utf8', 'binary') + cipher.final('binary');
const l = Math.ceil(str.length / 8) * 8;
//$message = $message.str_repeat("\0", $l - strlen($message));
return Buffer.from(en_key.substr(0, l), 'binary').toString('base64');
}
Hi buddy,
According to "npm audit", base64url dependency should be updated.
https://nodesecurity.io/advisories/658
Cheers
Hi
I have just installed this module to connect to my VPO in my Meteor JS app but I am getting problems. In my server code I have created a new method called from the client. The code in the server looks like this:
`var redsys = new Redsys({
"merchant": {
"code": "MERCHANT_CODE",
"terminal": "1",
"titular": "TITULAR",
"name": "NAME",
"secret": "qwertyasdf0123456789"
},
"language": "auto",
"test": true
});
form_data = redsys.create_payment({
total: ORDER_TOTAL,
currency: "EUR",
order: "ORDER ID",
description: "ORDER DESCRIPTION",
data: "CART DATA",
transaction_type: 0,
redirect_urls: {
callback: "CALLBACK URL",
return_url: "OK URL",
cancel_url: "KO URL"
}
});`
I got an error from the server saying that Redsys is not defined. I guess I have to put and import somewhere to make it works but do not know where.
Neither I know where I should put the URL where the form is sent, https://sis-t.redsys.es:25443/sis/realizarPago
I hope someone can help me
When the payment is made in international currencies gives error:
URIError: URI malformed
I20230421-11:26:58.465(2)? at decodeURIComponent ()
I20230421-11:26:58.465(2)? at Redsys.decodeMerchantParameters (.../node_modules/node-redsys-api/src/api-redsys.js:42:39)
This error ocurrs because the parameter Ds_Markup_DCC has the character '%'
Hola buenas.
¿Se podría de alguna manera hacer una devolución usando este módulo?
Actualmente lo usamos para generar formularios de pago pero estaría geníal poder pasar parte de la operativa que tenemos que hacer en la web del banco a poder hacerse programaticamente. Así si pudieramos de alguna manera listar las operaciones realizadas y sus dato y poder por ejemplo seleccionar una de las operaciones y realizar una devolución podríamos integrar de manera total el pago web en nuestro sistema.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.