-
Notifications
You must be signed in to change notification settings - Fork 23
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 #215 from Mangopay/feature/conversions_quote
Conversion Quote
- Loading branch information
Showing
14 changed files
with
305 additions
and
115 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,134 @@ | ||
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_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 ConversionPostDTO( | ||
john.Id, | ||
debitedWallet.Id, | ||
creditedWallet.Id, | ||
new Money { Amount = 30, Currency = CurrencyIso.EUR }, | ||
new Money { Currency = CurrencyIso.GBP }, | ||
new Money { Amount = 10, Currency = CurrencyIso.GBP }, | ||
"create instant conversion" | ||
); | ||
|
||
return await Api.Conversions.CreateInstantConversion(instantConversion); | ||
} | ||
|
||
private async Task<ConversionQuoteDTO> CreateConversionQuote() | ||
{ | ||
var conversionQuote = new ConversionQuotePostDTO( | ||
new Money { Amount = 30, 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
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(ConversionPostDTO conversion, | ||
string idempotentKey = null) | ||
{ | ||
return await | ||
this.CreateObjectAsync<ConversionDTO, ConversionPostDTO>(MethodKey.CreateInstantConversion, | ||
conversion, idempotentKey); | ||
} | ||
|
||
public async Task<ConversionDTO> GetInstantConversion(string id) | ||
{ | ||
return await this.GetObjectAsync<ConversionDTO>(MethodKey.GetInstantConversion, | ||
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<QuotedConversionDTO> CreateQuotedConversion( | ||
QuotedConversionPostDTO quotedConversionPostDto, | ||
string idempotentKey = null) | ||
{ | ||
return await this.CreateObjectAsync<QuotedConversionDTO, 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
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,26 @@ | ||
using System; | ||
using MangoPay.SDK.Core.Enumerations; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
namespace MangoPay.SDK.Entities.GET | ||
{ | ||
public class ConversionQuoteDTO : EntityBase | ||
{ | ||
/// <summary>The date and time at which the quote expires</summary> | ||
[JsonConverter(typeof(Core.UnixDateTimeConverter))] | ||
public DateTime ExpirationDate { get; set; } | ||
|
||
/// <summary>The status of the transaction.</summary> | ||
public string Status { get; set; } | ||
|
||
/// <summary>The sell funds</summary> | ||
public Money DebitedFunds { get; set; } | ||
|
||
/// <summary>The buy funds</summary> | ||
public Money CreditedFunds { get; set; } | ||
|
||
/// <summary>Real time indicative market rate of a specific currency pair</summary> | ||
public ConversionRateDTO ConversionRateResponse { get; set; } | ||
} | ||
} |
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,11 @@ | ||
namespace MangoPay.SDK.Entities.GET | ||
{ | ||
public class QuotedConversionDTO : TransactionDTO | ||
{ | ||
/// <summary>The unique identifier of the active quote which guaranteed the rate for the conversion.</summary> | ||
public string QuoteId { get; set; } | ||
|
||
/// <summary>Information about the conversion rate used during the transaction.</summary> | ||
public ConversionRateDTO ConversionRateResponse { get; set; } | ||
} | ||
} |
Oops, something went wrong.