From 13c5778353fb2cf4e4d47acce59b94152122264f Mon Sep 17 00:00:00 2001 From: Silviana Ghita Date: Wed, 20 Sep 2023 11:45:02 +0300 Subject: [PATCH] Integrated Spot FX endpoints --- .../ApiInstantConversionTest.cs | 70 +++++++++++++++++++ MangoPay.SDK/Core/APIs/ApiBase.cs | 6 +- .../Core/APIs/ApiInstantConversion.cs | 34 +++++++++ MangoPay.SDK/Core/Enumerations/MethodKey.cs | 6 +- .../Core/Enumerations/TransactionType.cs | 5 +- .../Entities/GET/ConversionRateDTO.cs | 18 +++++ .../Entities/GET/InstantConversionDTO.cs | 54 ++++++++++++++ .../Entities/POST/InstantConversionPostDTO.cs | 33 +++++++++ MangoPay.SDK/MangoPayApi.cs | 3 + 9 files changed, 226 insertions(+), 3 deletions(-) create mode 100644 MangoPay.SDK.Tests/ApiInstantConversionTest.cs create mode 100644 MangoPay.SDK/Core/APIs/ApiInstantConversion.cs create mode 100644 MangoPay.SDK/Entities/GET/ConversionRateDTO.cs create mode 100644 MangoPay.SDK/Entities/GET/InstantConversionDTO.cs create mode 100644 MangoPay.SDK/Entities/POST/InstantConversionPostDTO.cs diff --git a/MangoPay.SDK.Tests/ApiInstantConversionTest.cs b/MangoPay.SDK.Tests/ApiInstantConversionTest.cs new file mode 100644 index 00000000..8c81ea86 --- /dev/null +++ b/MangoPay.SDK.Tests/ApiInstantConversionTest.cs @@ -0,0 +1,70 @@ +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 ApiInstantConversionTest: BaseTest + { + [Test] + public async Task Test_GetConversionRate() + { + var conversionRate = await Api.InstantConversion.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.InstantConversion.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); + } + + private async Task CreateInstantConversion() + { + var john = await GetJohn(); + var wallet = + new WalletPostDTO(new List {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 = 79, Currency = CurrencyIso.EUR }, + new Money { Currency = CurrencyIso.GBP }, + "create instant conversion" + ); + + return await Api.InstantConversion.CreateInstantConversion(instantConversion); + } + } +} \ No newline at end of file diff --git a/MangoPay.SDK/Core/APIs/ApiBase.cs b/MangoPay.SDK/Core/APIs/ApiBase.cs index 6c9f5876..a5cb100e 100644 --- a/MangoPay.SDK/Core/APIs/ApiBase.cs +++ b/MangoPay.SDK/Core/APIs/ApiBase.cs @@ -220,7 +220,11 @@ public abstract class ApiBase { MethodKey.DepositsCreate,new ApiEndPoint("/deposit-preauthorizations/card/direct",RequestType.POST)}, { MethodKey.DepositsGet,new ApiEndPoint("/deposit-preauthorizations/{0}",RequestType.GET)}, - { MethodKey.DepositsCancel,new ApiEndPoint("/deposit-preauthorizations/{0}",RequestType.PUT)} + { MethodKey.DepositsCancel,new ApiEndPoint("/deposit-preauthorizations/{0}",RequestType.PUT)}, + + { 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)} }; /// Creates new API instance. diff --git a/MangoPay.SDK/Core/APIs/ApiInstantConversion.cs b/MangoPay.SDK/Core/APIs/ApiInstantConversion.cs new file mode 100644 index 00000000..f237315c --- /dev/null +++ b/MangoPay.SDK/Core/APIs/ApiInstantConversion.cs @@ -0,0 +1,34 @@ +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 a5874a61..3149beba 100644 --- a/MangoPay.SDK/Core/Enumerations/MethodKey.cs +++ b/MangoPay.SDK/Core/Enumerations/MethodKey.cs @@ -179,6 +179,10 @@ public enum MethodKey DepositsCreate, DepositsGet, DepositsCancel, - PayInsCreateCardPreAuthorizedDeposit + PayInsCreateCardPreAuthorizedDeposit, + + GetConversionRate, + CreateInstantConversion, + GetInstantConversion } } diff --git a/MangoPay.SDK/Core/Enumerations/TransactionType.cs b/MangoPay.SDK/Core/Enumerations/TransactionType.cs index 2a0d3df2..9e4b7cb4 100644 --- a/MangoPay.SDK/Core/Enumerations/TransactionType.cs +++ b/MangoPay.SDK/Core/Enumerations/TransactionType.cs @@ -17,6 +17,9 @@ public enum TransactionType PAYOUT = 0x02, /// TRANSFER transaction type. - TRANSFER = 0x04 + TRANSFER = 0x04, + + /// CONVERSION transaction type. + CONVERSION = 0x06 } } diff --git a/MangoPay.SDK/Entities/GET/ConversionRateDTO.cs b/MangoPay.SDK/Entities/GET/ConversionRateDTO.cs new file mode 100644 index 00000000..9420c66a --- /dev/null +++ b/MangoPay.SDK/Entities/GET/ConversionRateDTO.cs @@ -0,0 +1,18 @@ +namespace MangoPay.SDK.Entities.GET +{ + public class ConversionRateDTO: EntityBase + { + /// The sell currency – the currency of the wallet to be debited + public string DebitedCurrency { get; set; } + + /// The buy currency – the currency of the wallet to be credited. + public string CreditedCurrency { get; set; } + + /// The market rate plus Mangopay's commission, + /// charged during the platform's billing cycle. This is an indicative rate. + public string ClientRate { get; set; } + + /// The rate used for the conversion, excluding Mangopay's commission. + public string MarketRate { get; set; } + } +} \ No newline at end of file diff --git a/MangoPay.SDK/Entities/GET/InstantConversionDTO.cs b/MangoPay.SDK/Entities/GET/InstantConversionDTO.cs new file mode 100644 index 00000000..72f7d48b --- /dev/null +++ b/MangoPay.SDK/Entities/GET/InstantConversionDTO.cs @@ -0,0 +1,54 @@ +using System; +using MangoPay.SDK.Core.Enumerations; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace MangoPay.SDK.Entities.GET +{ + public class InstantConversionDTO: EntityBase + { + /// The unique identifier of the user at the source of the transaction. + public string AuthorId { get; set; } + + /// The unique identifier of the debited wallet. + public string DebitedWalletId { get; set; } + + /// The unique identifier of the credited wallet + public string CreditedWalletId { 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 ConversionRate { get; set; } + + /// The status of the transaction. + [JsonConverter(typeof(StringEnumConverter))] + public TransactionStatus Status { get; set; } + + /// The type of transaction + [JsonConverter(typeof(StringEnumConverter))] + public TransactionType Type { get; set; } + + /// The nature of the transaction, providing more + /// information about the context in which the transaction occurred + [JsonConverter(typeof(StringEnumConverter))] + public TransactionNature Nature { get; set; } + + /// The code indicates the result of the operation. + /// This information is mostly used to handle errors or for filtering purposes. + public string ResultCode { get; set; } + + /// The explanation of the result code. + public string ResultMessage { get; set; } + + /// 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 + [JsonConverter(typeof(Core.UnixDateTimeConverter))] + public DateTime ExecutionDate { get; set; } + } +} \ No newline at end of file diff --git a/MangoPay.SDK/Entities/POST/InstantConversionPostDTO.cs b/MangoPay.SDK/Entities/POST/InstantConversionPostDTO.cs new file mode 100644 index 00000000..5dccc47a --- /dev/null +++ b/MangoPay.SDK/Entities/POST/InstantConversionPostDTO.cs @@ -0,0 +1,33 @@ +namespace MangoPay.SDK.Entities.POST +{ + public class InstantConversionPostDTO: EntityPostBase + { + + public InstantConversionPostDTO(string authorId, string debitedWalletId, string creditedWalletId, + Money debitedFunds, Money creditedFunds, + string tag = null) + { + AuthorId = authorId; + DebitedWalletId = debitedWalletId; + CreditedWalletId = creditedWalletId; + DebitedFunds = debitedFunds; + CreditedFunds = creditedFunds; + Tag = tag; + } + + /// The unique identifier of the user at the source of the transaction. + public string AuthorId { get; set; } + + /// The unique identifier of the debited wallet. + public string DebitedWalletId { get; set; } + + /// The unique identifier of the credited wallet + public string CreditedWalletId { get; set; } + + /// The sell funds + public Money DebitedFunds { get; set; } + + /// The buy funds + public Money CreditedFunds { get; set; } + } +} \ No newline at end of file diff --git a/MangoPay.SDK/MangoPayApi.cs b/MangoPay.SDK/MangoPayApi.cs index d8953010..469c2b38 100644 --- a/MangoPay.SDK/MangoPayApi.cs +++ b/MangoPay.SDK/MangoPayApi.cs @@ -42,6 +42,7 @@ public MangoPayApi() UboDeclarations = new ApiUboDeclarations(this); Regulatory = new ApiRegulatory(this); Deposits = new ApiDeposits(this); + InstantConversion = new ApiInstantConversion(this); } /// Provides authorization token methods. @@ -124,6 +125,8 @@ public MangoPayApi() public ApiDeposits Deposits; + public ApiInstantConversion InstantConversion; + #endregion #region Internal and private