From 492a5064226f4874cfd035d3bdda120aea1c48ca Mon Sep 17 00:00:00 2001 From: Samuel Date: Mon, 13 Jan 2020 19:24:52 +0100 Subject: [PATCH 1/8] Test module for transfer recipients --- test/transfer.js | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/transfer.js diff --git a/test/transfer.js b/test/transfer.js new file mode 100644 index 0000000..ed49bae --- /dev/null +++ b/test/transfer.js @@ -0,0 +1,67 @@ +var paystack = require('../index')(process.env.KEY) + , mocha = require('mocha') + , expect = require('chai').expect + ; + + + describe("Paystack Transferrecipients", function() { + + var transfer_id, recipient_code; + + //Create Transfer Recipient + it("should create a new transfer recipient", function(done) { + paystack.transfer.create({ + type: 'nuban', + name: 'Samuel Oluwatomi', + account_number: '0172345944', + bank_code: '058', + currency: 'NGN', + description: 'A transfer recipient' + }) + .then(function(body){ + expect(body).to.have.property('status'); + expect(body).to.have.property('data'); + expect(body.data).to.have.property('id'); + expect(body.data).to.have.property('recipient_code'); + + transfer_id = body.data.id; + recipient_code = body.data.recipient_code; + done(); + }) + .catch(function(error){ + return done(error); + }); + }); + + //List Transfer Recipient + it("should list transfer recipients", function(done) { + paystack.transfer.list_recipients() + .then(function(body){ + expect(body).to.have.property('data'); + expect(body.data).to.be.instanceof(Array); + done(); + }) + .catch(function(error){ + return done(error); + }); + }); + + //Update Transfer Recipient + it("should update a transfer recipient", function(done) { + paystack.transfer.update(transfer_id, { + name: 'Samuel Jackson' + }) + .then(function(body){ + expect(body).to.have.property('status'); + expect(body).to.have.property('message'); + done(); + }) + .catch(function(error){ + return done(error); + }); + }); +}); + +//Delete Transfer Recipient + + \ No newline at end of file From e716024b8e7dc3bb4d3314c5d8690c2a8296f60e Mon Sep 17 00:00:00 2001 From: Samuel Date: Mon, 13 Jan 2020 19:27:04 +0100 Subject: [PATCH 2/8] transfer recipient module created --- resources/transfer.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 resources/transfer.js diff --git a/resources/transfer.js b/resources/transfer.js new file mode 100644 index 0000000..13d9333 --- /dev/null +++ b/resources/transfer.js @@ -0,0 +1,36 @@ +'use strict'; + +var root = '/transferrecipient'; + +module.exports = { + + /* + Create transferrecipient + @param: type, name, account_number, bank_code, currency, description + */ + create: { + method: 'post', + endpoint: root, + params: ['type*', 'name*', 'account_number*', 'bank_code*', 'currency', 'description'] + }, + + /* + List recipients + */ + list_recipients: { + method: 'get', + endpoint: root, + params: ['perPage', 'page'] + }, + + /* + Update recipient + @params: name, email + */ + update: { + method: 'put', + endpoint: [root, '/{id}'].join(''), + params: ['name', 'email'], + args: ['id'] + } +}; From 17e91ae3d032974c2153bb27e94f5dfad1bc16ad Mon Sep 17 00:00:00 2001 From: Samuel Date: Mon, 13 Jan 2020 19:28:24 +0100 Subject: [PATCH 3/8] Transfer recipient added to resources --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 529eaf0..137bc1a 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,8 @@ var resources = { subscription: require('./resources/subscription'), subaccount: require('./resources/subaccount'), settlements: require('./resources/settlements'), - misc: require('./resources/misc') + misc: require('./resources/misc'), + transfer: require('./resources/transfer') } function Paystack(key) { From e9a960d06958b53eb4448d00256b6e9b9f42459d Mon Sep 17 00:00:00 2001 From: Samuel Date: Mon, 20 Jan 2020 13:52:28 +0100 Subject: [PATCH 4/8] change to module name --- resources/{transfer.js => transferrecipient.js} | 0 test/{transfer.js => transferrecipient.js} | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) rename resources/{transfer.js => transferrecipient.js} (100%) rename test/{transfer.js => transferrecipient.js} (81%) diff --git a/resources/transfer.js b/resources/transferrecipient.js similarity index 100% rename from resources/transfer.js rename to resources/transferrecipient.js diff --git a/test/transfer.js b/test/transferrecipient.js similarity index 81% rename from test/transfer.js rename to test/transferrecipient.js index ed49bae..486ddec 100644 --- a/test/transfer.js +++ b/test/transferrecipient.js @@ -60,8 +60,23 @@ var paystack = require('../index')(process.env.KEY) return done(error); }); }); + + //Delete Transfer Recipient + it("should delete a transfer recipient", function(done) { + paystack.transfer.update(transfer_id, { + name: 'Samuel Jackson' + }) + .then(function(body){ + expect(body).to.have.property('status'); + expect(body).to.have.property('message'); + done(); + }) + .catch(function(error){ + return done(error); + }); + }); }); -//Delete Transfer Recipient + \ No newline at end of file From b50e1dc2456c461f7c3d8995cb058e45352a8440 Mon Sep 17 00:00:00 2001 From: Samuel Date: Mon, 20 Jan 2020 14:08:19 +0100 Subject: [PATCH 5/8] delete method included --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 137bc1a..e7339b4 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ var resources = { subaccount: require('./resources/subaccount'), settlements: require('./resources/settlements'), misc: require('./resources/misc'), - transfer: require('./resources/transfer') + transferrecipient: require('./resources/transferrecipient') } function Paystack(key) { @@ -51,7 +51,7 @@ Paystack.prototype = { var body, qs; // quick fix - method checking - var method = params.method in {"get":'', "post":'', "put":''} + var method = params.method in {"get":'', "post":'', "put":'', "delete":''} ? params.method : (function () { throw new Error("Method not Allowed! - Resource declaration error") })() var endpoint = [root, params.endpoint].join(''); From a556b4605ae42f87becfd727a2c2e8cf130458e9 Mon Sep 17 00:00:00 2001 From: Samuel Date: Mon, 20 Jan 2020 14:28:23 +0100 Subject: [PATCH 6/8] delete transfer recipient --- resources/transferrecipient.js | 17 +++++++++++++---- test/transferrecipient.js | 10 ++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/resources/transferrecipient.js b/resources/transferrecipient.js index 13d9333..23309fb 100644 --- a/resources/transferrecipient.js +++ b/resources/transferrecipient.js @@ -15,7 +15,7 @@ module.exports = { }, /* - List recipients + List transferrecipients */ list_recipients: { method: 'get', @@ -24,13 +24,22 @@ module.exports = { }, /* - Update recipient - @params: name, email + Update transferrecipient + @params: name, email */ update: { method: 'put', endpoint: [root, '/{id}'].join(''), params: ['name', 'email'], args: ['id'] - } + }, + + /* + Delete transferrecipient + */ + delete: { + method: 'delete', + endpoint: [root, '/{id}'].join(''), + args: ['id'] + } }; diff --git a/test/transferrecipient.js b/test/transferrecipient.js index 486ddec..5c5865c 100644 --- a/test/transferrecipient.js +++ b/test/transferrecipient.js @@ -10,7 +10,7 @@ var paystack = require('../index')(process.env.KEY) //Create Transfer Recipient it("should create a new transfer recipient", function(done) { - paystack.transfer.create({ + paystack.transferrecipient.create({ type: 'nuban', name: 'Samuel Oluwatomi', account_number: '0172345944', @@ -35,7 +35,7 @@ var paystack = require('../index')(process.env.KEY) //List Transfer Recipient it("should list transfer recipients", function(done) { - paystack.transfer.list_recipients() + paystack.transferrecipient.list_recipients() .then(function(body){ expect(body).to.have.property('data'); expect(body.data).to.be.instanceof(Array); @@ -48,7 +48,7 @@ var paystack = require('../index')(process.env.KEY) //Update Transfer Recipient it("should update a transfer recipient", function(done) { - paystack.transfer.update(transfer_id, { + paystack.transferrecipient.update(transfer_id, { name: 'Samuel Jackson' }) .then(function(body){ @@ -63,9 +63,7 @@ var paystack = require('../index')(process.env.KEY) //Delete Transfer Recipient it("should delete a transfer recipient", function(done) { - paystack.transfer.update(transfer_id, { - name: 'Samuel Jackson' - }) + paystack.transferrecipient.delete(transfer_id) .then(function(body){ expect(body).to.have.property('status'); expect(body).to.have.property('message'); From 9106858184b79d06fefaef66db895b53178e8162 Mon Sep 17 00:00:00 2001 From: Samuel Date: Mon, 20 Jan 2020 14:43:22 +0100 Subject: [PATCH 7/8] Quick refactor --- resources/transferrecipient.js | 12 ++++++------ test/transferrecipient.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/resources/transferrecipient.js b/resources/transferrecipient.js index 23309fb..f4a4bdd 100644 --- a/resources/transferrecipient.js +++ b/resources/transferrecipient.js @@ -17,7 +17,7 @@ module.exports = { /* List transferrecipients */ - list_recipients: { + list: { method: 'get', endpoint: root, params: ['perPage', 'page'] @@ -37,9 +37,9 @@ module.exports = { /* Delete transferrecipient */ - delete: { - method: 'delete', - endpoint: [root, '/{id}'].join(''), - args: ['id'] - } + delete: { + method: 'delete', + endpoint: [root, '/{id}'].join(''), + args: ['id'] + } }; diff --git a/test/transferrecipient.js b/test/transferrecipient.js index 5c5865c..84c754b 100644 --- a/test/transferrecipient.js +++ b/test/transferrecipient.js @@ -35,7 +35,7 @@ var paystack = require('../index')(process.env.KEY) //List Transfer Recipient it("should list transfer recipients", function(done) { - paystack.transferrecipient.list_recipients() + paystack.transferrecipient.list() .then(function(body){ expect(body).to.have.property('data'); expect(body.data).to.be.instanceof(Array); From 23774b4cefa61b5843188253c7511cfcf8dc4452 Mon Sep 17 00:00:00 2001 From: Samuel Date: Tue, 21 Jan 2020 10:18:09 +0100 Subject: [PATCH 8/8] line space fix --- test/transferrecipient.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/transferrecipient.js b/test/transferrecipient.js index 84c754b..b601db0 100644 --- a/test/transferrecipient.js +++ b/test/transferrecipient.js @@ -3,7 +3,6 @@ var paystack = require('../index')(process.env.KEY) , expect = require('chai').expect ; - describe("Paystack Transferrecipients", function() { var transfer_id, recipient_code;