├── index.js ├── lib ├── ebanx.js ├── resources │ ├── Constructor.js │ ├── Print.js │ ├── Cancel.js │ ├── Zipcode.js │ ├── Exchange.js │ ├── Query.js │ ├── Capture.js │ ├── DocumentBalance.js │ ├── RefundOrCancel.js │ ├── Request.js │ ├── Token.js │ ├── Direct.js │ ├── Refund.js │ └── Validator.js ├── Config.js ├── autoload.js └── http │ └── Client.js ├── .npmignore ├── .gitignore ├── .codeclimate.yml ├── .travis.yml ├── tests ├── ebanxTest.js ├── ConfigTest.js ├── cancelTest.js ├── zipcodeTest.js ├── printTest.js ├── directTestToken.js ├── exchangeTest.js ├── directTestDebit.js ├── documentBalanceTest.js ├── directTestCreditCard.js ├── refundOrCancelTest.js ├── directPersonType.js ├── httpTest.js ├── captureTest.js ├── queryTest.js ├── tokenTest.js ├── refundTest.js ├── requestTest.js ├── validatorTest.js └── directTest.js ├── package.json ├── LICENSE.md └── README.md /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require(__dirname + '/lib/ebanx'); -------------------------------------------------------------------------------- /lib/ebanx.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | module.exports = require('./autoload.js'); -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | teste.js 2 | node_modules/ 3 | tests/integration_key 4 | lib-cov/ 5 | .coveralls.yml 6 | npm-debug.log -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | app.js 2 | node_modules/ 3 | tests/integration_key 4 | lib-cov/ 5 | .coveralls.yml 6 | npm-debug.log 7 | teste.js -------------------------------------------------------------------------------- /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | exclude_paths: 2 | - tests/* 3 | - LICENSE.md 4 | - package.json 5 | - .gitignore 6 | - .travis.yml 7 | - .npmignore 8 | - README.md -------------------------------------------------------------------------------- /lib/resources/Constructor.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | function construct(obj, key, value) { 4 | var config = { 5 | value: value, 6 | writable: true, 7 | enumerable: true, 8 | configurable: true 9 | }; 10 | Object.defineProperty( obj, key, config ); 11 | } 12 | 13 | module.exports = construct; -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.12" 4 | - "0.11" 5 | - "0.10" 6 | script: 7 | - "npm run-script test-travis" 8 | after_script: 9 | - "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" 10 | - codeclimate < ./coverage/lcov.info 11 | addons: 12 | code_climate: 13 | repo_token: 9caeb32a0d2ba7177b282a49c919a38beea51696fc3002c373ddc002794a8c3a -------------------------------------------------------------------------------- /lib/resources/Print.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | function print(params, callback) { 5 | var client = require("../http/Client"); 6 | var validator = require("./Validator"); 7 | var method = "GET"; 8 | var uri = "print"; 9 | 10 | validator.params = params; 11 | validator.validatePresence("hash"); 12 | 13 | var config = { 14 | uri : uri, 15 | method : method 16 | }; 17 | 18 | client.send(config, params, function(err , reply) { 19 | if(err) { 20 | callback(err, null); 21 | } else { 22 | callback(null,reply); 23 | } 24 | }); 25 | } 26 | 27 | module.exports = print; -------------------------------------------------------------------------------- /lib/resources/Cancel.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | function cancel(params, callback) { 5 | var client = require("../http/Client"); 6 | var validator = require("./Validator"); 7 | var method = "POST"; 8 | var uri = "ws/cancel"; 9 | 10 | validator.params = params; 11 | validator.validatePresence("hash"); 12 | 13 | var config = { 14 | uri : uri, 15 | method : method, 16 | }; 17 | 18 | client.send(config, params, function(err , reply) { 19 | if(err) { 20 | callback(err, null); 21 | } else { 22 | callback(null,reply); 23 | } 24 | }); 25 | } 26 | 27 | module.exports = cancel; -------------------------------------------------------------------------------- /lib/resources/Zipcode.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | function zipcode(params, callback) { 5 | var client = require("../http/Client"); 6 | var validator = require("./Validator"); 7 | var method = "GET"; 8 | var uri = "ws/zipcode"; 9 | 10 | validator.params = params; 11 | validator.validatePresence("zipcode"); 12 | 13 | var config = { 14 | uri : uri, 15 | method : method 16 | }; 17 | 18 | client.send(config, params, function(err , reply) { 19 | if(err) { 20 | callback(err, null); 21 | } else { 22 | callback(null,reply); 23 | } 24 | }); 25 | } 26 | 27 | module.exports = zipcode; -------------------------------------------------------------------------------- /lib/resources/Exchange.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | function exchange(params, callback) { 5 | var client = require("../http/Client"); 6 | var validator = require("./Validator"); 7 | var method = "GET"; 8 | var uri = "ws/exchange"; 9 | 10 | validator.params = params; 11 | validator.validatePresence("currency_code"); 12 | 13 | var config = { 14 | uri : uri, 15 | method : method 16 | }; 17 | 18 | client.send(config, params, function(err , reply) { 19 | if(err) { 20 | callback(err, null); 21 | } else { 22 | callback(null,reply); 23 | } 24 | }); 25 | } 26 | 27 | module.exports = exchange; -------------------------------------------------------------------------------- /lib/Config.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var Config = function (integrationKey, testMode) { 5 | this.integrationKey = integrationKey; 6 | this.testMode = testMode; 7 | this.usingHttp = true; 8 | }; 9 | 10 | Config.prototype = { 11 | getTestMode : function() { 12 | return this.testMode; 13 | }, 14 | getIntegrationKey : function() { 15 | return this.integrationKey; 16 | }, 17 | 18 | getEndPoint : function() { 19 | if (this.getTestMode()) { 20 | return 'https://sandbox.ebanx.com/'; 21 | } else { 22 | return 'https://api.ebanx.com/'; 23 | } 24 | } 25 | }; 26 | 27 | module.exports = new Config(); -------------------------------------------------------------------------------- /lib/resources/Query.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | function query(params, callback) { 5 | var client = require("../http/Client"); 6 | var validator = require("./Validator"); 7 | var method = "GET"; 8 | var uri = "ws/query"; 9 | 10 | validator.params = params; 11 | validator.validatePresenceOr("hash","merchant_payment_code"); 12 | 13 | var config = { 14 | uri : uri, 15 | method : method 16 | }; 17 | 18 | client.send(config, params, function(err , reply) { 19 | if(err) { 20 | callback(err, null); 21 | } else { 22 | callback(null,reply); 23 | } 24 | }); 25 | } 26 | 27 | module.exports = query; -------------------------------------------------------------------------------- /lib/resources/Capture.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | function capture(params, callback) { 5 | var client = require("../http/Client"); 6 | var validator = require("./Validator"); 7 | var method = "GET"; 8 | var uri = "ws/capture"; 9 | 10 | validator.params = params; 11 | validator.validatePresenceOr("hash", "merchant_payment_code"); 12 | 13 | var config = { 14 | uri : uri, 15 | method : method 16 | }; 17 | 18 | client.send(config, params, function(err , reply) { 19 | if(err) { 20 | callback(err, null); 21 | } else { 22 | callback(null,reply); 23 | } 24 | }); 25 | } 26 | 27 | module.exports = capture; -------------------------------------------------------------------------------- /lib/resources/DocumentBalance.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | function cancel(params, callback) { 5 | var client = require("../http/Client"); 6 | var validator = require("./Validator"); 7 | var method = "GET"; 8 | var uri = "ws/documentbalance"; 9 | 10 | validator.params = params; 11 | validator.validatePresence("currency_code"); 12 | validator.validatePresence("document"); 13 | 14 | var config = { 15 | uri : uri, 16 | method : method 17 | }; 18 | 19 | client.send(config, params, function(err , reply) { 20 | if(err) { 21 | callback(err, null); 22 | } else { 23 | callback(null,reply); 24 | } 25 | }); 26 | } 27 | 28 | module.exports = cancel; -------------------------------------------------------------------------------- /lib/resources/RefundOrCancel.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | function refundOrCancel(params, callback) { 5 | var client = require("../http/Client"); 6 | var validator = require("./Validator"); 7 | var method = "POST"; 8 | var uri = "ws/refundOrCancel"; 9 | 10 | validator.params = params; 11 | validator.validatePresence("hash"); 12 | validator.validatePresence("description"); 13 | 14 | var config = { 15 | uri : uri, 16 | method : method 17 | }; 18 | 19 | client.send(config, params, function(err , reply) { 20 | if(err) { 21 | callback(err, null); 22 | } else { 23 | callback(null,reply); 24 | } 25 | }); 26 | } 27 | 28 | module.exports = refundOrCancel; -------------------------------------------------------------------------------- /tests/ebanxTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var ebanx = require('../lib/ebanx'); 5 | var utils = require('../lib/Config'); 6 | 7 | var eb = ebanx(); 8 | eb.configure({ 9 | integrationKey : "integration_key", 10 | testMode : true 11 | }); 12 | 13 | exports.testIntegrationKey = function(test) { 14 | test.equal( eb.settings.integrationKey, utils.getIntegrationKey()); 15 | test.done(); 16 | }; 17 | 18 | exports.testTestMode = function(test) { 19 | test.equal( eb.settings.testMode, utils.getTestMode()); 20 | test.done(); 21 | }; 22 | 23 | exports.testEndPoint = function(test) { 24 | test.equal( utils.getEndPoint(), "https://sandbox.ebanx.com/"); 25 | eb.configure({ 26 | testMode : false 27 | }); 28 | test.equal( utils.getEndPoint(), "https://api.ebanx.com/"); 29 | test.done(); 30 | }; -------------------------------------------------------------------------------- /lib/resources/Request.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | function request(params, callback) { 5 | var client = require("../http/Client"); 6 | var validator = require("./Validator"); 7 | var method = "POST"; 8 | var uri = "ws/request"; 9 | 10 | validator.params = params; 11 | validator.validatePresence("currency_code"); 12 | validator.validatePresence("amount"); 13 | validator.validatePresence("merchant_payment_code"); 14 | validator.validatePresence("name"); 15 | validator.validatePresence("email"); 16 | validator.validatePresence("payment_type_code"); 17 | 18 | var config = { 19 | uri : uri, 20 | method : method 21 | }; 22 | 23 | client.send(config, params, function(err , reply) { 24 | if(err) { 25 | callback(err, null); 26 | } else { 27 | callback(null,reply); 28 | } 29 | }); 30 | } 31 | 32 | module.exports = request; -------------------------------------------------------------------------------- /lib/resources/Token.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | function token(params, callback) { 5 | var client = require("../http/Client"); 6 | var validator = require("./Validator"); 7 | var method = "POST"; 8 | var uri = "ws/token"; 9 | 10 | validator.params = params; 11 | validator.validatePresence("payment_type_code"); 12 | validator.validatePresence("creditcard.card_number"); 13 | validator.validatePresence("creditcard.card_name"); 14 | validator.validatePresence("creditcard.card_due_date"); 15 | validator.validatePresence("creditcard.card_cvv"); 16 | 17 | var config = { 18 | uri : uri, 19 | method : method, 20 | direct : true 21 | }; 22 | 23 | client.send(config, params, function(err , reply) { 24 | if(err) { 25 | callback(err, null); 26 | } else { 27 | callback(null,reply); 28 | } 29 | }); 30 | } 31 | 32 | module.exports = token; -------------------------------------------------------------------------------- /lib/resources/Direct.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | function direct(params, callback) { 5 | var client = require("../http/Client"); 6 | var validator = require("./Validator"); 7 | var method = "POST"; 8 | var uri = "ws/direct"; 9 | 10 | validator.params = params.payment; 11 | validator.validatePresence("currency_code"); 12 | validator.validatePresence("amount_total"); 13 | validator.validatePresence("merchant_payment_code"); 14 | validator.validatePresence("name"); 15 | validator.validatePresence("email"); 16 | validator.validatePresence("payment_type_code"); 17 | 18 | var config = { 19 | uri : uri, 20 | method : method, 21 | direct : true 22 | }; 23 | 24 | client.send(config, params, function(err , reply) { 25 | if(err) { 26 | callback(err, null); 27 | } else { 28 | callback(null,reply); 29 | } 30 | }); 31 | } 32 | 33 | module.exports = direct; -------------------------------------------------------------------------------- /lib/resources/Refund.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | function refund(params, callback) { 5 | var client = require("../http/Client"); 6 | var validator = require("./Validator"); 7 | var method = "POST"; 8 | var uri = "ws/refund"; 9 | 10 | validator.params = params; 11 | validator.validatePresence("operation"); 12 | 13 | if (params.operation === "request") { 14 | validator.validatePresence("hash"); 15 | validator.validatePresence("amount"); 16 | validator.validatePresence("description"); 17 | 18 | } else { 19 | validator.validatePresenceOr("merchant_refund_code","refund_id"); 20 | } 21 | 22 | var config = { 23 | uri : uri, 24 | method : method 25 | }; 26 | 27 | client.send(config, params, function(err , reply) { 28 | if(err) { 29 | callback(err, null); 30 | } else { 31 | callback(null,reply); 32 | } 33 | }); 34 | } 35 | 36 | module.exports = refund; -------------------------------------------------------------------------------- /lib/autoload.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var config = require("./Config"); 5 | 6 | module.exports = function() { 7 | 8 | function configure(options) { 9 | config.integrationKey = options.integrationKey; 10 | config.testMode = options.testMode; 11 | config.usingHttp = true; 12 | } 13 | 14 | return { 15 | configure : configure, 16 | cancel : require("./resources/Cancel"), 17 | capture : require("./resources/Capture"), 18 | direct : require("./resources/Direct"), 19 | documentBalance : require("./resources/DocumentBalance"), 20 | exchange : require("./resources/Exchange"), 21 | print : require("./resources/Print"), 22 | query : require("./resources/Query"), 23 | refund : require("./resources/Refund"), 24 | refundOrCancel : require("./resources/RefundOrCancel"), 25 | request : require("./resources/Request"), 26 | token : require("./resources/Token"), 27 | zipcode : require("./resources/Zipcode"), 28 | settings : config 29 | }; 30 | }; -------------------------------------------------------------------------------- /tests/ConfigTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var ebanx = require('../lib/ebanx'); 5 | var utils = require('../lib/Config'); 6 | var eb = ebanx(); 7 | 8 | eb.configure({ 9 | integrationKey : "integration_key", 10 | testMode : true 11 | }); 12 | 13 | var should = require('chai').should(); 14 | var expect = require('chai').expect; 15 | 16 | describe('Configuration', function() { 17 | it('Integration Key should be setted', function(done) { 18 | expect(eb.settings.integrationKey).to.be.equal(utils.getIntegrationKey()); 19 | done(); 20 | }) 21 | 22 | it('Test Mode Should be Setted', function(done) { 23 | expect(eb.settings.testMode).to.be.equal(utils.getTestMode()); 24 | done(); 25 | }) 26 | 27 | it('EndPoint return for testMode false and true', function(done) { 28 | expect(utils.getEndPoint()).to.be.equal("https://sandbox.ebanx.com/"); 29 | eb.configure({ 30 | testMode : false 31 | }) 32 | expect(utils.getEndPoint()).to.be.equal("https://api.ebanx.com/"); 33 | done(); 34 | }) 35 | }); -------------------------------------------------------------------------------- /tests/cancelTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var eb = ebanx(); 7 | 8 | eb.configure({ 9 | integrationKey : "integration_key", 10 | testMode : true 11 | }); 12 | 13 | eb.settings.usingHttp = false; 14 | 15 | var hash = {hash:"1234"}; 16 | 17 | var should = require('chai').should(); 18 | var expect = require('chai').expect; 19 | 20 | describe('Cancel Operation', function() { 21 | eb.cancel (hash, function(err, reply) { 22 | it('Should return object', function(done) { 23 | reply.should.be.an('object'); 24 | done(); 25 | }) 26 | 27 | it('Method should be POST', function(done) { 28 | expect(reply.method).to.be.equal("POST"); 29 | done(); 30 | }) 31 | 32 | it('URI should point to ws/cancel', function(done) { 33 | expect(reply.uri).to.be.equal("ws/cancel"); 34 | done(); 35 | }) 36 | 37 | it('Params must be hash', function(done) { 38 | expect(reply).to.have.property("hash"); 39 | done(); 40 | }) 41 | }) 42 | }); -------------------------------------------------------------------------------- /tests/zipcodeTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var eb = ebanx(); 7 | 8 | eb.configure({ 9 | integrationKey : "integration_key", 10 | testMode : true 11 | }); 12 | 13 | eb.settings.usingHttp = false; 14 | 15 | var zipcode = {zipcode : "82530000"}; 16 | 17 | var should = require('chai').should(); 18 | var expect = require('chai').expect; 19 | 20 | describe('Zipcode Operation', function() { 21 | eb.zipcode (zipcode, function(err, reply) { 22 | it('Should return object', function(done) { 23 | reply.should.be.an('object'); 24 | done(); 25 | }) 26 | 27 | it('Method should be GET', function(done) { 28 | expect(reply.method).to.be.equal("GET"); 29 | done(); 30 | }) 31 | 32 | it('URI should point to ws/zipcode', function(done) { 33 | expect(reply.uri).to.be.equal("ws/zipcode"); 34 | done(); 35 | }) 36 | 37 | it('Params must be zipcode', function(done) { 38 | expect(reply).to.have.property("zipcode"); 39 | done(); 40 | }) 41 | }) 42 | }); -------------------------------------------------------------------------------- /tests/printTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var eb = ebanx(); 7 | 8 | eb.configure({ 9 | integrationKey : "integration_key", 10 | testMode : true 11 | }); 12 | 13 | eb.settings.usingHttp = false; 14 | 15 | var hash = {hash : "552c21d21c55dd815c92ca69d937603913f1e69153916b0f"}; 16 | 17 | var should = require('chai').should(); 18 | var expect = require('chai').expect; 19 | 20 | describe('Print Operation', function() { 21 | eb.print (hash, function(err, reply) { 22 | it('Should return object', function(done) { 23 | reply.should.be.an('object'); 24 | done(); 25 | }) 26 | 27 | it('Method should be GET', function(done) { 28 | expect(reply.method).to.be.equal("GET"); 29 | done(); 30 | }) 31 | 32 | it('URI should point to print', function(done) { 33 | expect(reply.uri).to.be.equal("print"); 34 | done(); 35 | }) 36 | 37 | it('Param must have hash', function(done) { 38 | expect(reply).to.have.property("hash"); 39 | done(); 40 | }) 41 | }) 42 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Heitor Dolinski (http://www.ebanx.com/)", 3 | "license": "ISC", 4 | "name": "ebanx", 5 | "version": "1.5.0", 6 | "homepage": "https://github.com/ebanx-integration/ebanx-nodejs", 7 | "description": "Provides access to EBANX API", 8 | "main": "index.js", 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/ebanx-integration/ebanx-nodejs" 12 | }, 13 | "dependencies": { 14 | "request": "2.*.*" 15 | }, 16 | "devDependencies": { 17 | "chai": "2.3.0", 18 | "coveralls": "2.10.0", 19 | "mocha": "^2.2.4", 20 | "istanbul": "0.3.5", 21 | "codeclimate-test-reporter": "*" 22 | 23 | }, 24 | "scripts": { 25 | "test": "./node_modules/mocha/bin/mocha --recursive ./tests", 26 | "test-travis": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec ./tests" 27 | }, 28 | "keywords": [ 29 | "ebanx", 30 | "payment gateway", 31 | "boleto bancario" 32 | ], 33 | "readmeFilename": "README.md", 34 | "bugs": { 35 | "url": "https://github.com/ebanx-integration/ebanx-nodejs/issues" 36 | } 37 | } -------------------------------------------------------------------------------- /tests/directTestToken.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var eb = ebanx(); 7 | 8 | eb.configure({ 9 | integrationKey : "integration_key", 10 | testMode : true 11 | }); 12 | 13 | eb.settings.usingHttp = false; 14 | 15 | var direct = { 16 | payment : { 17 | name : "carlos test", 18 | email : "carlos@test.com", 19 | birth_date : "12/04/1979", 20 | document : "853.513.468.93", 21 | address : "Rua e", 22 | street_number : "1040", 23 | city : "Curitiba", 24 | state : "PR", 25 | zipcode : "82530000", 26 | country : "br", 27 | phone_number : "32329913", 28 | payment_type_code : "visa", 29 | merchant_payment_code : "123141dafefesf", 30 | currency_code : "BRL", 31 | amount_total : 423.00, 32 | creditcard : { 33 | token : "123" 34 | } 35 | } 36 | }; 37 | 38 | var should = require('chai').should(); 39 | var expect = require('chai').expect; 40 | 41 | describe('Direct Operation Credit Card Tolkien',function() { 42 | eb.direct (direct, function(err, reply) { 43 | it('Should test creditcard.token object', function(done) { 44 | expect(reply.payment.creditcard).to.have.property("token"); 45 | done(); 46 | }) 47 | }) 48 | }); -------------------------------------------------------------------------------- /tests/exchangeTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var test = require('assert'); 7 | var eb = ebanx(); 8 | 9 | eb.configure({ 10 | integrationKey : "integration_key", 11 | testMode : true 12 | }); 13 | 14 | eb.settings.usingHttp = false; 15 | 16 | var currency = {currency_code : "USD", currency_base : "BRL"}; 17 | 18 | var should = require('chai').should(); 19 | var expect = require('chai').expect; 20 | 21 | describe('Exchange Operation', function() { 22 | eb.exchange (currency, function(err, reply) { 23 | it('Should return object', function(done) { 24 | reply.should.be.an('object'); 25 | done(); 26 | }) 27 | 28 | it('Method should be GET', function(done) { 29 | expect(reply.method).to.be.equal("GET"); 30 | done(); 31 | }) 32 | 33 | it('URI should point to ws/exchange', function(done) { 34 | expect(reply.uri).to.be.equal("ws/exchange"); 35 | done(); 36 | }) 37 | 38 | it('Param must have currency_code', function(done) { 39 | expect(reply).to.have.property("currency_code"); 40 | done(); 41 | }) 42 | 43 | it('Param must have currency_base', function(done) { 44 | expect(reply).to.have.property("currency_base"); 45 | done(); 46 | }) 47 | }) 48 | }); -------------------------------------------------------------------------------- /tests/directTestDebit.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var eb = ebanx(); 7 | 8 | eb.configure({ 9 | integrationKey : "integration_key", 10 | testMode : true 11 | }); 12 | 13 | eb.settings.usingHttp = false; 14 | 15 | var direct = { 16 | payment : { 17 | name : "carlos test", 18 | email : "carlos@test.com", 19 | birth_date : "12/04/1979", 20 | document : "853.513.468.93", 21 | address : "Rua e", 22 | street_number : "1040", 23 | city : "Curitiba", 24 | state : "PR", 25 | zipcode : "82530000", 26 | country : "br", 27 | phone_number : "32329913", 28 | payment_type_code : "directdebit", 29 | merchant_payment_code : "123141dafefesf", 30 | currency_code : "BRL", 31 | amount_total : 423.00, 32 | directdebit : { 33 | bank_code: "033", 34 | bank_agency: "12345", 35 | bank_account: "12345" 36 | } 37 | } 38 | }; 39 | 40 | var should = require('chai').should(); 41 | var expect = require('chai').expect; 42 | 43 | describe('Direct Operation Debit', function() { 44 | eb.direct (direct, function(err, reply) { 45 | it('Should test directdebit object', function(done) { 46 | expect(reply.payment).to.have.property("directdebit"); 47 | done(); 48 | }) 49 | }) 50 | }); -------------------------------------------------------------------------------- /tests/documentBalanceTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var test = require('assert'); 7 | var eb = ebanx(); 8 | 9 | eb.configure({ 10 | integrationKey : "integration_key", 11 | testMode : true 12 | }); 13 | 14 | eb.settings.usingHttp = false; 15 | 16 | var currency = {currency_code : "USD", document : "853.513.468.93"}; 17 | 18 | var should = require('chai').should(); 19 | var expect = require('chai').expect; 20 | 21 | describe('DocumentBalance Operation', function() { 22 | eb.documentBalance (currency, function(err, reply) { 23 | it('Should return object', function(done) { 24 | reply.should.be.an('object'); 25 | done(); 26 | }) 27 | 28 | it('Method should be GET', function(done) { 29 | expect(reply.method).to.be.equal("GET"); 30 | done(); 31 | }) 32 | 33 | it('URI should point to ws/documentbalance', function(done) { 34 | expect(reply.uri).to.be.equal("ws/documentbalance"); 35 | done(); 36 | }) 37 | 38 | it('Param must have currency_code', function(done) { 39 | expect(reply).to.have.property("currency_code"); 40 | done(); 41 | }) 42 | 43 | it('Param must have document', function(done) { 44 | expect(reply).to.have.property("document"); 45 | done(); 46 | }) 47 | }) 48 | }); -------------------------------------------------------------------------------- /tests/directTestCreditCard.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var eb = ebanx(); 7 | 8 | eb.configure({ 9 | integrationKey : "integration_key", 10 | testMode : true 11 | }); 12 | 13 | eb.settings.usingHttp = false; 14 | 15 | var direct = { 16 | payment : { 17 | name : "carlos test", 18 | email : "carlos@test.com", 19 | birth_date : "12/04/1979", 20 | document : "853.513.468.93", 21 | address : "Rua e", 22 | street_number : "1040", 23 | city : "Curitiba", 24 | state : "PR", 25 | zipcode : "82530000", 26 | country : "br", 27 | phone_number : "32329913", 28 | payment_type_code : "visa", 29 | merchant_payment_code : "123141dafefesf", 30 | currency_code : "BRL", 31 | amount_total : 423.00, 32 | creditcard : { 33 | card_number : "4111111111111111", 34 | card_name : "Jose da Silva", 35 | card_due_date : "10/2018", 36 | card_cvv : "123" 37 | } 38 | } 39 | }; 40 | 41 | var should = require('chai').should(); 42 | var expect = require('chai').expect; 43 | 44 | describe('Direct Operation Credit Card', function() { 45 | eb.direct (direct, function(err, reply) { 46 | it('Should test creditcard object', function(done) { 47 | expect(reply.payment).to.have.property("creditcard"); 48 | done(); 49 | }) 50 | }) 51 | }); -------------------------------------------------------------------------------- /tests/refundOrCancelTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var eb = ebanx(); 7 | 8 | eb.configure({ 9 | integrationKey : "integration_key", 10 | testMode : true 11 | }); 12 | 13 | eb.settings.usingHttp = false; 14 | 15 | var should = require('chai').should(); 16 | var expect = require('chai').expect; 17 | 18 | var refund = { 19 | hash : "552c21d21c55dd815c92ca69d937603913f1e69153916b0f", 20 | description : "Lorem ipsum dolor sit amet." 21 | }; 22 | 23 | describe('RefundOrCancel Operation', function() { 24 | eb.refundOrCancel (refund, function(err, reply) { 25 | it('Should return object', function(done) { 26 | reply.should.be.an('object'); 27 | done(); 28 | }) 29 | 30 | it('Method should be POST', function(done) { 31 | expect(reply.method).to.be.equal("POST"); 32 | done(); 33 | }) 34 | 35 | it('URI should point to ws/refundOrCancel', function(done) { 36 | expect(reply.uri).to.be.equal("ws/refundOrCancel"); 37 | done(); 38 | }) 39 | 40 | it('Params should have hash', function(done) { 41 | expect(reply).to.have.property("hash"); 42 | done(); 43 | }) 44 | 45 | it('Params should have description', function(done) { 46 | expect(reply.description).to.be.equal(refund.description); 47 | done(); 48 | }) 49 | }) 50 | }); -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, EBANX Tecnologia da Informação Ltda. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of EBANX nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /tests/directPersonType.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var eb = ebanx(); 7 | 8 | eb.configure({ 9 | integrationKey : "integration_key", 10 | testMode : true 11 | }); 12 | 13 | eb.settings.usingHttp = false; 14 | 15 | var direct = { 16 | payment : { 17 | name : "Fabricas Branco Ltda.", 18 | email : "fabricasbranco@example.com", 19 | birth_date : "12/04/1979", 20 | document : "01/03/1985", 21 | address :"Rua E", 22 | street_number : "1040", 23 | city : "Maracanaú", 24 | state : "CE", 25 | zipcode : "61919-230", 26 | country : "br", 27 | person_type: "business", 28 | responsible: { 29 | name: "José Silva", 30 | birth_date: "12/04/1979", 31 | document: "853.513.468-93" 32 | }, 33 | phone_number : "8522847035", 34 | payment_type_code : "boleto", 35 | merchant_payment_code : "0efa347229e", 36 | currency_code : "BRL", 37 | amount_total : "100.00" 38 | } 39 | }; 40 | 41 | var should = require('chai').should(); 42 | var expect = require('chai').expect; 43 | 44 | describe('Direct Operation Person Type', function() { 45 | eb.direct (direct, function(err, reply) { 46 | it('Should test person_type="business"', function(done) { 47 | expect(reply.payment.person_type).to.be.equal("business"); 48 | done(); 49 | }) 50 | 51 | it('Should test responsible object for person_type="business"', function(done) { 52 | expect(reply.payment).to.have.property("responsible"); 53 | done(); 54 | }) 55 | }) 56 | }); -------------------------------------------------------------------------------- /tests/httpTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var config = require('../lib/Config'); 5 | 6 | var hash = {hash : "552c21d21c55dd815c92ca69d937603913f1e69153916b0f"}; 7 | 8 | var should = require('chai').should(); 9 | var expect = require('chai').expect; 10 | 11 | describe('HTTP Client test', function() { 12 | var ebanx = require('../lib/ebanx'); 13 | var eb = ebanx(); 14 | 15 | it('Should return response', function(done) { 16 | 17 | eb.configure({ 18 | integrationKey : "integration_key", 19 | testMode : true 20 | }); 21 | 22 | eb.settings.usingHttp = true; 23 | eb.query (hash, function(err, reply) { 24 | should.exist(reply); 25 | done(); 26 | }) 27 | 28 | }) 29 | 30 | it('Should return error from API', function(done) { 31 | eb.query (hash, function(err, reply) { 32 | var reply = JSON.parse(reply); 33 | expect(reply.status).to.be.equal("ERROR"); 34 | done(); 35 | }) 36 | 37 | }) 38 | 39 | it('Should test direct method', function(done) { 40 | var direct = { 41 | payment : { 42 | name : "carlos test", 43 | email : "carlos@test.com", 44 | birth_date : "12/04/1979", 45 | document : "853.513.468.93", 46 | address : "Rua e", 47 | street_number : "1040", 48 | city : "Curitiba", 49 | state : "PR", 50 | zipcode : "82530000", 51 | country : "br", 52 | phone_number : "32329913", 53 | payment_type_code : "itau", 54 | merchant_payment_code : "123141dafefesf", 55 | currency_code : "BRL", 56 | amount_total : 423.00 57 | } 58 | }; 59 | 60 | eb.direct (direct, function(err, reply) { 61 | should.not.exist(err); 62 | should.exist(reply); 63 | done(); 64 | }) 65 | }) 66 | }); -------------------------------------------------------------------------------- /lib/http/Client.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var config = require("../Config"); 5 | var validator = require("../resources/Validator"); 6 | var constructor = require('../resources/Constructor'); 7 | var Client = function () {}; 8 | 9 | Client.prototype.send = function (options, params, callback) { 10 | var url = config.getEndPoint() + options.uri; 11 | var method = options.method; 12 | var data = {}; 13 | 14 | for (var i in params) { 15 | constructor(data, i, params[i]); 16 | } 17 | 18 | if (!config.usingHttp) { 19 | for (var i in options) { 20 | constructor(data, i, options[i]); 21 | } 22 | callback(null, data); 23 | } else { 24 | var req = require("request"); 25 | validator.validateConfig(config); 26 | 27 | options.params = data; 28 | options.params.integration_key = config.integrationKey; 29 | 30 | // If is Direct operation, change some parameters 31 | if (options.direct) { 32 | options.params.operation = "request"; 33 | var request = { request_body : JSON.stringify(options.params)}; 34 | 35 | req({ 36 | url: url, 37 | headers: { 38 | 'User-Agent': 'EBANX NodeJS Module Direct' 39 | }, 40 | method: method, 41 | form : request 42 | }, function(error, response, body) { 43 | if (error) { 44 | throw new Error(error); 45 | } else { 46 | callback(null, body); 47 | } 48 | }); 49 | } else { 50 | req({ 51 | url: url, 52 | headers: { 53 | 'User-Agent': 'EBANX NodeJS Module' 54 | }, 55 | method: method, 56 | qs : options.params 57 | }, function(error, response, body) { 58 | if (error) { 59 | throw new Error(error); 60 | } else { 61 | callback(null, body); 62 | } 63 | }); 64 | } 65 | } 66 | }; 67 | 68 | module.exports = new Client(); -------------------------------------------------------------------------------- /lib/resources/Validator.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var Validator = function (params) { 5 | this.params = params; 6 | }; 7 | 8 | Validator.prototype = { 9 | exists : function(key) { 10 | if (key.indexOf(".") > 0) { 11 | var keys = key.split("."); 12 | var levels = keys.length; 13 | var params = this.params; 14 | 15 | if (levels === 4) { 16 | if (params[keys[0]][keys[1]][keys[2]][keys[3]]) { 17 | return params[keys[0]][keys[1]][keys[2]][keys[3]]; 18 | } 19 | } 20 | else if (levels === 3) { 21 | if (params[keys[0]][keys[1]][keys[2]]) { 22 | return params[keys[0]][keys[1]][keys[2]]; 23 | } 24 | 25 | } 26 | else { 27 | if (params[keys[0]][keys[1]]) { 28 | return params[keys[0]][keys[1]]; 29 | } 30 | } 31 | } 32 | 33 | if (this.params.hasOwnProperty(key)) { 34 | return true; 35 | } 36 | 37 | return false; 38 | }, 39 | validatePresence : function(key) { 40 | if(this.exists(key)) { 41 | return true; 42 | } 43 | throw new Error("The parameter " + key + " was not supplied."); 44 | }, 45 | 46 | validatePresenceOr : function(key1, key2) { 47 | if(this.exists(key1)) { 48 | if(this.exists(key2)) { 49 | throw new Error("Either parameter " + key1 + " or " + key2 + " must be supplied, but not both."); 50 | } 51 | 52 | return true; 53 | } 54 | else if(this.exists(key2)) { 55 | return true; 56 | } 57 | 58 | throw new Error("Either the parameter " + key1 + " or " + key2 + " must be supplied."); 59 | }, 60 | 61 | validateConfig : function(config) { 62 | if (!config.integrationKey) { 63 | throw new Error("Config value integrationKey not informed"); 64 | } 65 | if (typeof(config.testMode) !== "boolean") { 66 | throw new Error("Config key testMode not boolean value"); 67 | } 68 | } 69 | }; 70 | 71 | module.exports = new Validator(); -------------------------------------------------------------------------------- /tests/captureTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var eb = ebanx(); 7 | 8 | eb.configure({ 9 | integrationKey : "integration_key", 10 | testMode : true 11 | }); 12 | 13 | eb.settings.usingHttp = false; 14 | 15 | var hash = {hash : "552c21d21c55dd815c92ca69d937603913f1e69153916b0f"}; 16 | 17 | var merchant_payment_code = {merchant_payment_code : "1428955597"}; 18 | 19 | var should = require('chai').should(); 20 | var expect = require('chai').expect; 21 | 22 | describe('Capture Operation With Hash', function() { 23 | eb.capture ({hash : hash}, function(err, reply) { 24 | it('Should return object', function(done) { 25 | reply.should.be.an('object'); 26 | done(); 27 | }) 28 | 29 | it('Method should be GET', function(done) { 30 | expect(reply.method).to.be.equal("GET"); 31 | done(); 32 | }) 33 | 34 | it('URI should point to ws/capture', function(done) { 35 | expect(reply.uri).to.be.equal("ws/capture"); 36 | done(); 37 | }) 38 | 39 | it('Params must be hash', function(done) { 40 | expect(reply).to.have.property("hash"); 41 | done(); 42 | }) 43 | }) 44 | }); 45 | 46 | describe('Capture Operation With Merchant Payment Code', function() { 47 | eb.capture ({merchant_payment_code : merchant_payment_code}, function(err, reply) { 48 | it('Should return object', function(done) { 49 | reply.should.be.an('object'); 50 | done(); 51 | }) 52 | 53 | it('Method should be GET', function(done) { 54 | expect(reply.method).to.be.equal("GET"); 55 | done(); 56 | }) 57 | 58 | it('URI should point to ws/capture', function(done) { 59 | expect(reply.uri).to.be.equal("ws/capture"); 60 | done(); 61 | }) 62 | 63 | it('Params must be merchant_payment_code', function(done) { 64 | expect(reply).to.have.property("merchant_payment_code"); 65 | done(); 66 | }) 67 | }) 68 | }); -------------------------------------------------------------------------------- /tests/queryTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var test = require('assert'); 7 | var eb = ebanx(); 8 | 9 | eb.configure({ 10 | integrationKey : "integration_key", 11 | testMode : true 12 | }); 13 | 14 | eb.settings.usingHttp = false; 15 | 16 | var hash = {hash : "552c21d21c55dd815c92ca69d937603913f1e69153916b0f"}; 17 | 18 | var merchant_payment_code = {merchant_payment_code : "1428955597"}; 19 | 20 | var should = require('chai').should(); 21 | var expect = require('chai').expect; 22 | 23 | describe('Query Operation With Hash', function() { 24 | eb.query ({hash : hash}, function(err, reply) { 25 | it('Should return object', function(done) { 26 | reply.should.be.an('object'); 27 | done(); 28 | }) 29 | 30 | it('Method should be GET', function(done) { 31 | expect(reply.method).to.be.equal("GET"); 32 | done(); 33 | }) 34 | 35 | it('URI should point to ws/query', function(done) { 36 | expect(reply.uri).to.be.equal("ws/query"); 37 | done(); 38 | }) 39 | 40 | it('Params must be hash', function(done) { 41 | expect(reply).to.have.property("hash"); 42 | done(); 43 | }) 44 | }) 45 | }); 46 | 47 | describe('Query Operation With Hash', function() { 48 | eb.query ({merchant_payment_code : merchant_payment_code}, function(err, reply) { 49 | it('Should return object', function(done) { 50 | reply.should.be.an('object'); 51 | done(); 52 | }) 53 | 54 | it('Method should be GET', function(done) { 55 | expect(reply.method).to.be.equal("GET"); 56 | done(); 57 | }) 58 | 59 | it('URI should point to ws/query', function(done) { 60 | expect(reply.uri).to.be.equal("ws/query"); 61 | done(); 62 | }) 63 | 64 | it('Params must be merchant_payment_code', function(done) { 65 | expect(reply).to.have.property("merchant_payment_code"); 66 | done(); 67 | }) 68 | }) 69 | }); -------------------------------------------------------------------------------- /tests/tokenTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var test = require('assert'); 7 | var eb = ebanx(); 8 | 9 | eb.configure({ 10 | integrationKey : "integration_key", 11 | testMode : true 12 | }); 13 | 14 | eb.settings.usingHttp = false; 15 | 16 | var creditcard = { 17 | payment_type_code : "visa", 18 | creditcard : { 19 | card_number : "4111111111111111", 20 | card_name : "Jose da Silva", 21 | card_due_date : "10/2018", 22 | card_cvv : "123" 23 | } 24 | }; 25 | 26 | var should = require('chai').should(); 27 | var expect = require('chai').expect; 28 | 29 | describe('Token Operation', function() { 30 | eb.token (creditcard, function(err, reply) { 31 | it('Should return object', function(done) { 32 | reply.should.be.an('object'); 33 | done(); 34 | }) 35 | 36 | it('Method should be POST', function(done) { 37 | expect(reply.method).to.be.equal("POST"); 38 | done(); 39 | }) 40 | 41 | it('URI should point to ws/token', function(done) { 42 | expect(reply.uri).to.be.equal("ws/token"); 43 | done(); 44 | }) 45 | 46 | it('Params should have payment_type_code', function(done) { 47 | expect(reply).to.have.property("payment_type_code"); 48 | done(); 49 | }) 50 | 51 | it('Params should have creditcard.card_number', function(done) { 52 | expect(reply.creditcard).to.have.property("card_number"); 53 | done(); 54 | }) 55 | 56 | it('Params should have creditcard.card_name', function(done) { 57 | expect(reply.creditcard).to.have.property("card_name"); 58 | done(); 59 | }) 60 | 61 | it('Params should have creditcard.card_due_date', function(done) { 62 | expect(reply.creditcard).to.have.property("card_due_date"); 63 | done(); 64 | }) 65 | 66 | it('Params should have creditcard.card_cvv', function(done) { 67 | expect(reply.creditcard).to.have.property("card_cvv"); 68 | done(); 69 | }) 70 | }) 71 | }); -------------------------------------------------------------------------------- /tests/refundTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var eb = ebanx(); 7 | 8 | eb.configure({ 9 | integrationKey : "integration_key", 10 | testMode : true 11 | }); 12 | 13 | eb.settings.usingHttp = false; 14 | 15 | var refund = { 16 | hash : "552c21d21c55dd815c92ca69d937603913f1e69153916b0f", 17 | description : "Lorem ipsum dolor sit amet.", 18 | amount : "1.00", 19 | operation : "request" 20 | }; 21 | 22 | var should = require('chai').should(); 23 | var expect = require('chai').expect; 24 | 25 | describe('Refund Operation', function() { 26 | eb.refund (refund, function(err, reply) { 27 | it('Should return object', function(done) { 28 | reply.should.be.an('object'); 29 | done(); 30 | }) 31 | 32 | it('Method should be POST', function(done) { 33 | expect(reply.method).to.be.equal("POST"); 34 | done(); 35 | }) 36 | 37 | it('URI should point to ws/refund', function(done) { 38 | expect(reply.uri).to.be.equal("ws/refund"); 39 | done(); 40 | }) 41 | 42 | it('Params should have hash', function(done) { 43 | expect(reply).to.have.property("hash"); 44 | done(); 45 | }) 46 | 47 | it('Params should have description', function(done) { 48 | expect(reply).to.have.property("description"); 49 | done(); 50 | }) 51 | 52 | it('Params should have amount', function(done) { 53 | expect(reply).to.have.property("amount"); 54 | done(); 55 | }) 56 | 57 | it('Params should have operation', function(done) { 58 | expect(reply).to.have.property("operation"); 59 | done(); 60 | }) 61 | }) 62 | }); 63 | 64 | describe('Refund Operation Cancel', function() { 65 | var refund = { 66 | hash : "552c21d21c55dd815c92ca69d937603913f1e69153916b0f", 67 | description : "Lorem ipsum dolor sit amet.", 68 | amount : "1.00", 69 | operation : "cancel", 70 | refund_id : "123" 71 | }; 72 | eb.refund (refund, function(err, reply) { 73 | it('Should test operation', function(done) { 74 | expect(reply).to.have.property("refund_id"); 75 | done(); 76 | }) 77 | }) 78 | }); -------------------------------------------------------------------------------- /tests/requestTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var eb = ebanx(); 7 | 8 | eb.configure({ 9 | integrationKey : "integration_key", 10 | testMode : true 11 | }); 12 | 13 | eb.settings.usingHttp = false; 14 | 15 | var request = { 16 | name : "carlos test", 17 | email : "carlos@test.com", 18 | country : "br", 19 | payment_type_code : "boleto", 20 | merchant_payment_code : "123141dafefesf", 21 | currency_code : "BRL", 22 | amount : 423.00 23 | } 24 | 25 | var should = require('chai').should(); 26 | var expect = require('chai').expect; 27 | 28 | describe('Request Operation With Hash', function() { 29 | eb.request (request, function(err, reply) { 30 | it('Should return object', function(done) { 31 | reply.should.be.an('object'); 32 | done(); 33 | }) 34 | 35 | it('Method should be POST', function(done) { 36 | expect(reply.method).to.be.equal("POST"); 37 | done(); 38 | }) 39 | 40 | it('URI should point to ws/request', function(done) { 41 | expect(reply.uri).to.be.equal("ws/request"); 42 | done(); 43 | }) 44 | 45 | it('Params should have name', function(done) { 46 | expect(reply).to.have.property("name"); 47 | done(); 48 | }) 49 | 50 | it('Params should have email', function(done) { 51 | expect(reply).to.have.property("email"); 52 | done(); 53 | }) 54 | 55 | it('Params should have country', function(done) { 56 | expect(reply).to.have.property("country"); 57 | done(); 58 | }) 59 | 60 | it('Params should have payment_type_code', function(done) { 61 | expect(reply).to.have.property("payment_type_code"); 62 | done(); 63 | }) 64 | 65 | it('Params should have merchant_payment_code', function(done) { 66 | expect(reply).to.have.property("merchant_payment_code"); 67 | done(); 68 | }) 69 | 70 | it('Params should have currency_code', function(done) { 71 | expect(reply).to.have.property("currency_code"); 72 | done(); 73 | }) 74 | 75 | it('Params should have amount', function(done) { 76 | expect(reply).to.have.property("amount"); 77 | done(); 78 | }) 79 | }) 80 | }); -------------------------------------------------------------------------------- /tests/validatorTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var validator = require('../lib/resources/Validator'); 5 | 6 | var should = require('chai').should(); 7 | var expect = require('chai').expect; 8 | 9 | describe('Validator module', function() { 10 | var token = { 11 | payment_type_code : "visa", 12 | creditcard : { 13 | card_number : "4111111111111111", 14 | card_name : "eita teste", 15 | card_due_date : "10/2020", 16 | card_cvv : "123", 17 | levelThree : { 18 | thisIsLevelThree : { 19 | yetAnotherLevel : "test" 20 | } 21 | } 22 | } 23 | } 24 | 25 | it('Should have hash (simple level)', function(done) { 26 | validator.params = {hash : "LoremIpsum"}; 27 | expect(validator.validatePresence("hash")).to.be.ok; 28 | done(); 29 | }) 30 | 31 | it('Should have creditcard.card_number (level two)', function(done) { 32 | validator.params = token; 33 | expect(validator.validatePresence("creditcard.card_number")).to.be.ok; 34 | done(); 35 | }) 36 | 37 | it('Should have creditcard.levelThree.thisIsLevelThree (level three)', function(done) { 38 | validator.params = token; 39 | expect(validator.validatePresence("creditcard.levelThree.thisIsLevelThree")).to.be.ok; 40 | done(); 41 | }) 42 | 43 | it('Should have creditcard.levelThree.thisIsLevelThree.yetAnotherLevel (level four)', function(done) { 44 | validator.params = token; 45 | expect(validator.validatePresence("creditcard.levelThree.thisIsLevelThree.yetAnotherLevel")).to.be.ok; 46 | done(); 47 | }) 48 | 49 | it('Should test integrationKey config error', function(done) { 50 | var err = new Error('Config value integrationKey not informed'); 51 | var config = { 52 | integrationKey : "", 53 | testMode : true 54 | } 55 | expect(function() { 56 | validator.validateConfig(config); 57 | }).to.throw('Config value integrationKey not informed'); 58 | 59 | done(); 60 | }) 61 | 62 | it('Should test testMode config error', function(done) { 63 | var config = { 64 | integrationKey : "integration_key", 65 | testMode : "true" 66 | } 67 | expect(function() { 68 | validator.validateConfig(config); 69 | }).to.throw('Config key testMode not boolean value'); 70 | 71 | done(); 72 | }) 73 | 74 | it('Should test presence error', function(done) { 75 | var params = {}; 76 | 77 | validator.params = params; 78 | expect(function() { 79 | validator.validatePresence("hash"); 80 | }).to.throw('The parameter hash was not supplied.'); 81 | 82 | done(); 83 | }) 84 | 85 | it('Should test presenceOr error: absence', function(done) { 86 | var params = {}; 87 | 88 | validator.params = params; 89 | expect(function() { 90 | validator.validatePresenceOr("hash", "merchant_payment_code"); 91 | }).to.throw('Either the parameter hash or merchant_payment_code must be supplied.'); 92 | 93 | done(); 94 | }) 95 | 96 | it('Should test presenceOr error: double presence', function(done) { 97 | var params = {hash : "foo", merchant_payment_code : "bar"}; 98 | 99 | validator.params = params; 100 | expect(function() { 101 | validator.validatePresenceOr("hash", "merchant_payment_code"); 102 | }).to.throw('Either parameter hash or merchant_payment_code must be supplied, but not both.'); 103 | 104 | done(); 105 | }) 106 | }); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | EBANX NodeJs Module: 2 | ============== 3 | EBANX is the market leader in e-commerce payment solutions for International Merchants selling online to Brazil. This module enables you to integrate EBANX with NodeJs. 4 | 5 | Continuous Integration status: 6 | 7 | [![Build Status](https://travis-ci.org/ebanx-integration/ebanx-nodejs.svg?branch=master)](https://travis-ci.org/ebanx-integration/ebanx-nodejs) [![Coverage Status](https://codeclimate.com/github/ebanx-integration/ebanx-nodejs/badges/coverage.svg)](https://coveralls.io/r/ebanx-integration/ebanx-nodejs) 8 | [![Code Climate](https://codeclimate.com/github/ebanx-integration/ebanx-nodejs/badges/gpa.svg)](https://codeclimate.com/github/ebanx-integration/ebanx-nodejs) 9 | 10 | NPM status: 11 | 12 | [![NPM version](https://badge.fury.io/js/ebanx.svg)](https://badge.fury.io/js/ebanx) 13 | [![Dependency Status](https://david-dm.org/ebanx-integration/ebanx-nodejs.svg)](https://david-dm.org/ebanx-integration/ebanx-nodejs) 14 | 15 | 16 | [![Shields](https://img.shields.io/badge/awesome-yes-brightgreen.svg)](http://shields.io/) 17 | 18 | Installation 19 | ----------- 20 | 21 | ### npm 22 | 23 | npm install ebanx 24 | 25 | Usage 26 | --------- 27 | ```javascript 28 | //Require the module 29 | var ebanx; 30 | var ebanxMod; 31 | ebanxMod = require('ebanx'); 32 | ebanx = new ebanxMod(); 33 | 34 | //Configure the integration key and test mode 35 | ebanx.configure({ 36 | integrationKey : '1231000', 37 | testMode : true 38 | }); 39 | ``` 40 | 41 | You can change the following settings: 42 | *integrationKey: your integration key. It will be different in test and production modes. 43 | *testMode: enable or disable the test mode. The default value is _true_. 44 | 45 | To create a new API request, just call one of the following functions 46 | on the ebanx object and supply it with the request parameters: 47 | * ebanx.cancel() 48 | * ebanx.capture() 49 | * ebanx.direct() 50 | * ebanx.documentBalance() 51 | * ebanx.exchange() 52 | * ebanx.print() 53 | * ebanx.query() 54 | * ebanx.refund() 55 | * ebanx.refundOrCancel() 56 | * ebanx.request() 57 | * ebanx.token() 58 | * ebanx.zipcode() 59 | 60 | You can check your settings by accessing the settings module: 61 | * ebanx.settings 62 | * ebanx.settings.integrationKey 63 | * ebanx.settings.testMode 64 | 65 | #Examples: 66 | 67 | ```javascript 68 | 69 | var ebanx; 70 | var ebanxMod; 71 | ebanxMod = require('ebanx'); 72 | ebanx = new ebanxMod(); 73 | 74 | //Configuring the module 75 | ebanx.configure({ 76 | integrationKey : '1231000', 77 | testMode : true 78 | }); 79 | 80 | //Creating new checkout payment 81 | 82 | var params = { 83 | currency_code : 'USD', 84 | 'amount' : '22.00', 85 | 'name' : 'Jose da Silva', 86 | 'email' : 'jose@example.org', 87 | 'payment_type_code' : '_all', 88 | 'merchant_payment_code' : "example123" //must be unique 89 | }; 90 | 91 | ebanx.request(params, function(error, reply) { 92 | if(error) { 93 | console.log(error); 94 | } else { 95 | console.log(reply); 96 | } 97 | }); 98 | 99 | ``` 100 | 101 | ## Changelog 102 | * **1.5.0**: Implemented dynamic object construction for request 103 | * **1.4.1**: Corrected indentation 104 | * **1.4.0**: Added documentBalance operation 105 | * **1.3.0**: Codeclimate integration 106 | * **1.2.8**: Corrected Direct Debit. Added Business Person Type 107 | * **1.2.7**: Adapted to Coveralls. 108 | * **1.2.6**: Added dependency badge 109 | * **1.2.5**: Changed require capital letter for Validator 110 | * **1.2.4**: Corrected unit testings 111 | * **1.2.3**: Changed require capital letter 112 | * **1.2.2**: Added validation on "testMode". 113 | * **1.2.1**: Calling Config module in Client only. 114 | * **1.2.0**: Refactored coding. Changed Config module. 115 | * **1.1.2**: Corrected double params in certain requests. Corrected Client module. 116 | * **1.1.1**: Saved integration_key on file for tests. 117 | * **1.1.0**: Implemented error first callbacks. 118 | * **1.0.0**: Using Request Module. Added Test Cases. 119 | * **0.2.1**: Added Validator module. 120 | * **0.1.1**: Structured Client code. 121 | * **0.1.0**: Added Direct and Token operations. 122 | * **0.0.1**: Beta release. -------------------------------------------------------------------------------- /tests/directTest.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 EBANX */ 2 | 'use strict'; 3 | 4 | var utils = require('../lib/Config'); 5 | var ebanx = require('../lib/ebanx'); 6 | var eb = ebanx(); 7 | 8 | eb.configure({ 9 | integrationKey : "integration_key", 10 | testMode : true 11 | }); 12 | 13 | eb.settings.usingHttp = false; 14 | 15 | var direct = { 16 | payment : { 17 | name : "carlos test", 18 | email : "carlos@test.com", 19 | birth_date : "12/04/1979", 20 | document : "853.513.468.93", 21 | address : "Rua e", 22 | street_number : "1040", 23 | city : "Curitiba", 24 | state : "PR", 25 | zipcode : "82530000", 26 | country : "br", 27 | phone_number : "32329913", 28 | payment_type_code : "itau", 29 | merchant_payment_code : "123141dafefesf", 30 | currency_code : "BRL", 31 | amount_total : 423.00 32 | 33 | } 34 | }; 35 | 36 | var should = require('chai').should(); 37 | var expect = require('chai').expect; 38 | 39 | describe('Direct Operation Boleto', function() { 40 | eb.direct (direct, function(err, reply) { 41 | it('Should return object', function(done) { 42 | reply.should.be.an('object'); 43 | done(); 44 | }) 45 | 46 | it('Method should be POST', function(done) { 47 | expect(reply.method).to.be.equal("POST"); 48 | done(); 49 | }) 50 | 51 | it('URI should point to ws/direct', function(done) { 52 | expect(reply.uri).to.be.equal("ws/direct"); 53 | done(); 54 | }) 55 | 56 | it('Params should contain "direct"', function(done) { 57 | expect(reply.direct).to.be.ok; 58 | done(); 59 | }) 60 | 61 | it('Param "currency_code" should be passed', function(done) { 62 | expect(reply.payment.currency_code).to.be.equal(direct.payment.currency_code); 63 | done(); 64 | }) 65 | 66 | it('Param "merchant_payment_code" should be passed', function(done) { 67 | expect(reply.payment.merchant_payment_code).to.be.equal(direct.payment.merchant_payment_code); 68 | done(); 69 | }) 70 | 71 | it('Param "phone_number" should be passed', function(done) { 72 | expect(reply.payment.phone_number).to.be.equal(direct.payment.phone_number); 73 | done(); 74 | }) 75 | 76 | it('Param "country" should be passed', function(done) { 77 | expect(reply.payment.country).to.be.equal(direct.payment.country); 78 | done(); 79 | }) 80 | 81 | it('Param "zipcode" should be passed', function(done) { 82 | expect(reply.payment.zipcode).to.be.equal(direct.payment.zipcode); 83 | done(); 84 | }) 85 | 86 | it('Param "state" should be passed', function(done) { 87 | expect(reply.payment.state).to.be.equal(direct.payment.state); 88 | done(); 89 | }) 90 | 91 | it('Param "city" should be passed', function(done) { 92 | expect(reply.payment.city).to.be.equal(direct.payment.city); 93 | done(); 94 | }) 95 | 96 | it('Param "street_number" should be passed', function(done) { 97 | expect(reply.payment.street_number).to.be.equal(direct.payment.street_number); 98 | done(); 99 | }) 100 | 101 | it('Param "address" should be passed', function(done) { 102 | expect(reply.payment.address).to.be.equal(direct.payment.address); 103 | done(); 104 | }) 105 | 106 | it('Param "document" should be passed', function(done) { 107 | expect(reply.payment.document).to.be.equal(direct.payment.document); 108 | done(); 109 | }) 110 | 111 | it('Param "birth_date" should be passed', function(done) { 112 | expect(reply.payment.birth_date).to.be.equal(direct.payment.birth_date); 113 | done(); 114 | }) 115 | 116 | it('Param "email" should be passed', function(done) { 117 | expect(reply.payment.email).to.be.equal(direct.payment.email); 118 | done(); 119 | }) 120 | 121 | it('Param "name" should be passed', function(done) { 122 | expect(reply.payment.name).to.be.equal(direct.payment.name); 123 | done(); 124 | }) 125 | 126 | it('Param "payment_type_code" should be passed', function(done) { 127 | expect(reply.payment.payment_type_code).to.be.equal(direct.payment.payment_type_code); 128 | done(); 129 | }) 130 | 131 | it('Param "amount_total" should be passed', function(done) { 132 | expect(reply.payment.amount_total).to.be.equal(direct.payment.amount_total); 133 | done(); 134 | }) 135 | }) 136 | }); --------------------------------------------------------------------------------