From 841dace713fe6e84bdbb09cc87f5fe62f08a4170 Mon Sep 17 00:00:00 2001 From: Mihai Moiseanu Date: Thu, 22 Feb 2024 13:33:48 +0200 Subject: [PATCH] rename InstantConversion to Conversions added quote endpoints --- ...onversionTest.cs => ApiConversionsTest.cs} | 51 ++++++++++++++++--- MangoPay.SDK/Core/APIs/ApiBase.cs | 5 +- MangoPay.SDK/Core/APIs/ApiConversions.cs | 48 +++++++++++++++++ .../Core/APIs/ApiInstantConversion.cs | 34 ------------- MangoPay.SDK/Core/Enumerations/MethodKey.cs | 4 +- ...stantConversionDTO.cs => ConversionDTO.cs} | 2 +- .../Entities/GET/ConversionQuoteDTO.cs | 26 ++++++++++ ...versionPostDTO.cs => ConversionPostDTO.cs} | 4 +- .../Entities/POST/ConversionQuotePostDTO.cs | 27 ++++++++++ MangoPay.SDK/MangoPayApi.cs | 4 +- 10 files changed, 157 insertions(+), 48 deletions(-) rename MangoPay.SDK.Tests/{ApiInstantConversionTest.cs => ApiConversionsTest.cs} (51%) create mode 100644 MangoPay.SDK/Core/APIs/ApiConversions.cs delete mode 100644 MangoPay.SDK/Core/APIs/ApiInstantConversion.cs rename MangoPay.SDK/Entities/GET/{InstantConversionDTO.cs => ConversionDTO.cs} (97%) create mode 100644 MangoPay.SDK/Entities/GET/ConversionQuoteDTO.cs rename MangoPay.SDK/Entities/POST/{InstantConversionPostDTO.cs => ConversionPostDTO.cs} (86%) create mode 100644 MangoPay.SDK/Entities/POST/ConversionQuotePostDTO.cs diff --git a/MangoPay.SDK.Tests/ApiInstantConversionTest.cs b/MangoPay.SDK.Tests/ApiConversionsTest.cs similarity index 51% rename from MangoPay.SDK.Tests/ApiInstantConversionTest.cs rename to MangoPay.SDK.Tests/ApiConversionsTest.cs index 8c81ea8..299b6e5 100644 --- a/MangoPay.SDK.Tests/ApiInstantConversionTest.cs +++ b/MangoPay.SDK.Tests/ApiConversionsTest.cs @@ -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); @@ -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); @@ -46,7 +46,32 @@ public async Task Test_GetInstantConversion() Assert.AreEqual(returnedInstantConversion.Type, TransactionType.CONVERSION); } - private async Task 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 CreateInstantConversion() { var john = await GetJohn(); var wallet = @@ -55,16 +80,28 @@ private async Task 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 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); } } } \ No newline at end of file diff --git a/MangoPay.SDK/Core/APIs/ApiBase.cs b/MangoPay.SDK/Core/APIs/ApiBase.cs index 2799d27..8f554f2 100644 --- a/MangoPay.SDK/Core/APIs/ApiBase.cs +++ b/MangoPay.SDK/Core/APIs/ApiBase.cs @@ -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)}, + }; /// Creates new API instance. diff --git a/MangoPay.SDK/Core/APIs/ApiConversions.cs b/MangoPay.SDK/Core/APIs/ApiConversions.cs new file mode 100644 index 0000000..8ea98b5 --- /dev/null +++ b/MangoPay.SDK/Core/APIs/ApiConversions.cs @@ -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 GetConversionRate(string debitedCurrency, string creditedCurrency) + { + return await this.GetObjectAsync(MethodKey.GetConversionRate, + entitiesId: new[] { debitedCurrency, creditedCurrency }); + } + + public async Task CreateInstantConversion(ConversionPostDTO conversion, + string idempotentKey = null) + { + return await + this.CreateObjectAsync(MethodKey.CreateInstantConversion, + conversion, idempotentKey); + } + + public async Task GetInstantConversion(string id) + { + return await this.GetObjectAsync(MethodKey.GetInstantConversion, + entitiesId: id); + } + + public async Task CreateConversionQuote(ConversionQuotePostDTO conversionQuote, + string idempotentKey = null) + { + return await this.CreateObjectAsync( + MethodKey.CreateConversionQuote, + conversionQuote, + idempotentKey); + } + + public async Task GetConversionQuote(string id) + { + return await this.GetObjectAsync(MethodKey.GetConversionQuote, entitiesId: id); + } + } +} \ No newline at end of file diff --git a/MangoPay.SDK/Core/APIs/ApiInstantConversion.cs b/MangoPay.SDK/Core/APIs/ApiInstantConversion.cs deleted file mode 100644 index f237315..0000000 --- a/MangoPay.SDK/Core/APIs/ApiInstantConversion.cs +++ /dev/null @@ -1,34 +0,0 @@ -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 ApiInstantConversion : ApiBase - { - public ApiInstantConversion(MangoPayApi root) : base(root) - { - } - - public async Task GetConversionRate(string debitedCurrency, string creditedCurrency) - { - return await this.GetObjectAsync(MethodKey.GetConversionRate, - entitiesId: new[] { debitedCurrency, creditedCurrency }); - } - - public async Task CreateInstantConversion(InstantConversionPostDTO instantConversion, - string idempotentKey = null) - { - return await - this.CreateObjectAsync(MethodKey.CreateInstantConversion, - instantConversion, idempotentKey); - } - - public async Task GetInstantConversion(string id) - { - return await this.GetObjectAsync(MethodKey.GetInstantConversion, - entitiesId: id); - } - } -} \ No newline at end of file diff --git a/MangoPay.SDK/Core/Enumerations/MethodKey.cs b/MangoPay.SDK/Core/Enumerations/MethodKey.cs index dee1495..4ada411 100644 --- a/MangoPay.SDK/Core/Enumerations/MethodKey.cs +++ b/MangoPay.SDK/Core/Enumerations/MethodKey.cs @@ -192,6 +192,8 @@ public enum MethodKey GetConversionRate, CreateInstantConversion, - GetInstantConversion + GetInstantConversion, + CreateConversionQuote, + GetConversionQuote, } } diff --git a/MangoPay.SDK/Entities/GET/InstantConversionDTO.cs b/MangoPay.SDK/Entities/GET/ConversionDTO.cs similarity index 97% rename from MangoPay.SDK/Entities/GET/InstantConversionDTO.cs rename to MangoPay.SDK/Entities/GET/ConversionDTO.cs index 72f7d48..843efe4 100644 --- a/MangoPay.SDK/Entities/GET/InstantConversionDTO.cs +++ b/MangoPay.SDK/Entities/GET/ConversionDTO.cs @@ -5,7 +5,7 @@ namespace MangoPay.SDK.Entities.GET { - public class InstantConversionDTO: EntityBase + public class ConversionDTO: EntityBase { /// The unique identifier of the user at the source of the transaction. public string AuthorId { get; set; } diff --git a/MangoPay.SDK/Entities/GET/ConversionQuoteDTO.cs b/MangoPay.SDK/Entities/GET/ConversionQuoteDTO.cs new file mode 100644 index 0000000..43af40c --- /dev/null +++ b/MangoPay.SDK/Entities/GET/ConversionQuoteDTO.cs @@ -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 + { + /// The date and time at which the quote expires + [JsonConverter(typeof(Core.UnixDateTimeConverter))] + public DateTime ExpirationDate { get; set; } + + /// The status of the transaction. + public string Status { get; set; } + + /// The sell funds + public Money DebitedFunds { get; set; } + + /// The buy funds + public Money CreditedFunds { get; set; } + + /// Real time indicative market rate of a specific currency pair + public ConversionRateDTO ConversionRateResponse { get; set; } + } +} \ No newline at end of file diff --git a/MangoPay.SDK/Entities/POST/InstantConversionPostDTO.cs b/MangoPay.SDK/Entities/POST/ConversionPostDTO.cs similarity index 86% rename from MangoPay.SDK/Entities/POST/InstantConversionPostDTO.cs rename to MangoPay.SDK/Entities/POST/ConversionPostDTO.cs index 5dccc47..1c1e64d 100644 --- a/MangoPay.SDK/Entities/POST/InstantConversionPostDTO.cs +++ b/MangoPay.SDK/Entities/POST/ConversionPostDTO.cs @@ -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) { diff --git a/MangoPay.SDK/Entities/POST/ConversionQuotePostDTO.cs b/MangoPay.SDK/Entities/POST/ConversionQuotePostDTO.cs new file mode 100644 index 0000000..5a6444a --- /dev/null +++ b/MangoPay.SDK/Entities/POST/ConversionQuotePostDTO.cs @@ -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; + } + + /// The sell funds + public Money DebitedFunds { get; set; } + + /// The buy funds + public Money CreditedFunds { get; set; } + + /// The time in seconds during which the quote is active and can be used for conversions. + public int Duration { get; set; } + } +} \ No newline at end of file diff --git a/MangoPay.SDK/MangoPayApi.cs b/MangoPay.SDK/MangoPayApi.cs index 469c2b3..65855d5 100644 --- a/MangoPay.SDK/MangoPayApi.cs +++ b/MangoPay.SDK/MangoPayApi.cs @@ -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); } /// Provides authorization token methods. @@ -125,7 +125,7 @@ public MangoPayApi() public ApiDeposits Deposits; - public ApiInstantConversion InstantConversion; + public ApiConversions Conversions; #endregion