From 99c9a3ab3b0cf150d67672a3cbf494d7205d56fd Mon Sep 17 00:00:00 2001 From: Silviana Ghita Date: Mon, 6 Nov 2023 13:29:09 +0200 Subject: [PATCH 1/2] Handled partial refund --- test/helpers.js | 16 ++++++++++++++++ test/services/PayIns.js | 17 +++++++++++++++++ typings/mangopay2-nodejs-sdk-tests.ts | 14 ++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/test/helpers.js b/test/helpers.js index ebee03f..3b1b5a0 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -486,6 +486,22 @@ module.exports = { api.PayIns.createRefund(payIn.Id, refund, callback); }, + getPartialRefundForPayIn: function(api, user, payIn, callback) { + var refund = { + AuthorId: user.Id, + DebitedFunds: new api.models.Money({ + Amount: 100, + Currency: payIn.DebitedFunds.Currency + }), + Fees: new api.models.Money({ + Amount: 10, + Currency: payIn.Fees.Currency + }), + }; + + api.PayIns.createRefund(payIn.Id, refund, callback); + }, + getPaylineCorrectRegistartionData: function(cardRegistration, callback) { /* ****** DO NOT use this code in a production environment - it is just for unit tests. In production you are not allowed to have the user's card details pass via your server (which is what is required to use this code here) ******* diff --git a/test/services/PayIns.js b/test/services/PayIns.js index cf59d49..4341edb 100644 --- a/test/services/PayIns.js +++ b/test/services/PayIns.js @@ -111,6 +111,23 @@ describe('PayIns', function () { expect(refund.Nature).to.equal('REFUND'); }); }); + + describe('Create Partial Refund', function () { + var refund; + + before(function (done) { + helpers.getPartialRefundForPayIn(api, john, payIn, function (data, response) { + refund = data; + done(); + }); + }); + + it('should succeed', function () { + expect(refund.Id).to.not.be.null; + expect(refund.Type).to.equal('PAYOUT'); + expect(refund.Nature).to.equal('REFUND'); + }); + }); }); describe('PreAuthorizedDirect', function () { diff --git a/typings/mangopay2-nodejs-sdk-tests.ts b/typings/mangopay2-nodejs-sdk-tests.ts index 7467686..627b457 100644 --- a/typings/mangopay2-nodejs-sdk-tests.ts +++ b/typings/mangopay2-nodejs-sdk-tests.ts @@ -841,6 +841,14 @@ api.PayIns.createRefund("payin-id", {AuthorId: "user-id"}).then(data => { const d = data; // $ExpectType RefundData }); +api.PayIns.createRefund("payin-id", { + AuthorId: "user-id", + DebitedFunds: {Amount: 100, Currency: "EUR"}, + Fees: {Amount: 15, Currency: "EUR"} +}).then(data => { + const d = data; // $ExpectType RefundData +}); + api.PayIns.getRefunds("payin-id").then(data => { const d = data; // $ExpectType RefundData[] }); @@ -1036,6 +1044,12 @@ api.Transfers.createRefund("transfer-id", {AuthorId: "user-id"}).then( } ); +api.Transfers.createRefund("transfer-id", {AuthorId: "user-id"}).then( + data => { + const d = data; // $ExpectType RefundData + } +); + api.Transfers.getRefunds("transfer-id").then(data => { const d = data; // $ExpectType RefundData[] }); From 244b7204985e2cc3ea7e36393e460fb07b221d94 Mon Sep 17 00:00:00 2001 From: Silviana Ghita Date: Mon, 6 Nov 2023 13:31:29 +0200 Subject: [PATCH 2/2] Cleanup --- typings/mangopay2-nodejs-sdk-tests.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/typings/mangopay2-nodejs-sdk-tests.ts b/typings/mangopay2-nodejs-sdk-tests.ts index 627b457..a8d6b1f 100644 --- a/typings/mangopay2-nodejs-sdk-tests.ts +++ b/typings/mangopay2-nodejs-sdk-tests.ts @@ -1044,12 +1044,6 @@ api.Transfers.createRefund("transfer-id", {AuthorId: "user-id"}).then( } ); -api.Transfers.createRefund("transfer-id", {AuthorId: "user-id"}).then( - data => { - const d = data; // $ExpectType RefundData - } -); - api.Transfers.getRefunds("transfer-id").then(data => { const d = data; // $ExpectType RefundData[] });