From 3e0d4e770a5757c805a31ad6aa5508de8ca894a6 Mon Sep 17 00:00:00 2001 From: Mihai Moiseanu Date: Thu, 22 Feb 2024 14:09:49 +0200 Subject: [PATCH] quoted conversion impl --- MangoPay.SDK.Tests/ApiConversionsTest.cs | 27 +++++++++++++++ MangoPay.SDK/Core/APIs/ApiBase.cs | 1 + MangoPay.SDK/Core/APIs/ApiConversions.cs | 12 ++++++- MangoPay.SDK/Core/Enumerations/MethodKey.cs | 1 + .../Entities/GET/QuotedConversionDTO.cs | 11 ++++++ .../Entities/POST/QuotedConversionPostDTO.cs | 34 +++++++++++++++++++ 6 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 MangoPay.SDK/Entities/GET/QuotedConversionDTO.cs create mode 100644 MangoPay.SDK/Entities/POST/QuotedConversionPostDTO.cs diff --git a/MangoPay.SDK.Tests/ApiConversionsTest.cs b/MangoPay.SDK.Tests/ApiConversionsTest.cs index 299b6e5..999b9cc 100644 --- a/MangoPay.SDK.Tests/ApiConversionsTest.cs +++ b/MangoPay.SDK.Tests/ApiConversionsTest.cs @@ -71,6 +71,33 @@ public async Task Test_GetConversionQuote() Assert.AreEqual("ACTIVE", returnedConversionQuote.Status); } + [Test] + public async Task Test_CreateQuotedConversion() + { + 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 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 CreateInstantConversion() { var john = await GetJohn(); diff --git a/MangoPay.SDK/Core/APIs/ApiBase.cs b/MangoPay.SDK/Core/APIs/ApiBase.cs index 8f554f2..55dac18 100644 --- a/MangoPay.SDK/Core/APIs/ApiBase.cs +++ b/MangoPay.SDK/Core/APIs/ApiBase.cs @@ -237,6 +237,7 @@ public abstract class ApiBase { 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)}, + { MethodKey.CreateQuotedConversion, new ApiEndPoint("/conversions/quoted-conversion", RequestType.POST)}, }; diff --git a/MangoPay.SDK/Core/APIs/ApiConversions.cs b/MangoPay.SDK/Core/APIs/ApiConversions.cs index 8ea98b5..1359030 100644 --- a/MangoPay.SDK/Core/APIs/ApiConversions.cs +++ b/MangoPay.SDK/Core/APIs/ApiConversions.cs @@ -24,7 +24,7 @@ public async Task CreateInstantConversion(ConversionPostDTO conve this.CreateObjectAsync(MethodKey.CreateInstantConversion, conversion, idempotentKey); } - + public async Task GetInstantConversion(string id) { return await this.GetObjectAsync(MethodKey.GetInstantConversion, @@ -44,5 +44,15 @@ public async Task GetConversionQuote(string id) { return await this.GetObjectAsync(MethodKey.GetConversionQuote, entitiesId: id); } + + public async Task CreateQuotedConversion( + QuotedConversionPostDTO quotedConversionPostDto, + string idempotentKey = null) + { + return await this.CreateObjectAsync( + MethodKey.CreateQuotedConversion, + quotedConversionPostDto, + idempotentKey); + } } } \ No newline at end of file diff --git a/MangoPay.SDK/Core/Enumerations/MethodKey.cs b/MangoPay.SDK/Core/Enumerations/MethodKey.cs index 4ada411..76158d1 100644 --- a/MangoPay.SDK/Core/Enumerations/MethodKey.cs +++ b/MangoPay.SDK/Core/Enumerations/MethodKey.cs @@ -195,5 +195,6 @@ public enum MethodKey GetInstantConversion, CreateConversionQuote, GetConversionQuote, + CreateQuotedConversion, } } diff --git a/MangoPay.SDK/Entities/GET/QuotedConversionDTO.cs b/MangoPay.SDK/Entities/GET/QuotedConversionDTO.cs new file mode 100644 index 0000000..827f534 --- /dev/null +++ b/MangoPay.SDK/Entities/GET/QuotedConversionDTO.cs @@ -0,0 +1,11 @@ +namespace MangoPay.SDK.Entities.GET +{ + public class QuotedConversionDTO : TransactionDTO + { + /// The unique identifier of the active quote which guaranteed the rate for the conversion. + public string QuoteId { get; set; } + + /// Information about the conversion rate used during the transaction. + public ConversionRateDTO ConversionRateResponse { get; set; } + } +} \ No newline at end of file diff --git a/MangoPay.SDK/Entities/POST/QuotedConversionPostDTO.cs b/MangoPay.SDK/Entities/POST/QuotedConversionPostDTO.cs new file mode 100644 index 0000000..f9ccc88 --- /dev/null +++ b/MangoPay.SDK/Entities/POST/QuotedConversionPostDTO.cs @@ -0,0 +1,34 @@ +namespace MangoPay.SDK.Entities.POST +{ + public class QuotedConversionPostDTO : EntityPostBase + { + public QuotedConversionPostDTO( + string quoteId, + string authorId, + string debitedWalletId, + string creditedWalletId, + string tag + ) + { + QuoteId = quoteId; + AuthorId = authorId; + DebitedWalletId = debitedWalletId; + CreditedWalletId = creditedWalletId; + Tag = tag; + } + + /// The unique identifier of the active quote which guaranteed + /// the rate for the conversion. + public string QuoteId { get; set; } + + /// The unique identifier of the user at the source of the + /// transaction. In a conversion, both the debited and credited wallets are owned by the author. + public string AuthorId { get; set; } + + /// The unique identifier of the debited wallet (in the sell currency). + public string DebitedWalletId { get; set; } + + /// The unique identifier of the credited wallet (in the buy currency). + public string CreditedWalletId { get; set; } + } +} \ No newline at end of file