![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
redsys-pay
Advanced tools
NodeJS library to ease the communication with RedSys point of sales
Install the NPM package:
npm install redsys-pay
Generate the parameters to create a transaction:
const {
secretKey,
makeParameters,
CURRENCIES,
TRANSACTION_TYPES
} = require('redsys-pos')
secretKey("sq7HjrUOBfKmC576ILgskD5srU870gJ7")
const obj = {
amount: '100', // cents (in euro)
order: '123123',
merchantName: "REDSYS PAY SHOP",
merchantCode: '123123123',
currency: CURRENCIES.EUR,
transactionType: TRANSACTION_TYPES.AUTHORIZATION, // '0'
terminal: '1',
merchantURL: 'http://shop.js.gl/merchant',
successURL: 'http://shop.js.gl/success',
errorURL: 'http://shop.js.gl/error'
}
const result = makeParameters(obj)
console.log(result);
The above code will print:
const form_params = {
Ds_SignatureVersion: 'HMAC_SHA256_V1',
Ds_MerchantParameters: 'eyJEU19NRVJDSEFOVF9BTU9VTlQiOiIxMDAiLCJEU19NRVJDSEFOVF9PUkRFUiI6IjE1MDg0MjgzNjAiLCJEU19NRVJDSEFOVF9NRVJDSEFOVE5BTUUiOiJUZXN0aW5nIFNob3AiLCJEU19NRVJDSEFOVF9NRVJDSEFOVENPREUiOiIzMjcyMzQ2ODgiLCJEU19NRVJDSEFOVF9DVVJSRU5DWSI6Ijk3OCIsIkRTX01FUkNIQU5UX1RSQU5TQUNUSU9OVFlQRSI6IjAiLCJEU19NRVJDSEFOVF9URVJNSU5BTCI6IjEiLCJEU19NRVJDSEFOVF9NRVJDSEFOVFVSTCI6IiIsIkRTX01FUkNIQU5UX1VSTE9LIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwL3N1Y2Nlc3MiLCJEU19NRVJDSEFOVF9VUkxLTyI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODA4MC9lcnJvciJ9',
Ds_Signature: 'qkMJMWR6Dq32xwbQuguTv39OvXv4KdD1Xg7pZ8phGZI='
}
With express.js you can send object to view:
app.get('/form/', (req, res) => {
const form_params = req.body
res.render('form', form_params)
})
This is a ejs template view:
<html>
<head>
<title></title>
</head>
<body>
<form name="from" action="https://sis-t.redsys.es:25443/sis/realizarPago" method="POST">
<input type="hidden" name="Ds_SignatureVersion" value="<%- Ds_SignatureVersion %>" />
<input type="hidden" name="Ds_MerchantParameters" value="<%- Ds_MerchantParameters %>" />
<input type="hidden" name="Ds_Signature" value="<%- Ds_Signature %>" />
<input type="submit" value="Go to pay">
</form>
</body>
</html>
Need make html same this:
<form name="from" action="https://sis-t.redsys.es:25443/sis/realizarPago" method="POST">
<input type="hidden" name="Ds_SignatureVersion" value="HMAC_SHA256_V1" />
<input type="hidden" name="Ds_MerchantParameters" value="eyJEU19NRVJDSEFOVF9BTU9VTlQiOiIxMDAiLCJEU19NRVJDSEFOVF9PUkRFUiI6IjE1MDg0MjgzNjAiLCJEU19NRVJDSEFOVF9NRVJDSEFOVE5BTUUiOiJUZXN0aW5nIFNob3AiLCJEU19NRVJDSEFOVF9NRVJDSEFOVENPREUiOiIzMjcyMzQ2ODgiLCJEU19NRVJDSEFOVF9DVVJSRU5DWSI6Ijk3OCIsIkRTX01FUkNIQU5UX1RSQU5TQUNUSU9OVFlQRSI6IjAiLCJEU19NRVJDSEFOVF9URVJNSU5BTCI6IjEiLCJEU19NRVJDSEFOVF9NRVJDSEFOVFVSTCI6IiIsIkRTX01FUkNIQU5UX1VSTE9LIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwL3N1Y2Nlc3MiLCJEU19NRVJDSEFOVF9VUkxLTyI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODA4MC9lcnJvciJ9" />
<input type="hidden" name="Ds_Signature" value="qkMJMWR6Dq32xwbQuguTv39OvXv4KdD1Xg7pZ8phGZI=" />
<input type="submit" value="Go to pay">
</form>
const { getResponseParameters } = require("redsys-pos")
const RESPONSE = req.body.Ds_MerchantParameters
const result = getResponseParameters(RESPONSE)
console.log(result)
If successful, this will print:
{
Ds_Date: '20%2F10%2F2017',
Ds_Hour: '18%3A20',
Ds_SecurePayment: '1',
Ds_Amount: '100',
Ds_Currency: '978',
Ds_Order: '00007921799',
Ds_MerchantCode: '327234688',
Ds_Terminal: '001',
Ds_Response: '0000',
Ds_TransactionType: '0',
Ds_MerchantData: '',
Ds_AuthorisationCode: '678746',
Ds_ConsumerLanguage: '1',
Ds_Card_Country: '724',
Ds_Card_Brand: '1'
}
const { getResponseCodeMessage } = require("redsys-pos")
var str = getResponseCodeMessage("0180")
console.log(str)
This will print:
Operación no permitida para ese tipo de tarjeta.
const { getResponseCodeMessage } = require("redsys-pos")
var str = getResponseCodeMessage("xyz")
console.log(str)
This will print:
null
Install soap client
npm i soap
Recurrent payment with SOAP:
const {
secretKey,
CURRENCIES,
TRANSACTION_TYPES,
makeWSParameters,
SANDBOX_WS
} = require('redsys-pay')
const soap = require('soap')
secretKey("sq7HjrUOBfKmC576ILgskD5srU870gJ7")
const params = {
amount: '100', // cents (in euro)
order: '000123',
merchantCode: '132132132',
currency: CURRENCIES.EUR,
expiryDate: "2012",
transactionType: TRANSACTION_TYPES.NO_AUTHENTICATION,
terminal: '1',
identifier: '18550bc2358294ddfdb50f74d149a31eecebb9d36'
}
const params = makeWSParameters(dataparams)
soap.createClient(SANDBOX_WS, (err, client) => {
if (err) throw new Error(err)
else {
client.trataPeticion({ _xml: params }, (err2, result, rawResponse) => {
if (err2) throw new Error(err2)
else {
console.log(JSON.stringify(rawResponse))
console.log(JSON.stringify(result))
}
})
}
})
const {
SANDBOX_URL,
PRODUCTION_URL,
SANDBOX_WS,
PRODUCTION_WS
} = require('redsys-pay')
Based redsys-pos 0.9.0 library by Jordi Moraleda and Joel Moreno redsys-pay library by Josep Subils
Josep Subils updates:
Carlos Asín @carlosasin updates:
@dlopesino update:
@gianbuono update:
FAQs
Node JS library to ease the communication with RedSys point of sales
The npm package redsys-pay receives a total of 201 weekly downloads. As such, redsys-pay popularity was classified as not popular.
We found that redsys-pay demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.