npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redsys-polite

v1.4.3

Published

Use redsys payment platform wherever you want in an easy way

Downloads

14

Readme

npm version GitHub version NPM

redsys-polite

Redsys payment gateway compatible with ES6. It implements the new HMAC-SHA256 request signing procedure.

Install package

You can install the package with npm:

npm install --save redsys-polite

Import package using ES6:

import {RedsysBuilder, PaymentBuilder} from 'redsys-polite';

With node:

var RedsysBuilder = require('redsys-polite').RedsysBuilder;
var PaymentBuilder = require('redsys-polite').PaymentBuilder;

How to use it

Generate form parameters with the following code.

const commerce_code = "<your_commerce_code>";
const secret_code = "<your_secret_key>";

const redsys = new RedsysBuilder()
    .setMerchantCode(commerce_code)
    .setName("Faable.com")
    .setTitular("Marc Pomar")
    .setSecret(secret_code)
    .enableDebug()
    .build();

const payment = new PaymentBuilder()
    .setTotal(3.20)
    .setOrderId("1")
    .setUrlMerchant("http://faable.com/notify")
    .setUrlCancel("http://faable.com/cancel")
    .setUrlOK("http://faable.com/accept")
    .build();

const form_encoded_params = redsys.getFormData(payment);

Then form_encoded_params will have the required properties to generate a payment form. Use this object to

{ redsys_url: 'https://sis-t.redsys.es:25443/sis/realizarPago',
  Ds_SignatureVersion: 'HMAC_SHA256_V1',
  Ds_MerchantParameters: '<encoded merchant parameters>',
  Ds_Signature: '<signature>' }

Form example using React:

  <form action={sign_payment.redsys_url} method="POST" ref="payform" >
    <input type="hidden" name="Ds_SignatureVersion" value={sign_payment.Ds_SignatureVersion}/>
    <input type="hidden" name="Ds_MerchantParameters" value={sign_payment.Ds_MerchantParameters}/>
    <input type="hidden" name="Ds_Signature" value={sign_payment.Ds_Signature}/>
  </form>

Decode POST notification received from payment server

With initialized redsys object using RedsysBuilder call the method like this: var Ds_Signature = req.body.Ds_Signature; var Ds_MerchantParameters = req.body.Ds_MerchantParameters; redsys.decodeNotifiedMerchantParams(Ds_Signature, Ds_MerchantParameters) .then((decodedParams) => console.log(decodedParams)) .catch(e => console.log(e)); // Catch error for invalid signature

_decodeNotifiedMerchantParams returns a promise that is rejected if signature is not valid. Remember to catch it like the shown example.

Redsys server notification

Convert response DS_Code to a message string: import {codeToMessage} from 'redsys-polite'; var obj = codeToMessage('9915'); // Example Ds_Response code can be 9915, user canceled the payment; console.log(obj.message); // Prints text description for this code

Author

Marc Pomar Torres