Coder Social home page Coder Social logo

davidsandez / node-redsys-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from santiperez/node-redsys-api

0.0 0.0 0.0 83 KB

Redsys nodejs api implementation with new the key-hashed message autentication code (HMAC) SH256.

License: MIT License

JavaScript 100.00%

node-redsys-api's Introduction

node-redsys-api

Node.js Redsys api implementation with new the key-hashed message authentication code (HMAC) SHA256 for the virtual payment gateway integration. This is a node.js port of the PHP API provided by Redsys

Installation

npm install node-redsys-api --save

Examples

Obtain signature and merchant parameters

const Redsys = require('node-redsys-api').Redsys;

function createPayment(description, total, titular, orderId, paymentId) {
  const redsys = new Redsys();
  const mParams = {
    DS_MERCHANT_AMOUNT: total,
    DS_MERCHANT_ORDER: paymentId,
    DS_MERCHANT_MERCHANTCODE: TPVConfig.fucCode,
    DS_MERCHANT_CURRENCY: TPVConfig.currency,
    DS_MERCHANT_TRANSACTIONTYPE: TPVConfig.transaction_type,
    DS_MERCHANT_TERMINAL: TPVConfig.terminal,
    DS_MERCHANT_MERCHANTURL: `${baseDomain + TPVConfig.redirect_urls.callbackBasePath}/${orderId}`,
    DS_MERCHANT_URLOK: `${baseDomain + TPVConfig.redirectPaths.OK}&id=${orderId}`,
    DS_MERCHANT_URLKO: `${baseDomain + TPVConfig.redirectPaths.KO}&id=${orderId}`,
  };

  return { signature: redsys.createMerchantSignature(TPVConfig.secret, mParams), merchantParameters: redsys.createMerchantParameters(mParams), raw: mParams };
}

Process TPV callback

const merchantParams = response.Ds_MerchantParameters || response.DS_MERCHANTPARAMETERS;
const signature = response.Ds_Signature || response.DS_SIGNATURE;

const merchantParamsDecoded = redsys.decodeMerchantParameters(merchantParams);
const merchantSignatureNotif = redsys.createMerchantSignatureNotif(TPVConfig.secret, merchantParams);
const dsResponse = parseInt(merchantParamsDecoded.Ds_Response || merchantParamsDecoded.DS_RESPONSE, 10);

if (redsys.merchantSignatureIsValid(signature, merchantSignatureNotif) && dsResponse > -1 && dsResponse < 100) {
/* TPV payment is OK;
... */
} else {
/* 'TPV payment is KO;
... */
}

Tests

npm run test

Alternative implementations

You can download Java, PHP, .NET implementations

Authors

Santi Pérez

License

MIT

node-redsys-api's People

Contributors

davidsandez avatar javiertury avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.