Skip to content

Commit

Permalink
Handled partial refund
Browse files Browse the repository at this point in the history
  • Loading branch information
Silviana Ghita committed Nov 6, 2023
1 parent 82b4c8e commit 99c9a3a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) *******
Expand Down
17 changes: 17 additions & 0 deletions test/services/PayIns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
14 changes: 14 additions & 0 deletions typings/mangopay2-nodejs-sdk-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
});
Expand Down Expand Up @@ -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[]
});
Expand Down

0 comments on commit 99c9a3a

Please sign in to comment.