currency-cloud
Advanced tools
Comparing version 3.3.3 to 3.4.0
@@ -51,3 +51,30 @@ /** | ||
return promise; | ||
}, | ||
/** | ||
* Tops up the margin balances with the given amount for the given currency. | ||
* @param {Object} params Object, which contains parameters of the margin balance top up | ||
* @param {String} params.currency Currency of the top up, required | ||
* @param {String} params.amount Amount to top up, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains information about the top up; if rejected returns APIerror. | ||
*/ | ||
topUpMargin: function(params) { | ||
params = params || {}; | ||
if(!params.hasOwnProperty('currency')) { | ||
throw new Error('currency is required'); | ||
} | ||
if(!params.hasOwnProperty('amount')) { | ||
throw new Error('amount is required'); | ||
} | ||
var url = '/v2/balances/top_up_margin'; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: params | ||
}); | ||
return promise; | ||
} | ||
}; |
{ | ||
"name": "currency-cloud", | ||
"description": "Currencycloud API v2 JavaScript client", | ||
"version": "3.3.3", | ||
"version": "3.4.0", | ||
"author": "Currencycloud", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -57,2 +57,19 @@ 'use strict'; | ||
}); | ||
describe('topUpMargin', function () { | ||
it('successfully tops up margin balance', function (done) { | ||
currencyCloud.balances.topUpMargin({ | ||
currency: 'GBP', | ||
amount: '450'}) | ||
.then(function (res) { | ||
expect(res).is.not.empty; | ||
expect(res).to.have.property('accountId').that.eql("6c046c51-2387-4004-8e87-4bf97102e36d"); | ||
expect(res).to.have.property('currency').that.eql("GBP"); | ||
expect(res).to.have.property('transferredAmount').that.eql("450.0"); | ||
expect(res).to.have.property('transferCompletedAt').that.eql("2007-11-19T08:37:48-06:00"); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
}); | ||
}); |
@@ -18,3 +18,15 @@ var nock = require('nock'); | ||
nock('https://devapi.currencycloud.com:443') | ||
.post('/v2/balances/top_up_margin', { | ||
"currency": "GBP", | ||
"amount": "450" | ||
}) | ||
.reply(200, { | ||
"account_id": "6c046c51-2387-4004-8e87-4bf97102e36d", | ||
"currency": "GBP", | ||
"transferred_amount": "450.0", | ||
"transfer_completed_at": "2007-11-19T08:37:48-06:00" | ||
}); | ||
nock('https://devapi.currencycloud.com:443') | ||
.post('/v2/authenticate/close_session') | ||
.reply(200, {}); |
471222
10893