-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from Mangopay/feature/conversions
Conversions
- Loading branch information
Showing
14 changed files
with
365 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using MangoPay.SDK.Core.Enumerations; | ||
using MangoPay.SDK.Entities; | ||
using MangoPay.SDK.Entities.GET; | ||
using MangoPay.SDK.Entities.POST; | ||
using NUnit.Framework; | ||
|
||
namespace MangoPay.SDK.Tests | ||
{ | ||
[TestFixture] | ||
public class ApiConversionsTest : BaseTest | ||
{ | ||
[Test] | ||
public async Task Test_GetConversionRate() | ||
{ | ||
var conversionRate = await Api.Conversions.GetConversionRate("EUR", "GBP"); | ||
|
||
Assert.IsNotNull(conversionRate); | ||
Assert.IsNotNull(conversionRate.ClientRate); | ||
Assert.IsNotNull(conversionRate.MarketRate); | ||
} | ||
|
||
[Test] | ||
public async Task Test_CreateInstantConversion() | ||
{ | ||
var createdInstantConversion = await CreateInstantConversion(); | ||
|
||
Assert.IsNotNull(createdInstantConversion); | ||
Assert.IsNotNull(createdInstantConversion.CreditedFunds.Amount); | ||
Assert.IsNotNull(createdInstantConversion.DebitedFunds.Amount); | ||
Assert.AreEqual(createdInstantConversion.Status, TransactionStatus.SUCCEEDED); | ||
Assert.AreEqual(createdInstantConversion.Type, TransactionType.CONVERSION); | ||
} | ||
|
||
[Test] | ||
public async Task Test_GetInstantConversion() | ||
{ | ||
var createdInstantConversion = await CreateInstantConversion(); | ||
var returnedInstantConversion = await Api.Conversions.GetInstantConversion(createdInstantConversion.Id); | ||
|
||
Assert.IsNotNull(returnedInstantConversion); | ||
Assert.IsNotNull(returnedInstantConversion.CreditedFunds.Amount); | ||
Assert.IsNotNull(returnedInstantConversion.DebitedFunds.Amount); | ||
Assert.AreEqual(returnedInstantConversion.Status, TransactionStatus.SUCCEEDED); | ||
Assert.AreEqual(returnedInstantConversion.Type, TransactionType.CONVERSION); | ||
} | ||
|
||
[Test] | ||
public async Task Test_GetQuotedConversion() | ||
{ | ||
var createdQuotedConversion = await CreateQuotedConversion(); | ||
var returnedInstantConversion = await Api.Conversions.GetInstantConversion(createdQuotedConversion.Id); | ||
|
||
Assert.IsNotNull(returnedInstantConversion); | ||
Assert.IsNotNull(returnedInstantConversion.Id); | ||
Assert.IsNotNull(returnedInstantConversion.CreditedFunds.Amount); | ||
Assert.IsNotNull(returnedInstantConversion.DebitedFunds.Amount); | ||
Assert.AreEqual(returnedInstantConversion.Status, TransactionStatus.SUCCEEDED); | ||
Assert.AreEqual(returnedInstantConversion.Type, TransactionType.CONVERSION); | ||
} | ||
|
||
[Test] | ||
public async Task Test_CreateConversionQuote() | ||
{ | ||
var createdConversionQuote = await CreateConversionQuote(); | ||
|
||
Assert.IsNotNull(createdConversionQuote); | ||
Assert.IsNotNull(createdConversionQuote.CreditedFunds); | ||
Assert.IsNotNull(createdConversionQuote.DebitedFunds); | ||
Assert.IsNotNull(createdConversionQuote.ConversionRateResponse); | ||
Assert.AreEqual("ACTIVE", createdConversionQuote.Status); | ||
} | ||
|
||
[Test] | ||
public async Task Test_GetConversionQuote() | ||
{ | ||
var createdConversionQuote = await CreateConversionQuote(); | ||
var returnedConversionQuote = await Api.Conversions.GetConversionQuote(createdConversionQuote.Id); | ||
|
||
Assert.IsNotNull(returnedConversionQuote); | ||
Assert.IsNotNull(returnedConversionQuote.CreditedFunds); | ||
Assert.IsNotNull(returnedConversionQuote.DebitedFunds); | ||
Assert.IsNotNull(returnedConversionQuote.ConversionRateResponse); | ||
Assert.AreEqual("ACTIVE", returnedConversionQuote.Status); | ||
} | ||
|
||
[Test] | ||
public async Task Test_CreateQuotedConversion() | ||
{ | ||
var john = await GetJohn(); | ||
var wallet = | ||
new WalletPostDTO(new List<string> { john.Id }, "WALLET IN GBP WITH MONEY", CurrencyIso.GBP); | ||
var creditedWallet = await Api.Wallets.CreateAsync(wallet); | ||
|
||
var debitedWallet = await GetJohnsWalletWithMoney(); | ||
|
||
var quote = await CreateConversionQuote(); | ||
var quotedConversionPostDTO = new QuotedConversionPostDTO( | ||
quoteId: quote.Id, | ||
authorId: debitedWallet.Owners[0], | ||
debitedWalletId: debitedWallet.Id, | ||
creditedWalletId: creditedWallet.Id, | ||
tag: "Created using the Mangopay .NET SDK" | ||
); | ||
|
||
var quotedConversion = await this.Api.Conversions.CreateQuotedConversion(quotedConversionPostDTO); | ||
|
||
Assert.IsNotNull(quotedConversion); | ||
Assert.AreEqual(TransactionStatus.SUCCEEDED, quotedConversion.Status); | ||
Assert.AreEqual(TransactionNature.REGULAR, quotedConversion.Nature); | ||
} | ||
|
||
private async Task<ConversionDTO> CreateInstantConversion() | ||
{ | ||
var john = await GetJohn(); | ||
var wallet = | ||
new WalletPostDTO(new List<string> { john.Id }, "WALLET IN GBP WITH MONEY", CurrencyIso.GBP); | ||
var creditedWallet = await Api.Wallets.CreateAsync(wallet); | ||
|
||
var debitedWallet = await GetJohnsWalletWithMoney(); | ||
|
||
var instantConversion = new InstantConversionPostDTO( | ||
john.Id, | ||
debitedWallet.Id, | ||
creditedWallet.Id, | ||
new Money { Amount = 20, Currency = CurrencyIso.EUR }, | ||
new Money { Currency = CurrencyIso.GBP }, | ||
new Money { Amount = 10, Currency = CurrencyIso.EUR }, | ||
"create instant conversion" | ||
); | ||
|
||
return await Api.Conversions.CreateInstantConversion(instantConversion); | ||
} | ||
|
||
private async Task<ConversionDTO> CreateQuotedConversion() | ||
{ | ||
var john = await GetJohn(); | ||
var wallet = | ||
new WalletPostDTO(new List<string> { john.Id }, "WALLET IN GBP WITH MONEY", CurrencyIso.GBP); | ||
var creditedWallet = await Api.Wallets.CreateAsync(wallet); | ||
|
||
var debitedWallet = await GetJohnsWalletWithMoney(); | ||
|
||
var quote = await CreateConversionQuote(); | ||
var quotedConversionPostDTO = new QuotedConversionPostDTO( | ||
quoteId: quote.Id, | ||
authorId: debitedWallet.Owners[0], | ||
debitedWalletId: debitedWallet.Id, | ||
creditedWalletId: creditedWallet.Id, | ||
tag: "Created using the Mangopay .NET SDK" | ||
); | ||
|
||
return await this.Api.Conversions.CreateQuotedConversion(quotedConversionPostDTO); | ||
} | ||
|
||
private async Task<ConversionQuoteDTO> CreateConversionQuote() | ||
{ | ||
var conversionQuote = new ConversionQuotePostDTO( | ||
new Money { Amount = 20, Currency = CurrencyIso.EUR }, | ||
new Money { Currency = CurrencyIso.GBP }, | ||
90, | ||
"Created using the Mangopay .NET SDK" | ||
); | ||
|
||
return await Api.Conversions.CreateConversionQuote(conversionQuote); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Threading.Tasks; | ||
using MangoPay.SDK.Core.Enumerations; | ||
using MangoPay.SDK.Entities.GET; | ||
using MangoPay.SDK.Entities.POST; | ||
|
||
namespace MangoPay.SDK.Core.APIs | ||
{ | ||
public class ApiConversions : ApiBase | ||
{ | ||
public ApiConversions(MangoPayApi root) : base(root) | ||
{ | ||
} | ||
|
||
public async Task<ConversionRateDTO> GetConversionRate(string debitedCurrency, string creditedCurrency) | ||
{ | ||
return await this.GetObjectAsync<ConversionRateDTO>(MethodKey.GetConversionRate, | ||
entitiesId: new[] { debitedCurrency, creditedCurrency }); | ||
} | ||
|
||
public async Task<ConversionDTO> CreateInstantConversion(InstantConversionPostDTO instantConversion, | ||
string idempotentKey = null) | ||
{ | ||
return await | ||
this.CreateObjectAsync<ConversionDTO, InstantConversionPostDTO>(MethodKey.CreateInstantConversion, | ||
instantConversion, idempotentKey); | ||
} | ||
|
||
public async Task<ConversionDTO> GetInstantConversion(string id) | ||
{ | ||
return await this.GetObjectAsync<ConversionDTO>(MethodKey.GetConversion, | ||
entitiesId: id); | ||
} | ||
|
||
public async Task<ConversionQuoteDTO> CreateConversionQuote(ConversionQuotePostDTO conversionQuote, | ||
string idempotentKey = null) | ||
{ | ||
return await this.CreateObjectAsync<ConversionQuoteDTO, ConversionQuotePostDTO>( | ||
MethodKey.CreateConversionQuote, | ||
conversionQuote, | ||
idempotentKey); | ||
} | ||
|
||
public async Task<ConversionQuoteDTO> GetConversionQuote(string id) | ||
{ | ||
return await this.GetObjectAsync<ConversionQuoteDTO>(MethodKey.GetConversionQuote, entitiesId: id); | ||
} | ||
|
||
public async Task<ConversionDTO> CreateQuotedConversion( | ||
QuotedConversionPostDTO quotedConversionPostDto, | ||
string idempotentKey = null) | ||
{ | ||
return await this.CreateObjectAsync<ConversionDTO, QuotedConversionPostDTO>( | ||
MethodKey.CreateQuotedConversion, | ||
quotedConversionPostDto, | ||
idempotentKey); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.