diff --git a/MangoPay.SDK.Tests/ApiPayInsTest.cs b/MangoPay.SDK.Tests/ApiPayInsTest.cs index 4194d0e..ae1709e 100644 --- a/MangoPay.SDK.Tests/ApiPayInsTest.cs +++ b/MangoPay.SDK.Tests/ApiPayInsTest.cs @@ -529,6 +529,29 @@ public async Task Test_PayIns_CreateRefund_CardDirect() Assert.Fail(ex.Message); } } + + [Test] + public async Task Test_PayIns_CreatePartialRefund_CardDirect() + { + try + { + var payIn = await this.GetNewPayInCardDirect(); + var wallet = await this.GetJohnsWalletWithMoney(); + var walletBefore = await this.Api.Wallets.GetAsync(wallet.Id); + + var refund = await this.GetPartialRefundForPayIn(payIn); + var walletAfter = await this.Api.Wallets.GetAsync(wallet.Id); + + Assert.IsTrue(refund.Id.Length > 0); + Assert.IsTrue(walletAfter.Balance.Amount == (walletBefore.Balance.Amount - refund.DebitedFunds.Amount)); + Assert.AreEqual(TransactionType.PAYOUT, refund.Type); + Assert.AreEqual(TransactionNature.REFUND, refund.Nature); + } + catch (Exception ex) + { + Assert.Fail(ex.Message); + } + } [Test] public async Task Test_PayIns_PreAuthorizedDirect() diff --git a/MangoPay.SDK.Tests/BaseTest.cs b/MangoPay.SDK.Tests/BaseTest.cs index 15d58e0..ea902b4 100644 --- a/MangoPay.SDK.Tests/BaseTest.cs +++ b/MangoPay.SDK.Tests/BaseTest.cs @@ -869,6 +869,28 @@ protected async Task GetNewRefundForPayIn(PayInDTO payIn, string idem var refund = new RefundPayInPostDTO(user.Id, fees, debitedFunds); return await this.Api.PayIns.CreateRefundAsync(payIn.Id, refund, idempotentKey: idempotencyKey); } + + /// Creates partial refund object for PayIn. + /// PayIn entity. + /// Refund instance returned from API. + protected async Task GetPartialRefundForPayIn(PayInDTO payIn, string idempotencyKey = null) + { + var user = await this.GetJohn(); + + var debitedFunds = new Money + { + Amount = 100, + Currency = payIn.DebitedFunds.Currency + }; + var fees = new Money + { + Amount = 10, + Currency = payIn.Fees.Currency + }; + + var refund = new RefundPayInPostDTO(user.Id, fees, debitedFunds); + return await this.Api.PayIns.CreateRefundAsync(payIn.Id, refund, idempotentKey: idempotencyKey); + } /// Creates card registration object. /// Card type.