Skip to content

Commit

Permalink
Merge pull request #216 from Mangopay/feature/quoted_conversion
Browse files Browse the repository at this point in the history
Quoted conversion
  • Loading branch information
mihaimoiseanu authored Mar 7, 2024
2 parents 841dace + 3e0d4e7 commit c9307d4
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 1 deletion.
27 changes: 27 additions & 0 deletions MangoPay.SDK.Tests/ApiConversionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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"
);

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<ConversionDTO> CreateInstantConversion()
{
var john = await GetJohn();
Expand Down
1 change: 1 addition & 0 deletions MangoPay.SDK/Core/APIs/ApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)},

};

Expand Down
12 changes: 11 additions & 1 deletion MangoPay.SDK/Core/APIs/ApiConversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<ConversionDTO> CreateInstantConversion(ConversionPostDTO conve
this.CreateObjectAsync<ConversionDTO, ConversionPostDTO>(MethodKey.CreateInstantConversion,
conversion, idempotentKey);
}

public async Task<ConversionDTO> GetInstantConversion(string id)
{
return await this.GetObjectAsync<ConversionDTO>(MethodKey.GetInstantConversion,
Expand All @@ -44,5 +44,15 @@ public async Task<ConversionQuoteDTO> GetConversionQuote(string id)
{
return await this.GetObjectAsync<ConversionQuoteDTO>(MethodKey.GetConversionQuote, entitiesId: id);
}

public async Task<QuotedConversionDTO> CreateQuotedConversion(
QuotedConversionPostDTO quotedConversionPostDto,
string idempotentKey = null)
{
return await this.CreateObjectAsync<QuotedConversionDTO, QuotedConversionPostDTO>(
MethodKey.CreateQuotedConversion,
quotedConversionPostDto,
idempotentKey);
}
}
}
1 change: 1 addition & 0 deletions MangoPay.SDK/Core/Enumerations/MethodKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,6 @@ public enum MethodKey
GetInstantConversion,
CreateConversionQuote,
GetConversionQuote,
CreateQuotedConversion,
}
}
11 changes: 11 additions & 0 deletions MangoPay.SDK/Entities/GET/QuotedConversionDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace MangoPay.SDK.Entities.GET
{
public class QuotedConversionDTO : TransactionDTO
{
/// <summary>The unique identifier of the active quote which guaranteed the rate for the conversion.</summary>
public string QuoteId { get; set; }

/// <summary>Information about the conversion rate used during the transaction.</summary>
public ConversionRateDTO ConversionRateResponse { get; set; }
}
}
34 changes: 34 additions & 0 deletions MangoPay.SDK/Entities/POST/QuotedConversionPostDTO.cs
Original file line number Diff line number Diff line change
@@ -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;
}

/// <summary>The unique identifier of the active quote which guaranteed
/// the rate for the conversion.</summary>
public string QuoteId { get; set; }

/// <summary>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.</summary>
public string AuthorId { get; set; }

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

/// <summary>The unique identifier of the credited wallet (in the buy currency).</summary>
public string CreditedWalletId { get; set; }
}
}

0 comments on commit c9307d4

Please sign in to comment.