Skip to content
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
64 changes: 64 additions & 0 deletions lib/api/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,5 +277,69 @@ module.exports = {
});

return promise;
},

getPaymentFees: function (params) {
params = params || {};

const url = '/v2/payments/payment_fees';

return client.request({
url: url,
method: 'GET',
qs: params
});
},

unassignPaymentFee: function (params) {
params = params || {};

if (!params.hasOwnProperty("accountId")) {
throw new Error("accountId is required");
}

const url = "/v2/payments/unassign_payment_fee";

return client.request({
url: url,
method: 'POST',
qs: params
});
},

assignPaymentFee: function (params) {
params = params || {};

if (!params.hasOwnProperty("paymentFeeId")) {
throw new Error("paymentFeeId is required");
}

if (!params.hasOwnProperty("accountId")) {
throw new Error("accountId is required");
}

const url = "/v2/payments/assign_payment_fee";

return client.request({
url: url,
method: 'POST',
qs: params
});
},

assignedPaymentFee: function (params) {
params = params || {};

if (!params.hasOwnProperty("accountId")) {
throw new Error("accountId is required");
}

const url = "/v2/payments/assigned_payment_fee";

return client.request({
url: url,
method: 'GET',
qs: params
});
}
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 64 additions & 1 deletion test/api/fixtures/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,69 @@ nock('https://devapi.currencycloud.com:443', {"encodedQueryParams": true})
"fee_amount": "10.00",
"fee_currency": "EUR" });

nock('https://devapi.currencycloud.com:443', {"encodedQueryParams": true})
.get('/v2/payments/payment_fees')
.reply(200, {
"payment_fees": [
{
"id": "e7e1b6e5-c596-4ad1-b8d4-a7035185143a",
"name": "Fee Table CAD 5 - 10 - 15",
"currency": "CAD",
"regular_amount": "5.00",
"priority_shared_amount": "10.00",
"priority_ours_amount": "15.00",
"owner_account_id": ""
},
{
"id": "029e1771-8de7-4ab0-9c19-c14b325c0c9e",
"name": "Fee Table USD 2 - 4 - 12",
"currency": "USD",
"regular_amount": "2.00",
"priority_shared_amount": "4.00",
"priority_ours_amount": "12.00",
"owner_account_id": ""
}
],
"pagination": {
"total_entries": 2,
"total_pages": 1,
"current_page": 1,
"per_page": 25,
"previous_page": -1,
"next_page": -1,
"order": "created_at",
"order_asc_desc": "asc"
}
});

nock("https://devapi.currencycloud.com:443", {
encodedQueryParams: true
}).post("/v2/payments/unassign_payment_fee").reply(200, {
account_id: "245a1ebd-d8a6-416d-bcc1-9de381d22f90"
});

nock("https://devapi.currencycloud.com:443", {
encodedQueryParams: true
}).post("/v2/payments/assign_payment_fee").reply(200, {
id: "7c17b546-0435-45f0-9c17-3a4e0f2d3e84",
account_id: "245a1ebd-d8a6-416d-bcc1-9de381d22f90"
});

nock("https://devapi.currencycloud.com:443", {
encodedQueryParams: true
})
.get("/v2/payments/assigned_payment_fee")
.query({account_id: "4e8ca601-80c0-0133-26ca-0022194273c7"})
.reply(200, {
id: "2bd34951-becc-4b52-b7d1-3f954609d173",
name: "Fee table name",
currency: "EUR",
regular_amount: "4.00",
priority_shared_amount: "5.00",
priority_ours_amount: "6.00",
owner_account_id: "4e8ca601-80c0-0133-26ca-0022194273c7"
});

nock('https://devapi.currencycloud.com:443')
.post('/v2/authenticate/close_session')
.reply(200, {});
.reply(200, {});
103 changes: 103 additions & 0 deletions test/api/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,107 @@ describe('payments', function () {
.catch(done);
});
});

describe("getPaymentFees", function () {
it("successfully gets payment fees", function () {
currencyCloud.payments.getPaymentFees()
.then(function (res) {
expect(res).to.not.be.empty;

expect(res).to.have.property("pagination").that.is.not.empty;
expect(res.pagination).to.have.property("totalEntries").that.equals(2);
expect(res.pagination).to.have.property("totalPages").that.equals(1);
expect(res.pagination).to.have.property("currentPage").that.equals(1);
expect(res.pagination).to.have.property("perPage").that.equals(25);
expect(res.pagination).to.have.property("previousPage").that.equals(-1);
expect(res.pagination).to.have.property("nextPage").that.equals(-1);
expect(res.pagination).to.have.property("order").that.equals("created_at");
expect(res.pagination).to.have.property("orderAscDesc").that.equals("asc");

expect(res).to.have.property("paymentFees").that.is.not.empty;
expect(res.paymentFees[0]).to.have.property("id").that.equals("e7e1b6e5-c596-4ad1-b8d4-a7035185143a");
expect(res.paymentFees[0]).to.have.property("name").that.equals("Fee Table CAD 5 - 10 - 15");
expect(res.paymentFees[0]).to.have.property("currency").that.equals("CAD");
expect(res.paymentFees[0]).to.have.property("regularAmount").that.equals("5.00");
expect(res.paymentFees[0]).to.have.property("prioritySharedAmount").that.equals("10.00");
expect(res.paymentFees[0]).to.have.property("priorityOursAmount").that.equals("15.00");
expect(res.paymentFees[0]).to.have.property("ownerAccountId").that.is.empty;

expect(res.paymentFees[1]).to.have.property("id").that.equals("029e1771-8de7-4ab0-9c19-c14b325c0c9e");
expect(res.paymentFees[1]).to.have.property("name").that.equals("Fee Table USD 2 - 4 - 12");
expect(res.paymentFees[1]).to.have.property("currency").that.equals("USD");
expect(res.paymentFees[1]).to.have.property("regularAmount").that.equals("2.00");
expect(res.paymentFees[1]).to.have.property("prioritySharedAmount").that.equals("4.00");
expect(res.paymentFees[1]).to.have.property("priorityOursAmount").that.equals("12.00");
expect(res.paymentFees[1]).to.have.property("ownerAccountId").that.is.empty;
});
});
});

describe("unassignPaymentFee", function () {
it("successfully unassigns a payment fee", function () {
currencyCloud.payments.unassignPaymentFee({
accountId: "accountId123"
}).then(function (res) {
expect(res).to.not.be.empty;

expect(res).to.have.property("accountId").that.equals("245a1ebd-d8a6-416d-bcc1-9de381d22f90");
});
});

it("throws an error if the accountId is not provided", function() {
expect(function () {
currencyCloud.payments.unassignPaymentFee();
}).to.throw("accountId is required");
});
});

describe("assignPaymentFee", function () {
it("successfully assigns a payment fee to an account", function () {
currencyCloud.payments.assignPaymentFee({
paymentFeeId: "hello",
accountId: "accountId123"
})
.then(function (res) {
expect(res).to.not.be.empty;

expect(res).to.have.property("id").that.equals("7c17b546-0435-45f0-9c17-3a4e0f2d3e84");
expect(res).to.have.property("accountId").that.equals("245a1ebd-d8a6-416d-bcc1-9de381d22f90");
});
});

it ("throws an error when the paymentFeeId is missing", function () {
expect(function () {
currencyCloud.payments.assignPaymentFee({
accountId: "accountId123"
});
}).to.throw("paymentFeeId is required");
});

it ("throws an error when the accountId is missing", function () {
expect(function () {
currencyCloud.payments.assignPaymentFee({
paymentFeeId: "hello"
});
}).to.throw("accountId is required");
});
});

describe("assignedPaymentFee", function () {
it("successfully gets the assigned payment fee", function () {
currencyCloud.payments.assignedPaymentFee({
accountId: "4e8ca601-80c0-0133-26ca-0022194273c7"
}).then(function (res) {
expect(res).to.not.be.empty;

expect(res).to.have.property("id").that.equals("2bd34951-becc-4b52-b7d1-3f954609d173");
expect(res).to.have.property("name").that.equals("Fee table name");
expect(res).to.have.property("currency").that.equals("EUR");
expect(res).to.have.property("regularAmount").that.equals("4.00");
expect(res).to.have.property("prioritySharedAmount").that.equals("5.00");
expect(res).to.have.property("priorityOursAmount").that.equals("6.00");
expect(res).to.have.property("ownerAccountId").that.equals("4e8ca601-80c0-0133-26ca-0022194273c7");
});
});
});
});