Skip to content

Commit

Permalink
Merge pull request #29 from Mangopay/MPSDK-13-implements-client-walle…
Browse files Browse the repository at this point in the history
…ts-api

implemented client wallet api
  • Loading branch information
hobailey authored Sep 29, 2016
2 parents b89dd73 + b12d4b5 commit 9274318
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/apiMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,10 @@ module.exports = {

"clients_get" : ["/${apiVersion}/${clientId}/clients", "GET"],
"clients_update" : ["/${apiVersion}/${clientId}/clients", "PUT"],
"clients_upload_logo" : ["/${apiVersion}/${clientId}/clients/logo", "PUT"]
"clients_upload_logo" : ["/${apiVersion}/${clientId}/clients/logo", "PUT"],
"client_wallets_all" : ["/${apiVersion}/${clientId}/clients/wallets/", "GET"],
"client_wallets_get" : ["/${apiVersion}/${clientId}/clients/wallets/${fundsType}/${currency}", "GET"],
"client_wallets_by_fundsType" : ["/${apiVersion}/${clientId}/clients/wallets/${fundsType}", "GET"],
"client_wallets_transactions" : ["/${apiVersion}/${clientId}/clients/wallets/${fundsType}/${currency}/transactions/", "GET"]

};
28 changes: 28 additions & 0 deletions lib/models/ClientWallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var EntityBase = require('./EntityBase');
var Money = require('./Money');

var ClientWallet = EntityBase.extend({
defaults : {
Balance : null,
Currency : null,
FundsType : null
},

getSubObjects: function() {
return {
'Balance': Money
}
},

/**
* Get array with read-only properties
* @return {Array} List of string properties
*/
getReadOnlyProperties: function() {
var properties = EntityBase.prototype.getReadOnlyProperties();
properties.push('Balance');
return properties;
}
});

module.exports = ClientWallet;
75 changes: 75 additions & 0 deletions lib/services/Clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var fs = require('fs');
var Service = require('../service');

var Client = require('../models/Client');
var Transaction = require('../models/Transaction');
var ClientWallet = require('../models/ClientWallet');

var Clients = Service.extend({
/**
Expand Down Expand Up @@ -80,7 +82,80 @@ var Clients = Service.extend({

if (!logo) this._api.errorHandler('Content of the file cannot be empty');
return this.uploadLogo(logo, callback, options);
},

/**
* Get all client wallets
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Promise of the request
*/
getClientWallets: function(callback, options) {
options = this._api._getOptions(callback, options, {
dataClass: ClientWallet
});

return this._api.method("client_wallets_all", callback, options);
},

/**
* Get a client wallet
* @param fundsType Wallet's funds type
* @param currency Currency of the wallet
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Promise of the request
*/
getClientWallet: function(fundsType, currency, callback, options) {
options = this._api._getOptions(callback, options, {
path: {
fundsType: fundsType,
currency: currency
},
dataClass: ClientWallet
});

return this._api.method("client_wallets_get", callback, options);
},

/**
* Get client wallets by the type of funds
* @param fundsType Wallets funds type
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Promise of the request
*/
getClientWalletsByFundsType: function(fundsType, callback, options) {
options = this._api._getOptions(callback, options, {
path: {
fundsType: fundsType
},
dataClass: ClientWallet
});

return this._api.method("client_wallets_by_fundsType", callback, options);
},

/**
* Get a client wallet's transactions
* @param fundsType Wallet's funds type
* @param currency Currency of the wallet
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Promise of the request
*/
getClientWalletTransactions: function(fundsType, currency, callback, options) {
options = this._api._getOptions(callback, options, {
path: {
fundsType: fundsType,
currency: currency
},
dataClass: Transaction
});

return this._api.method("client_wallets_transactions", callback, options);
}

});

module.exports = Clients;
62 changes: 62 additions & 0 deletions test/services/Clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var _ = require('underscore');
var path = require('path');
var expect = require('chai').expect;

var ClientWallet = require('../../lib/models/ClientWallet');
describe("Clients", function(){
var client;
before(function(done){
Expand Down Expand Up @@ -51,4 +52,65 @@ describe("Clients", function(){
});

});

describe("Get client wallets by funds type", function(){
var feesWallets;
var creditWallets;
before(function(done){
api.Clients.getClientWalletsByFundsType('FEES', function(data, response){
feesWallets = data;
api.Clients.getClientWalletsByFundsType('CREDIT', function(data, response){
creditWallets = data;
done();
});
});
});

it('should have wallets', function(){
expect(feesWallets).not.to.be.undefined;
expect(creditWallets).not.to.be.undefined;
})
});

describe("Get client wallet", function(){
var clientWallets;
var clientWallet;
before(function(done){
api.Clients.getClientWallets(function(data, response){
clientWallets = data;
api.Clients.getClientWallet(clientWallets[0].FundsType, clientWallets[0].Currency
, function(data, response){
clientWallet = data;
done();
});
});
});

it('should get the same client wallet', function(){
expect(clientWallet).not.to.be.undefined;
expect(clientWallet.FundsType).to.equal(clientWallets[0].FundsType);
expect(clientWallet.Currency).to.equal(clientWallets[0].Currency);
});
});

describe("Get client wallet's transactions",function(){
var clientWallets;
var transactions;
before(function(done){
api.Clients.getClientWallets(function(data, response){
clientWallets = data;
api.Clients.getClientWalletTransactions(clientWallets[0].FundsType, clientWallets[0].Currency
, function(data, response){
transactions = data;
done();
});
});
});

it('should get transactions', function(){
expect(transactions).not.to.be.undefined;
expect(transactions.length).to.be.greaterThan(0);
})

});
});

0 comments on commit 9274318

Please sign in to comment.