Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/ Handle partial refund #205

Merged
merged 2 commits into from
Nov 9, 2023
Merged
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
23 changes: 23 additions & 0 deletions MangoPay.SDK.Tests/ApiPayInsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
var wallet = await this.GetJohnsWallet();
var user = await this.GetJohn();

var payInPost = new PayInPayPalPostDTO(user.Id, new Money { Amount = 1000, Currency = CurrencyIso.EUR }, new Money { Amount = 0, Currency = CurrencyIso.EUR }, wallet.Id, "http://test/test");

Check warning on line 68 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'

Check warning on line 68 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'

var payIn = await this.Api.PayIns.CreatePayPalAsync(payInPost);

Check warning on line 70 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Check warning on line 70 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Assert.IsTrue(payIn.Id.Length > 0);
Assert.IsTrue(payIn.PaymentType == PayInPaymentType.PAYPAL);
Expand Down Expand Up @@ -197,12 +197,12 @@
PostalCode = "11222",
Region = "Region"
};
var payInPost = new PayInPayPalPostDTO(user.Id, new Money { Amount = 1000, Currency = CurrencyIso.EUR }, new Money { Amount = 0, Currency = CurrencyIso.EUR }, wallet.Id, "http://test/test")

Check warning on line 200 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'

Check warning on line 200 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'
{
ShippingAddress = new ShippingAddress("recipient name", AddressForShippingAddress)
};

var payIn = await this.Api.PayIns.CreatePayPalAsync(payInPost);

Check warning on line 205 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Check warning on line 205 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Assert.IsNotNull(payIn.ShippingAddress);
Assert.AreEqual("recipient name", payIn.ShippingAddress.RecipientName);
Expand Down Expand Up @@ -529,6 +529,29 @@
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()
Expand Down Expand Up @@ -859,15 +882,15 @@
var wallet = await this.GetJohnsWallet();
var user = await this.GetJohn();

var payInPost = new PayInPayPalPostDTO(user.Id, new Money { Amount = 1000, Currency = CurrencyIso.EUR }, new Money { Amount = 0, Currency = CurrencyIso.EUR }, wallet.Id, "http://test/test");

Check warning on line 885 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'

Check warning on line 885 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'

payIn = await this.Api.PayIns.CreatePayPalAsync(payInPost);

Check warning on line 887 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Check warning on line 887 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Assert.IsTrue(payIn.Id.Length > 0);
Assert.IsTrue(payIn.PaymentType == PayInPaymentType.PAYPAL);
Assert.IsTrue(payIn.ExecutionType == PayInExecutionType.WEB);

var getPayIn = await this.Api.PayIns.GetPayPalAsync(payIn.Id);

Check warning on line 893 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.GetPayPalAsync(string)' is obsolete: 'GetPayPalAsync is deprecated, please use GetPayPalWebAsync instead.'

Check warning on line 893 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.GetPayPalAsync(string)' is obsolete: 'GetPayPalAsync is deprecated, please use GetPayPalWebAsync instead.'

Assert.IsNotNull(getPayIn);
Assert.IsTrue(getPayIn.Id == payIn.Id);
Expand Down Expand Up @@ -896,14 +919,14 @@
Region = "Region"
};

var payInPost = new PayInPayPalPostDTO(user.Id, new Money { Amount = 1000, Currency = CurrencyIso.EUR }, new Money { Amount = 0, Currency = CurrencyIso.EUR }, wallet.Id, "http://test/test")

Check warning on line 922 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'

Check warning on line 922 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'
{
ShippingAddress = new ShippingAddress("recipient name", addressForShippingAddress)
};

payIn = await this.Api.PayIns.CreatePayPalAsync(payInPost);

Check warning on line 927 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Check warning on line 927 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

var getPayIn = await this.Api.PayIns.GetPayPalAsync(payIn.Id);

Check warning on line 929 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.GetPayPalAsync(string)' is obsolete: 'GetPayPalAsync is deprecated, please use GetPayPalWebAsync instead.'

Check warning on line 929 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.GetPayPalAsync(string)' is obsolete: 'GetPayPalAsync is deprecated, please use GetPayPalWebAsync instead.'

Assert.IsNotNull(getPayIn.ShippingAddress);
Assert.AreEqual("recipient name", getPayIn.ShippingAddress.RecipientName);
Expand Down
22 changes: 22 additions & 0 deletions MangoPay.SDK.Tests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,28 @@ protected async Task<RefundDTO> GetNewRefundForPayIn(PayInDTO payIn, string idem
var refund = new RefundPayInPostDTO(user.Id, fees, debitedFunds);
return await this.Api.PayIns.CreateRefundAsync(payIn.Id, refund, idempotentKey: idempotencyKey);
}

/// <summary>Creates partial refund object for PayIn.</summary>
/// <param name="payIn">PayIn entity.</param>
/// <returns>Refund instance returned from API.</returns>
protected async Task<RefundDTO> 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);
}

/// <summary>Creates card registration object.</summary>
/// <param name="cardType">Card type.</param>
Expand Down
Loading