currency-cloud
Advanced tools
Comparing version 1.15.0 to 1.23.2
@@ -12,25 +12,25 @@ /** | ||
const opts = { | ||
retries: 3, | ||
factor: 2, | ||
minTimeout: Math.random() * 750, | ||
maxTimeout: Math.random() * 30000 + 30000, | ||
randomize: true, | ||
log: true | ||
retries: 3, | ||
factor: 2, | ||
minTimeout: Math.random() * 750, | ||
maxTimeout: Math.random() * 30000 + 30000, | ||
randomize: true, | ||
log: true | ||
}; | ||
let convertFunds = { | ||
getQuote: { | ||
buyCurrency: "EUR", | ||
sellCurrency: "GBP", | ||
amount: 10000, | ||
fixedSide: "buy" | ||
}, | ||
conversion: { | ||
buyCurrency: "EUR", | ||
sellCurrency: "GBP", | ||
amount: 10000, | ||
fixedSide: "buy", | ||
reason: "Top up Euros balance", | ||
termAgreement: true | ||
} | ||
getQuote: { | ||
buyCurrency: "EUR", | ||
sellCurrency: "GBP", | ||
amount: 10000, | ||
fixedSide: "buy" | ||
}, | ||
conversion: { | ||
buyCurrency: "EUR", | ||
sellCurrency: "GBP", | ||
amount: 10000, | ||
fixedSide: "buy", | ||
reason: "Top up Euros balance", | ||
termAgreement: true | ||
}, | ||
}; | ||
@@ -56,13 +56,13 @@ | ||
let login = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.authentication.login({ | ||
environment: 'demo', | ||
loginId: 'development@currencycloud.com', | ||
apiKey: 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' | ||
}); | ||
}, | ||
opts, | ||
"currencyCloud.authentication.login" | ||
); | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.authentication.login({ | ||
environment: 'demo', | ||
loginId: 'development@currencycloud.com', | ||
apiKey: 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' | ||
}); | ||
}, | ||
opts, | ||
"currencyCloud.authentication.login" | ||
); | ||
}; | ||
@@ -77,10 +77,10 @@ | ||
let getQuote = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.rates.get(convertFunds.getQuote) | ||
.then((res) => { | ||
console.log('getQuote: ' + JSON.stringify(res, null, 2) + '\n'); | ||
}); | ||
}, | ||
opts); | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.rates.get(convertFunds.getQuote) | ||
.then((res) => { | ||
console.log('getQuote: ' + JSON.stringify(res, null, 2) + '\n'); | ||
}); | ||
}, | ||
opts); | ||
}; | ||
@@ -97,10 +97,10 @@ | ||
let createConversion = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.conversions.create(convertFunds.conversion) | ||
.then((res) => { | ||
console.log('createConversion: ' + JSON.stringify(res, null, 2) + '\n'); | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.conversions.create(convertFunds.conversion) | ||
.then((res) => { | ||
console.log('createConversion: ' + JSON.stringify(res, null, 2) + '\n'); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}; | ||
@@ -121,20 +121,93 @@ /** | ||
let retrieve_profit_and_loss = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.conversions.profit_and_loss() | ||
.then((res) => { | ||
console.log('Your data about profit and/or loss: ' + JSON.stringify(res, null, 2) + '\n'); | ||
}); | ||
}, | ||
opts); | ||
}; | ||
let quote_conversion_date_change = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.conversions.create(convertFunds.conversion) | ||
.then((res) => { | ||
var newDate = new Date(res.settlementDate); | ||
newDate.setDate(newDate.getDate() + 1); | ||
return currencyCloud.conversions.date_change_quote({ | ||
id: res.id, | ||
new_settlement_date: newDate.toDateString() | ||
}).then((result) => { | ||
console.log('Your date change quote made successfully: ' + JSON.stringify(result, null, 2) + '\n'); | ||
}); | ||
}); | ||
}, | ||
opts); | ||
}; | ||
let split_preview = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.conversions.split_preview({ | ||
id: "b9a4ea57-42a7-476d-95d6-6edceec5c5a0", | ||
amount: 2 | ||
}) | ||
.then((result) => { | ||
console.log('Split preview: ' + JSON.stringify(result, null, 2) + '\n'); | ||
}); | ||
}); | ||
}; | ||
let split_history = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.conversions.split_history({ | ||
id: 'c805aa35-9bd3-4afe-ade2-d341e551aa16' | ||
}) | ||
.then((result) => { | ||
console.log('Split history: ' + JSON.stringify(result, null, 2) + '\n'); | ||
}); | ||
}); | ||
}; | ||
let cancellation_quote = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.conversions.create(convertFunds.conversion) | ||
.then((res) => { | ||
return currencyCloud.conversions.cancellation_quote({ | ||
id: res.id | ||
}) | ||
.then((result) => { | ||
console.log('Successful cancellation quote: ' + JSON.stringify(result, null, 2) + '\n'); | ||
}); | ||
}); | ||
}); | ||
}; | ||
let logout = () => { | ||
return currencyCloud.authentication.logout() | ||
.then(() => { | ||
console.log('logout\n'); | ||
}); | ||
return currencyCloud.authentication.logout() | ||
.then(() => { | ||
console.log('logout\n'); | ||
}); | ||
}; | ||
login() | ||
.then(getQuote) | ||
.then(createConversion) | ||
.then(logout) | ||
.catch((err) => { | ||
if (err instanceof currencyCloud.APIerror) { | ||
console.log(err.toYAML()); | ||
} | ||
else { | ||
console.log(err); | ||
} | ||
}); | ||
.then(getQuote) | ||
.then(createConversion) | ||
.then(retrieve_profit_and_loss) | ||
.then(quote_conversion_date_change) | ||
.then(split_preview) | ||
.then(split_history) | ||
.then(cancellation_quote) | ||
.then(logout) | ||
.catch((err) => { | ||
if (err instanceof currencyCloud.APIerror) { | ||
console.log(err.toYAML()); | ||
} | ||
else { | ||
console.log(err); | ||
} | ||
}); |
@@ -13,31 +13,34 @@ /** | ||
const opts = { | ||
retries: 3, | ||
factor: 2, | ||
minTimeout: Math.random() * 750, | ||
maxTimeout: Math.random() * 30000 + 30000, | ||
randomize: true, | ||
log: true | ||
retries: 3, | ||
factor: 2, | ||
minTimeout: Math.random() * 750, | ||
maxTimeout: Math.random() * 30000 + 30000, | ||
randomize: true, | ||
log: true | ||
}; | ||
let simplePayment = { | ||
getBalance: { | ||
currency: "EUR" | ||
}, | ||
beneficiary: { | ||
name: "Acme GmbH", | ||
bankAccountHolderName: "Acme GmbH", | ||
currency: "EUR", | ||
beneficiaryCountry: "DE", | ||
bankCountry: "DE", | ||
bicSwift: "COBADEFF", | ||
iban: "DE89370400440532013000" | ||
}, | ||
payment: { | ||
currency: "EUR", | ||
amount: 10000, | ||
reason: "Invoice Payment", | ||
reference: "2018-014", | ||
paymentType: "regular", | ||
uniqueRequestId: uuid4() | ||
} | ||
getBalance: { | ||
currency: "EUR" | ||
}, | ||
beneficiary: { | ||
name: "Acme GmbH", | ||
bankAccountHolderName: "Acme GmbH", | ||
currency: "EUR", | ||
beneficiaryCountry: "DE", | ||
bankCountry: "DE", | ||
bicSwift: "COBADEFF", | ||
iban: "DE89370400440532013000" | ||
}, | ||
payment: { | ||
currency: "EUR", | ||
amount: 10000, | ||
reason: "Invoice Payment", | ||
reference: "2018-014", | ||
paymentType: "regular", | ||
uniqueRequestId: uuid4() | ||
}, | ||
payment_id: { | ||
id: 'ffbe0bcb-1cc0-43b8-b931-c40691cf09d9' | ||
} | ||
}; | ||
@@ -66,13 +69,13 @@ | ||
let login = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.authentication.login({ | ||
environment: 'demo', | ||
loginId: 'development@currencycloud.com', | ||
apiKey: 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' | ||
}); | ||
}, | ||
opts, | ||
"currencyCloud.authentication.login" | ||
); | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.authentication.login({ | ||
environment: 'demo', | ||
loginId: 'development@currencycloud.com', | ||
apiKey: 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' | ||
}); | ||
}, | ||
opts, | ||
"currencyCloud.authentication.login" | ||
); | ||
}; | ||
@@ -85,12 +88,12 @@ | ||
let getBalance = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.balances.get(simplePayment.getBalance) | ||
.then((res) => { | ||
console.log('getBalance: ' + JSON.stringify(res, null, 2) + '\n'); | ||
}); | ||
}, | ||
opts | ||
); | ||
let getBalance = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.balances.get(simplePayment.getBalance) | ||
.then((res) => { | ||
console.log('getBalance: ' + JSON.stringify(res, null, 2) + '\n'); | ||
}); | ||
}, | ||
opts | ||
); | ||
}; | ||
@@ -104,9 +107,9 @@ | ||
let findBalances = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.balances.find() | ||
.then((res) => { | ||
console.log('findBalance: ' + JSON.stringify(res, null, 2) + '\n'); | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.balances.find() | ||
.then((res) => { | ||
console.log('findBalance: ' + JSON.stringify(res, null, 2) + '\n'); | ||
}); | ||
}); | ||
}); | ||
}; | ||
@@ -133,15 +136,15 @@ | ||
let getBeneficiaryRequiredDetails = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.reference.getBeneficiaryRequiredDetails({ | ||
currency: simplePayment.beneficiary.currency, | ||
bankAccountCountry: simplePayment.beneficiary.bankCountry | ||
}) | ||
.then((res) => { | ||
console.log('getBeneficiaryRequiredDetails: ' + JSON.stringify(res, null, 2) + '\n'); | ||
}); | ||
}, | ||
opts, | ||
"currencyCloud.reference.getBeneficiaryRequiredDetails" | ||
); | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.reference.getBeneficiaryRequiredDetails({ | ||
currency: simplePayment.beneficiary.currency, | ||
bankAccountCountry: simplePayment.beneficiary.bankCountry | ||
}) | ||
.then((res) => { | ||
console.log('getBeneficiaryRequiredDetails: ' + JSON.stringify(res, null, 2) + '\n'); | ||
}); | ||
}, | ||
opts, | ||
"currencyCloud.reference.getBeneficiaryRequiredDetails" | ||
); | ||
}; | ||
@@ -162,12 +165,12 @@ | ||
let createBeneficiary = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.beneficiaries.create(simplePayment.beneficiary) | ||
.then((res) => { | ||
simplePayment.payment.beneficiaryId = res.id; | ||
console.log('createBeneficiary: ' + JSON.stringify(res, null, 2) + '\n'); | ||
}); | ||
}, | ||
opts | ||
); | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.beneficiaries.create(simplePayment.beneficiary) | ||
.then((res) => { | ||
simplePayment.payment.beneficiaryId = res.id; | ||
console.log('createBeneficiary: ' + JSON.stringify(res, null, 2) + '\n'); | ||
}); | ||
}, | ||
opts | ||
); | ||
}; | ||
@@ -188,11 +191,21 @@ | ||
let createPayment = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.payments.create(simplePayment.payment) | ||
.then((res) => { | ||
console.log('createPayment: ' + JSON.stringify(res, null, 2) + '\n'); | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.payments.create(simplePayment.payment) | ||
.then((res) => { | ||
console.log('createPayment: ' + JSON.stringify(res, null, 2) + '\n'); | ||
}); | ||
}); | ||
}); | ||
}; | ||
let getConfirmation = () => { | ||
return currencyCloud.retry( | ||
() => { | ||
return currencyCloud.payments.getConfirmation(simplePayment.payment_id) | ||
.then((res) => { | ||
console.log('Payment confirmation: ' + JSON.stringify(res, null, 2) + '\n'); | ||
}); | ||
}); | ||
}; | ||
/** | ||
@@ -216,22 +229,22 @@ * If the payment is successfully queued, the response payload will contain all the information about the payment as | ||
let logout = () => { | ||
return currencyCloud.authentication.logout() | ||
.then(() => { | ||
console.log('logout\n'); | ||
}); | ||
return currencyCloud.authentication.logout() | ||
.then(() => { | ||
console.log('logout\n'); | ||
}); | ||
}; | ||
login() | ||
.then(getBalance) | ||
.then(findBalances) | ||
.then(getBeneficiaryRequiredDetails) | ||
.then(createBeneficiary) | ||
.then(createPayment) | ||
.then(logout) | ||
.catch((err) => { | ||
if (err instanceof currencyCloud.APIerror) { | ||
console.log(err.toYAML()); | ||
} | ||
else { | ||
console.log(err); | ||
} | ||
}); | ||
.then(getBalance) | ||
.then(findBalances) | ||
.then(getBeneficiaryRequiredDetails) | ||
.then(createBeneficiary) | ||
.then(createPayment) | ||
.then(getConfirmation) | ||
.then(logout) | ||
.catch((err) => { | ||
if (err instanceof currencyCloud.APIerror) { | ||
console.log(err.toYAML()); | ||
} else { | ||
console.log(err); | ||
} | ||
}); |
@@ -10,175 +10,311 @@ /** | ||
module.exports = { | ||
/** | ||
* Creates a new conversion. | ||
* @param {Object} params Object, which contains parameters of the conversion | ||
* @param {String} params.buyCurrency Currency to buy, required | ||
* @param {String} params.sellCurrency Currency to sell, required | ||
* @param {String} params.fixedSide Fixed conversion side: buy or sell, required | ||
* @param {Number} params.amount Amount to convert, required | ||
* @param {String} params.reason Reason for conversion, required | ||
* @param {Boolean} params.termAgreement Agreement flag, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains created conversion; if rejected returns APIerror. | ||
*/ | ||
create: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('buyCurrency')) { | ||
throw new Error('buyCurrency is required'); | ||
} | ||
if (!params.hasOwnProperty('sellCurrency')) { | ||
throw new Error('sellCurrency is required'); | ||
} | ||
if (!params.hasOwnProperty('fixedSide')) { | ||
throw new Error('fixedSide is required'); | ||
} | ||
if (!params.hasOwnProperty('amount')) { | ||
throw new Error('amount is required'); | ||
} | ||
if (!params.hasOwnProperty('reason')) { | ||
throw new Error('reason is required'); | ||
} | ||
if (!params.hasOwnProperty('termAgreement')) { | ||
throw new Error('termAgreement is required'); | ||
} | ||
/** | ||
* Creates a new conversion. | ||
* @param {Object} params Object, which contains parameters of the conversion | ||
* @param {String} params.buyCurrency Currency to buy, required | ||
* @param {String} params.sellCurrency Currency to sell, required | ||
* @param {String} params.fixedSide Fixed conversion side: buy or sell, required | ||
* @param {Number} params.amount Amount to convert, required | ||
* @param {String} params.reason Reason for conversion, required | ||
* @param {Boolean} params.termAgreement Agreement flag, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains created conversion; if rejected returns APIerror. | ||
*/ | ||
create: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('buyCurrency')) { | ||
throw new Error('buyCurrency is required'); | ||
} | ||
if (!params.hasOwnProperty('sellCurrency')) { | ||
throw new Error('sellCurrency is required'); | ||
} | ||
if (!params.hasOwnProperty('fixedSide')) { | ||
throw new Error('fixedSide is required'); | ||
} | ||
if (!params.hasOwnProperty('amount')) { | ||
throw new Error('amount is required'); | ||
} | ||
if (!params.hasOwnProperty('reason')) { | ||
throw new Error('reason is required'); | ||
} | ||
if (!params.hasOwnProperty('termAgreement')) { | ||
throw new Error('termAgreement is required'); | ||
} | ||
var url = '/v2/conversions/create'; | ||
var url = '/v2/conversions/create'; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: params | ||
}); | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: params | ||
}); | ||
return promise; | ||
}, | ||
return promise; | ||
}, | ||
/** | ||
* Gets details of a conversion. | ||
* @param {Object} params Parameters object | ||
* @param {String} params.id Id of the requested conversion, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains requested conversion; if rejected returns APIerror. | ||
*/ | ||
get: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
/** | ||
* Gets details of a conversion. | ||
* @param {Object} params Parameters object | ||
* @param {String} params.id Id of the requested conversion, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains requested conversion; if rejected returns APIerror. | ||
*/ | ||
get: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
var url = '/v2/conversions/' + params.id; | ||
var url = '/v2/conversions/' + params.id; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: qs | ||
}); | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: qs | ||
}); | ||
return promise; | ||
}, | ||
return promise; | ||
}, | ||
/** | ||
* Finds conversions matching the search criteria for the active user. | ||
* @param {Object} params Object, which contains parameters of the sought conversions | ||
* @return {Promise} Promise; if fulfilled returns object, which contains array of found conversions, as well as pagination information; if rejected returns APIerror. | ||
*/ | ||
find: function (params) { | ||
var url = '/v2/conversions/find'; | ||
/** | ||
* Finds conversions matching the search criteria for the active user. | ||
* @param {Object} params Object, which contains parameters of the sought conversions | ||
* @return {Promise} Promise; if fulfilled returns object, which contains array of found conversions, as well as pagination information; if rejected returns APIerror. | ||
*/ | ||
find: function (params) { | ||
var url = '/v2/conversions/find'; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: params | ||
}); | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: params | ||
}); | ||
return promise; | ||
}, | ||
return promise; | ||
}, | ||
/** | ||
* Cancel a conversion | ||
* @param params | ||
* @params {String} params.id Id of the conversion (required) | ||
* @params {String} params.onBehalfOf UUID of account to act on behalf of. | ||
* @params {string} params.notes The notes, that will be stored with conversion cancellation (e.g. reason of cancellation) | ||
* @return {Promise} Promise; if fulfilled returns a json structure containing the details of the conversion cancellation. | ||
*/ | ||
cancel: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
/** | ||
* Cancel a conversion | ||
* @param params | ||
* @params {String} params.id Id of the conversion (required) | ||
* @params {String} params.onBehalfOf UUID of account to act on behalf of. | ||
* @params {string} params.notes The notes, that will be stored with conversion cancellation (e.g. reason of cancellation) | ||
* @return {Promise} Promise; if fulfilled returns a json structure containing the details of the conversion cancellation. | ||
*/ | ||
cancel: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
var url = '/v2/conversions/' + params.id + '/cancel'; | ||
var url = '/v2/conversions/' + params.id + '/cancel'; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: qs | ||
}); | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: qs | ||
}); | ||
return promise; | ||
}, | ||
return promise; | ||
}, | ||
/** | ||
* Change settlement date of a conversion | ||
* @param params | ||
* @params {String} params.id Id of the conversion (required) | ||
* @params {Date} params.new_settlement_date New settlement date (required) | ||
* @return {Promise} Promise; if fulfilled returns a json structure containing the details of the conversion date change; if rejected returns APIerror. | ||
* */ | ||
date_change: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
if (!params.hasOwnProperty('new_settlement_date')) { | ||
throw new Error('new settlement date is required'); | ||
} | ||
/** | ||
* Change settlement date of a conversion | ||
* @param params | ||
* @params {String} params.id Id of the conversion (required) | ||
* @params {Date} params.new_settlement_date New settlement date (required) | ||
* @return {Promise} Promise; if fulfilled returns a json structure containing the details of the conversion date change; if rejected returns APIerror. | ||
* */ | ||
date_change: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
if (!params.hasOwnProperty('new_settlement_date')) { | ||
throw new Error('new settlement date is required'); | ||
} | ||
var url = '/v2/conversions/' + params.id + '/date_change'; | ||
var url = '/v2/conversions/' + params.id + '/date_change'; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: qs | ||
}); | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: qs | ||
}); | ||
return promise; | ||
}, | ||
return promise; | ||
}, | ||
/** | ||
* Execute conversion split and returns a json structure containing split results | ||
* @param params | ||
* @params {String} params.id Id of the conversion (required) | ||
* @params {Number} params.amount Amount to split by (required) | ||
* @return {Promise} Promise; if fulfilled returns object, which contains the parent and child conversions; if rejected returns APIerror. | ||
*/ | ||
split: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
if (!params.hasOwnProperty('amount')) { | ||
throw new Error('amount is required'); | ||
} | ||
/** | ||
* Execute conversion split and returns a json structure containing split results | ||
* @param params | ||
* @params {String} params.id Id of the conversion (required) | ||
* @params {Number} params.amount Amount to split by (required) | ||
* @return {Promise} Promise; if fulfilled returns object, which contains the parent and child conversions; if rejected returns APIerror. | ||
*/ | ||
split: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
if (!params.hasOwnProperty('amount')) { | ||
throw new Error('amount is required'); | ||
} | ||
var url = '/v2/conversions/' + params.id + '/split'; | ||
var url = '/v2/conversions/' + params.id + '/split'; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: qs | ||
}); | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: qs | ||
}); | ||
return promise; | ||
} | ||
return promise; | ||
}, | ||
/** | ||
* Execute conversion retrieve profit and loss and returns a json structure containing data about all the profit and/or loss about conversions//TODO | ||
* @param params | ||
* @return {Promise} Promise; if fulfilled returns object, which contains the parent and child conversions; if rejected returns APIerror. | ||
*/ | ||
profit_and_loss: function (params) { | ||
params = params || {}; | ||
var url = '/v2/conversions/profit_and_loss'; | ||
var qs = Object.assign({}, params); | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: qs | ||
}); | ||
return promise; | ||
}, | ||
/** | ||
* Execute conversion date change qoute and returns a json structure containing conversion data with new settlement date | ||
* @param params | ||
* @params {String} params.id Id of the conversion (required) | ||
* @params {Date} params.new_settlement_date New settlement date (required) | ||
* @return {Promise} Promise; if fulfilled returns object, which contains the parent and child conversions; if rejected returns APIerror. | ||
*/ | ||
date_change_quote: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
if (!params.hasOwnProperty('new_settlement_date')) { | ||
throw new Error('new settlement date is required'); | ||
} | ||
var url = '/v2/conversions/' + params.id + '/date_change_quote'; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: qs | ||
}); | ||
return promise; | ||
}, | ||
/** | ||
* Execute conversion split preview and returns a json structure containing conversion preview of split | ||
* @param params | ||
* @params {String} params.id Id of the conversion (required) | ||
* @params {Number} params.amount Amount to split by (required) | ||
* @return {Promise} Promise; if fulfilled returns object, which contains the parent and child conversions; if rejected returns APIerror. | ||
*/ | ||
split_preview: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
if (!params.hasOwnProperty('amount')) { | ||
throw new Error('amount is required'); | ||
} | ||
var url = '/v2/conversions/' + params.id + '/split_preview'; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: qs | ||
}); | ||
return promise; | ||
}, | ||
/** | ||
* Execute conversion split history and returns a json structure containing conversion split history | ||
* @param params | ||
* @params {String} params.id Id of the conversion (required) | ||
* @return {Promise} Promise; if fulfilled returns object, which contains the parent and child conversions; if rejected returns APIerror. | ||
*/ | ||
split_history: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
var url = '/v2/conversions/' + params.id + '/split_history'; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: qs | ||
}); | ||
return promise; | ||
}, | ||
/** | ||
* Execute conversion cancellation quote and returns a json structure containing conversion //TODO | ||
* @param params | ||
* @params {String} params.id Id of the conversion (required) | ||
* @return {Promise} Promise; if fulfilled returns object, which contains the parent and child conversions; if rejected returns APIerror. | ||
*/ | ||
cancellation_quote: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
var url = '/v2/conversions/' + params.id + '/cancellation_quote'; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: qs | ||
}); | ||
return promise; | ||
} | ||
}; |
@@ -10,161 +10,201 @@ /** | ||
module.exports = { | ||
/** | ||
* Creates a new payment. | ||
* @param {Object} params Object, which contains parameters of the new payment | ||
* @param {String} params.currency Payment currency, required | ||
* @param {String} params.beneficiaryId Id of the payment beneficiary, required | ||
* @param {Number} params.amount Payment amount, required | ||
* @param {String} params.reason Payment reason, required | ||
* @param {String} params.reference Payment reference, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains newly created payment; if rejected returns APIerror. | ||
*/ | ||
create: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('currency')) { | ||
throw new Error('currency is required'); | ||
} | ||
if (!params.hasOwnProperty('beneficiaryId')) { | ||
throw new Error('beneficiaryId is required'); | ||
} | ||
if (!params.hasOwnProperty('amount')) { | ||
throw new Error('amount is required'); | ||
} | ||
if (!params.hasOwnProperty('reason')) { | ||
throw new Error('reason is required'); | ||
} | ||
if (!params.hasOwnProperty('reference')) { | ||
throw new Error('reference is required'); | ||
} | ||
/** | ||
* Creates a new payment. | ||
* @param {Object} params Object, which contains parameters of the new payment | ||
* @param {String} params.currency Payment currency, required | ||
* @param {String} params.beneficiaryId Id of the payment beneficiary, required | ||
* @param {Number} params.amount Payment amount, required | ||
* @param {String} params.reason Payment reason, required | ||
* @param {String} params.reference Payment reference, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains newly created payment; if rejected returns APIerror. | ||
*/ | ||
create: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('currency')) { | ||
throw new Error('currency is required'); | ||
} | ||
if (!params.hasOwnProperty('beneficiaryId')) { | ||
throw new Error('beneficiaryId is required'); | ||
} | ||
if (!params.hasOwnProperty('amount')) { | ||
throw new Error('amount is required'); | ||
} | ||
if (!params.hasOwnProperty('reason')) { | ||
throw new Error('reason is required'); | ||
} | ||
if (!params.hasOwnProperty('reference')) { | ||
throw new Error('reference is required'); | ||
} | ||
var url = '/v2/payments/create'; | ||
var url = '/v2/payments/create'; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: params | ||
}); | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: params | ||
}); | ||
return promise; | ||
}, | ||
return promise; | ||
}, | ||
/** | ||
* Gets details of a payment. | ||
* @param {Object} params Parameters object | ||
* @param {String} params.id Id of the requested payment, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains requested payment; if rejected returns APIerror. | ||
*/ | ||
get: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
/** | ||
* Gets details of a payment. | ||
* @param {Object} params Parameters object | ||
* @param {String} params.id Id of the requested payment, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains requested payment; if rejected returns APIerror. | ||
*/ | ||
get: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
var url = '/v2/payments/' + params.id; | ||
var url = '/v2/payments/' + params.id; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: qs | ||
}); | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: qs | ||
}); | ||
return promise; | ||
}, | ||
return promise; | ||
}, | ||
/** | ||
* Updates an existing payment. | ||
* @param {Object} params Object, which contains parameters of the updated payment | ||
* @param {String} params.id Id of the updated payment, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains updated payment; if rejected returns APIerror. | ||
*/ | ||
update: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
/** | ||
* Updates an existing payment. | ||
* @param {Object} params Object, which contains parameters of the updated payment | ||
* @param {String} params.id Id of the updated payment, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains updated payment; if rejected returns APIerror. | ||
*/ | ||
update: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
var url = '/v2/payments/' + params.id; | ||
var url = '/v2/payments/' + params.id; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: qs | ||
}); | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: qs | ||
}); | ||
return promise; | ||
}, | ||
return promise; | ||
}, | ||
/** | ||
* Finds payments matching the search criteria for the active user. | ||
* @param {Object} params Object, which contains parameters of the sought payments | ||
* @return {Promise} Promise; if fulfilled returns object, which contains array of found payments, as well as pagination information; if rejected returns APIerror. | ||
*/ | ||
find: function (params) { | ||
var url = '/v2/payments/find'; | ||
/** | ||
* Finds payments matching the search criteria for the active user. | ||
* @param {Object} params Object, which contains parameters of the sought payments | ||
* @return {Promise} Promise; if fulfilled returns object, which contains array of found payments, as well as pagination information; if rejected returns APIerror. | ||
*/ | ||
find: function (params) { | ||
var url = '/v2/payments/find'; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: params | ||
}); | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: params | ||
}); | ||
return promise; | ||
}, | ||
return promise; | ||
}, | ||
/** | ||
* Deletes an existing payment. | ||
* @param {Object} params Parameters object | ||
* @param {String} params.id Id of the deleted payment, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains deleted payment; if rejected returns APIerror. | ||
*/ | ||
delete: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
/** | ||
* Deletes an existing payment. | ||
* @param {Object} params Parameters object | ||
* @param {String} params.id Id of the deleted payment, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains deleted payment; if rejected returns APIerror. | ||
*/ | ||
delete: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
var url = '/v2/payments/' + params.id + '/delete'; | ||
var url = '/v2/payments/' + params.id + '/delete'; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: qs | ||
}); | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: qs | ||
}); | ||
return promise; | ||
}, | ||
return promise; | ||
}, | ||
/** | ||
* Returns MT103 message for payment. | ||
* @param {Object} params Parameters object | ||
* @param {String} params.id Id of the payment, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains deleted payment; if rejected returns APIerror. | ||
*/ | ||
retrieveSubmission: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
/** | ||
* Returns MT103 message for payment. | ||
* @param {Object} params Parameters object | ||
* @param {String} params.id Id of the payment, required | ||
* @return {Promise} Promise; if fulfilled returns object, which contains deleted payment; if rejected returns APIerror. | ||
*/ | ||
retrieveSubmission: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
var url = '/v2/payments/' + params.id + '/submission'; | ||
var url = '/v2/payments/' + params.id + '/submission'; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var qs = Object.assign({}, params); | ||
delete qs.id; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: qs | ||
}); | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: qs | ||
}); | ||
return promise; | ||
} | ||
}; | ||
return promise; | ||
}, | ||
/** | ||
* Creates payment authorisations. | ||
* @param {Object} params Object, which contains parameters of the new payment | ||
* @param {String} params.payment_ids Payment ids, required and array of payment_id(s) | ||
* @return {Promise} Promise; if fulfilled returns object, which contains newly authorised payment(s); if rejected returns APIerror. | ||
*/ | ||
authorise: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('payment_ids')) { | ||
throw new Error('payment_ids is required'); | ||
} | ||
var url = '/v2/payments/authorise'; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'POST', | ||
qs: params | ||
}); | ||
return promise; | ||
}, | ||
getConfirmation: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
var url = '/v2/payments/' + params.id + '/confirmation' ; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: params | ||
}); | ||
return promise; | ||
} | ||
}; |
@@ -51,3 +51,20 @@ /** | ||
return promise; | ||
} | ||
}, | ||
getSender: function (params) { | ||
params = params || {}; | ||
if (!params.hasOwnProperty('id')) { | ||
throw new Error('id is required'); | ||
} | ||
var url = '/v2/transactions/sender/' + params.id; | ||
var promise = client.request({ | ||
url: url, | ||
method: 'GET', | ||
qs: params | ||
}); | ||
return promise; | ||
} | ||
}; |
@@ -25,3 +25,5 @@ /** | ||
transfers: require('./api/transfers'), | ||
reports: require('./api/reports'), | ||
retry: require('./backoff'), | ||
vans: require('./api/vans'), | ||
onBehalfOf: client.onBehalfOf, | ||
@@ -36,2 +38,2 @@ APIerror: error.APIerror, | ||
UndefinedError: error.UndefinedError | ||
}; | ||
}; |
{ | ||
"name": "currency-cloud", | ||
"description": "Currencycloud API v2 JavaScript client", | ||
"version": "1.15.0", | ||
"version": "1.23.2", | ||
"author": "Currencycloud", | ||
@@ -36,4 +36,4 @@ "contributors": [ | ||
"dependencies": { | ||
"combined-stream": "^1.0.6", | ||
"request": "^2.83.0", | ||
"combined-stream": "^1.0.7", | ||
"request": "^2.88.0", | ||
"request-promise": "^4.2.2", | ||
@@ -44,6 +44,6 @@ "retry": "^0.12.0", | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"jshint": "^2.9.5", | ||
"chai": "^4.2.0", | ||
"jshint": "^2.9.7", | ||
"mocha": "^5.2.0", | ||
"nock": "^9.4.0" | ||
"nock": "^10.0.4" | ||
}, | ||
@@ -50,0 +50,0 @@ "scripts": { |
@@ -1,2 +0,2 @@ | ||
[](https://www.npmjs.com/package/currency-cloud) [](https://github.com/CurrencyCloud/currencycloud-js) [](https://david-dm.org/CurrencyCloud/currencycloud-js.svg) | ||
[](https://www.npmjs.com/package/currency-cloud) [](https://github.com/CurrencyCloud/currencycloud-js) [](https://github.com/CurrencyCloud/currencycloud-js) | ||
@@ -13,3 +13,3 @@ # Currencycloud | ||
## Supported Node versions | ||
The least supported Node version is 4.0.0. | ||
The least supported Node version is 6.0.0. | ||
@@ -302,2 +302,2 @@ # Usage | ||
[retry]: https://www.npmjs.com/package/retry | ||
[uuid]: https://www.npmjs.com/package/uuid | ||
[uuid]: https://www.npmjs.com/package/uuid |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
449872
71
10460
302
3
1
Updatedcombined-stream@^1.0.7
Updatedrequest@^2.88.0