Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer Recipients #39

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
transferrecipient: require('./resources/transferrecipient')
}

function Paystack(key) {
Expand Down Expand Up @@ -50,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('');
Expand Down
45 changes: 45 additions & 0 deletions resources/transferrecipient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'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 transferrecipients
*/
list: {
method: 'get',
endpoint: root,
params: ['perPage', 'page']
},

/*
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']
}
};
79 changes: 79 additions & 0 deletions test/transferrecipient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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.transferrecipient.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.transferrecipient.list()
.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.transferrecipient.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
it("should delete a transfer recipient", function(done) {
paystack.transferrecipient.delete(transfer_id)
.then(function(body){
expect(body).to.have.property('status');
expect(body).to.have.property('message');
done();
})
.catch(function(error){
return done(error);
});
});
});