Skip to content

Commit

Permalink
improvements on conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaimoiseanu committed Mar 7, 2024
1 parent eb32e85 commit 4092def
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 58 deletions.
43 changes: 39 additions & 4 deletions MangoPay.SDK.Tests/ApiConversionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ public async Task Test_GetInstantConversion()
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()
{
Expand Down Expand Up @@ -106,23 +120,44 @@ private async Task<ConversionDTO> CreateInstantConversion()

var debitedWallet = await GetJohnsWalletWithMoney();

var instantConversion = new ConversionPostDTO(
var instantConversion = new InstantConversionPostDTO(
john.Id,
debitedWallet.Id,
creditedWallet.Id,
new Money { Amount = 30, Currency = CurrencyIso.EUR },
new Money { Amount = 20, Currency = CurrencyIso.EUR },
new Money { Currency = CurrencyIso.GBP },
new Money { Amount = 10, 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 = 30, Currency = CurrencyIso.EUR },
new Money { Amount = 20, Currency = CurrencyIso.EUR },
new Money { Currency = CurrencyIso.GBP },
90,
"Created using the Mangopay .NET SDK"
Expand Down
2 changes: 1 addition & 1 deletion MangoPay.SDK.Tests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ protected async Task<WalletDTO> CreateJohnsWallet()
/// <returns>Wallet instance loaded with 10k EUR.</returns>
protected async Task<WalletDTO> GetJohnsWalletWithMoney()
{
return await GetJohnsWalletWithMoney(100);
return await GetJohnsWalletWithMoney(200);
}

/// <summary>Creates wallet for John, if not created yet, or returns an existing one.</summary>
Expand Down
7 changes: 3 additions & 4 deletions MangoPay.SDK/Core/APIs/ApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,10 @@ public abstract class ApiBase

{ MethodKey.GetConversionRate,new ApiEndPoint("/conversions/rate/{0}/{1}",RequestType.GET)},
{ MethodKey.CreateInstantConversion,new ApiEndPoint("/conversions/instant-conversion",RequestType.POST)},
{ MethodKey.GetInstantConversion,new ApiEndPoint("/conversions/{0}",RequestType.GET)},
{ MethodKey.CreateQuotedConversion, new ApiEndPoint("/conversions/quoted-conversion", RequestType.POST) },
{ MethodKey.GetConversion,new ApiEndPoint("/conversions/{0}",RequestType.GET)},
{ MethodKey.CreateConversionQuote,new ApiEndPoint("/conversions/quote",RequestType.POST)},
{ MethodKey.GetConversionQuote, new ApiEndPoint("/conversions/quote/{0}", RequestType.GET)},
{ MethodKey.CreateQuotedConversion, new ApiEndPoint("/conversions/quoted-conversion", RequestType.POST)},

{ MethodKey.GetConversionQuote, new ApiEndPoint("/conversions/quote/{0}", RequestType.GET) },
};

/// <summary>Creates new API instance.</summary>
Expand Down
12 changes: 6 additions & 6 deletions MangoPay.SDK/Core/APIs/ApiConversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ public async Task<ConversionRateDTO> GetConversionRate(string debitedCurrency, s
entitiesId: new[] { debitedCurrency, creditedCurrency });
}

public async Task<ConversionDTO> CreateInstantConversion(ConversionPostDTO conversion,
public async Task<ConversionDTO> CreateInstantConversion(InstantConversionPostDTO instantConversion,
string idempotentKey = null)
{
return await
this.CreateObjectAsync<ConversionDTO, ConversionPostDTO>(MethodKey.CreateInstantConversion,
conversion, idempotentKey);
this.CreateObjectAsync<ConversionDTO, InstantConversionPostDTO>(MethodKey.CreateInstantConversion,
instantConversion, idempotentKey);
}

public async Task<ConversionDTO> GetInstantConversion(string id)
{
return await this.GetObjectAsync<ConversionDTO>(MethodKey.GetInstantConversion,
return await this.GetObjectAsync<ConversionDTO>(MethodKey.GetConversion,
entitiesId: id);
}

Expand All @@ -45,11 +45,11 @@ public async Task<ConversionQuoteDTO> GetConversionQuote(string id)
return await this.GetObjectAsync<ConversionQuoteDTO>(MethodKey.GetConversionQuote, entitiesId: id);
}

public async Task<QuotedConversionDTO> CreateQuotedConversion(
public async Task<ConversionDTO> CreateQuotedConversion(
QuotedConversionPostDTO quotedConversionPostDto,
string idempotentKey = null)
{
return await this.CreateObjectAsync<QuotedConversionDTO, QuotedConversionPostDTO>(
return await this.CreateObjectAsync<ConversionDTO, QuotedConversionPostDTO>(
MethodKey.CreateQuotedConversion,
quotedConversionPostDto,
idempotentKey);
Expand Down
4 changes: 2 additions & 2 deletions MangoPay.SDK/Core/Enumerations/MethodKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ public enum MethodKey

GetConversionRate,
CreateInstantConversion,
GetInstantConversion,
CreateQuotedConversion,
GetConversion,
CreateConversionQuote,
GetConversionQuote,
CreateQuotedConversion,
}
}
59 changes: 31 additions & 28 deletions MangoPay.SDK/Entities/GET/ConversionDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,58 @@

namespace MangoPay.SDK.Entities.GET
{
public class ConversionDTO: EntityBase
public class ConversionDTO : EntityBase
{
/// <summary>The unique identifier of the active quote which guaranteed the rate for the conversion.</summary>
public string QuoteId { get; set; }

/// <summary>The type of transaction</summary>
[JsonConverter(typeof(StringEnumConverter))]
public TransactionType Type { get; set; }

/// <summary>The nature of the transaction, providing more
/// information about the context in which the transaction occurred</summary>
[JsonConverter(typeof(StringEnumConverter))]
public TransactionNature Nature { get; set; }

/// <summary>The status of the transaction.</summary>
[JsonConverter(typeof(StringEnumConverter))]
public TransactionStatus Status { get; set; }

/// <summary>The unique identifier of the user at the source of the transaction.</summary>
public string AuthorId { get; set; }

/// <summary>The unique identifier of the debited wallet.</summary>
public string DebitedWalletId { get; set; }

/// <summary>The unique identifier of the credited wallet</summary>
public string CreditedWalletId { 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 ConversionRate { get; set; }

/// <summary>The status of the transaction.</summary>
[JsonConverter(typeof(StringEnumConverter))]
public TransactionStatus Status { get; set; }

/// <summary>The type of transaction</summary>
[JsonConverter(typeof(StringEnumConverter))]
public TransactionType Type { get; set; }

/// <summary>The nature of the transaction, providing more
/// information about the context in which the transaction occurred</summary>
[JsonConverter(typeof(StringEnumConverter))]
public TransactionNature Nature { get; set; }

/// <summary>Information about the fees taken by the platform for
/// this transaction (and hence transferred to the Fees Wallet).</summary>
public Money Fees { get; set; }

/// <summary>The code indicates the result of the operation.
/// This information is mostly used to handle errors or for filtering purposes.</summary>
public string ResultCode { get; set; }

/// <summary>The explanation of the result code.</summary>
public string ResultMessage { get; set; }

/// <summary>The date and time at which the status changed to SUCCEEDED,
/// indicating that the transaction occurred.
/// The statuses CREATED and FAILED return an ExecutionDate of null</summary>
[JsonConverter(typeof(Core.UnixDateTimeConverter))]
public DateTime ExecutionDate { get; set; }


/// <summary>Information about the fees taken by the platform for
/// this transaction (and hence transferred to the Fees Wallet).</summary>
public Money Fees { get; set; }

/// <summary>Real time indicative market rate of a specific currency pair</summary>
public ConversionRateDTO ConversionRate { get; set; }

}
}
11 changes: 0 additions & 11 deletions MangoPay.SDK/Entities/GET/QuotedConversionDTO.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace MangoPay.SDK.Entities.POST
{
public class ConversionPostDTO: EntityPostBase
public class InstantConversionPostDTO: EntityPostBase
{

public ConversionPostDTO(string authorId, string debitedWalletId, string creditedWalletId,
public InstantConversionPostDTO(string authorId, string debitedWalletId, string creditedWalletId,
Money debitedFunds, Money creditedFunds, Money fees,
string tag = null)
{
Expand Down

0 comments on commit 4092def

Please sign in to comment.