Git Product home page Git Product logo

node-redsys-api's Introduction

node-redysys-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

var Redsys = require('node-redsys-api').Redsys;
...
//Snippet to obtain the signature & merchantParameters
function createPayment(description, total, titular, orderId, paymentId)
{
    var redsys = new Redsys();
    var mParams = {
        "DS_MERCHANT_AMOUNT":common.round(total*100).toString(),
        "DS_MERCHANT_ORDER":paymentId,
        "DS_MERCHANT_MERCHANTCODE":tpvInfo.fucCode,
        "DS_MERCHANT_CURRENCY":tpvInfo.currency,
        "DS_MERCHANT_TRANSACTIONTYPE":tpvInfo.transaction_type,
        "DS_MERCHANT_TERMINAL":tpvInfo.terminal,
        "DS_MERCHANT_MERCHANTURL":domain+tpvInfo.redirect_urls.callbackBasePath+'/'+orderId,
        "DS_MERCHANT_URLOK":domain+tpvInfo.redirect_urls.urlOK+'&id='+orderId,
        "DS_MERCHANT_URLKO":domain+tpvInfo.redirect_urls.urlKO+'&id='+orderId
    };

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

//Snippet to process the TPV callback
var merchantParams = tpvResponse.Ds_MerchantParameters || tpvResponse.DS_MERCHANTPARAMETERS;
var signature = tpvResponse.Ds_Signature || tpvResponse.DS_SIGNATURE;

var merchantParamsDecoded = redsys.decodeMerchantParameters(merchantParams);
var merchantSignatureNotif = redsys.createMerchantSignatureNotif(tpvInfo.secret, merchantParams);
var dsResponse = parseInt(merchantParamsDecoded.Ds_Response || merchantParamsDecoded.DS_RESPONSE);

if (redsys.merchantSignatureIsValid(signature , merchantSignatureNotif) && dsResponse > -1 && dsResponse < 100 ) {
console.log('TPV payment is OK');
...
} else {
console.log('TPV payment 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

Watchers

 avatar  avatar  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.