Skip to content

Commit

Permalink
Readme docs
Browse files Browse the repository at this point in the history
  • Loading branch information
boyander committed Oct 27, 2016
1 parent e1e9d00 commit 6f8f84f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,53 @@
[![NPM](https://nodei.co/npm/redsys-polite.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/redsys-polite/)

# redsys-polite
Use redsys payment platform wherever you want in an easy way
Use redsys payment platform wherever you want in an easy way.
It implements the new HMAC-SHA256 for signing the request.


# Importing package

You can install the package with npm:

npm install redsys-polite

Usage is fairly easy first just import the module, if using ES6:

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

Or if using old fashion javascript require:

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

# Usage

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")
.setUrlCallback("http://faable.com")
.setUrlCancel("http://faable.com/cancel")
.setUrlOK("http://faable.com/accept")
.build();

const form_encoded_params = redsys.getFormData(payment);

After that `form_encoded_params` will have the required properties to generate a payment form.

{ redsys_url: 'https://sis-t.redsys.es:25443/sis/realizarPago',
Ds_SignatureVersion: 'HMAC_SHA256_V1',
Ds_MerchantParameters: '<encoded merchant parameters>',
Ds_Signature: '<signature>' }
12 changes: 6 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {RedsysBuilder, PaymentBuilder} from '../src/redsys';
chai.should();
var assert = chai.assert;

var commerce_code = process.env.COMMERCE_CODE || '0001';
const commerce_code = process.env.COMMERCE_CODE || '0001';
console.log("Using commerce code -> " + commerce_code);

var secret_code = process.env.SECRET_CODE || "invalid-secret-code";
const secret_code = process.env.SECRET_CODE || "invalid-secret-code";
console.log("Using secret -> " + secret_code);

describe('Redsys', function() {
Expand Down Expand Up @@ -43,24 +43,24 @@ describe('Redsys', function() {
});
it('test generate form params', function() {

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

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

var form_encoded_params = redsys.getFormData(payment)
var all_params = redsys.generateMerchantParams(payment);
const form_encoded_params = redsys.getFormData(payment);
const all_params = redsys.generateMerchantParams(payment);
console.log(form_encoded_params);
console.log(all_params);
});
Expand Down

0 comments on commit 6f8f84f

Please sign in to comment.