Skip to content

Commit

Permalink
rename InstantConversion to Conversions
Browse files Browse the repository at this point in the history
added quote endpoints
  • Loading branch information
mihaimoiseanu committed Feb 22, 2024
1 parent 7b431ec commit 841dace
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
namespace MangoPay.SDK.Tests
{
[TestFixture]
public class ApiInstantConversionTest: BaseTest
public class ApiConversionsTest: BaseTest
{
[Test]
public async Task Test_GetConversionRate()
{
var conversionRate = await Api.InstantConversion.GetConversionRate("EUR", "GBP");
var conversionRate = await Api.Conversions.GetConversionRate("EUR", "GBP");

Assert.IsNotNull(conversionRate);
Assert.IsNotNull(conversionRate.ClientRate);
Expand All @@ -37,7 +37,7 @@ public async Task Test_CreateInstantConversion()
public async Task Test_GetInstantConversion()
{
var createdInstantConversion = await CreateInstantConversion();
var returnedInstantConversion = await Api.InstantConversion.GetInstantConversion(createdInstantConversion.Id);
var returnedInstantConversion = await Api.Conversions.GetInstantConversion(createdInstantConversion.Id);

Assert.IsNotNull(returnedInstantConversion);
Assert.IsNotNull(returnedInstantConversion.CreditedFunds.Amount);
Expand All @@ -46,7 +46,32 @@ public async Task Test_GetInstantConversion()
Assert.AreEqual(returnedInstantConversion.Type, TransactionType.CONVERSION);
}

private async Task<InstantConversionDTO> CreateInstantConversion()
[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);
}

private async Task<ConversionDTO> CreateInstantConversion()
{
var john = await GetJohn();
var wallet =
Expand All @@ -55,16 +80,28 @@ private async Task<InstantConversionDTO> CreateInstantConversion()

var debitedWallet = await GetJohnsWalletWithMoney();

var instantConversion = new InstantConversionPostDTO(
var instantConversion = new ConversionPostDTO(
john.Id,
debitedWallet.Id,
creditedWallet.Id,
new Money { Amount = 79, Currency = CurrencyIso.EUR },
new Money { Amount = 30, Currency = CurrencyIso.EUR },
new Money { Currency = CurrencyIso.GBP },
"create instant conversion"
);

return await Api.InstantConversion.CreateInstantConversion(instantConversion);
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);
}
}
}
5 changes: 4 additions & 1 deletion MangoPay.SDK/Core/APIs/ApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ public abstract class ApiBase

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

};

/// <summary>Creates new API instance.</summary>
Expand Down
48 changes: 48 additions & 0 deletions MangoPay.SDK/Core/APIs/ApiConversions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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);
}
}
}
34 changes: 0 additions & 34 deletions MangoPay.SDK/Core/APIs/ApiInstantConversion.cs

This file was deleted.

4 changes: 3 additions & 1 deletion MangoPay.SDK/Core/Enumerations/MethodKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ public enum MethodKey

GetConversionRate,
CreateInstantConversion,
GetInstantConversion
GetInstantConversion,
CreateConversionQuote,
GetConversionQuote,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace MangoPay.SDK.Entities.GET
{
public class InstantConversionDTO: EntityBase
public class ConversionDTO: EntityBase
{
/// <summary>The unique identifier of the user at the source of the transaction.</summary>
public string AuthorId { get; set; }
Expand Down
26 changes: 26 additions & 0 deletions MangoPay.SDK/Entities/GET/ConversionQuoteDTO.cs
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; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace MangoPay.SDK.Entities.POST
{
public class InstantConversionPostDTO: EntityPostBase
public class ConversionPostDTO: EntityPostBase
{

public InstantConversionPostDTO(string authorId, string debitedWalletId, string creditedWalletId,
public ConversionPostDTO(string authorId, string debitedWalletId, string creditedWalletId,
Money debitedFunds, Money creditedFunds,
string tag = null)
{
Expand Down
27 changes: 27 additions & 0 deletions MangoPay.SDK/Entities/POST/ConversionQuotePostDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace MangoPay.SDK.Entities.POST
{
public class ConversionQuotePostDTO : EntityPostBase
{
public ConversionQuotePostDTO(
Money debitedFunds,
Money creditedFunds,
int duration,
string tag
)
{
DebitedFunds = debitedFunds;
CreditedFunds = creditedFunds;
Duration = duration;
Tag = tag;
}

/// <summary>The sell funds</summary>
public Money DebitedFunds { get; set; }

/// <summary>The buy funds</summary>
public Money CreditedFunds { get; set; }

/// <summary>The time in seconds during which the quote is active and can be used for conversions.</summary>
public int Duration { get; set; }
}
}
4 changes: 2 additions & 2 deletions MangoPay.SDK/MangoPayApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public MangoPayApi()
UboDeclarations = new ApiUboDeclarations(this);
Regulatory = new ApiRegulatory(this);
Deposits = new ApiDeposits(this);
InstantConversion = new ApiInstantConversion(this);
Conversions = new ApiConversions(this);
}

/// <summary>Provides authorization token methods.</summary>
Expand Down Expand Up @@ -125,7 +125,7 @@ public MangoPayApi()

public ApiDeposits Deposits;

public ApiInstantConversion InstantConversion;
public ApiConversions Conversions;

#endregion

Expand Down

0 comments on commit 841dace

Please sign in to comment.