Skip to content

Commit

Permalink
Merge pull request #197 from Mangopay/feature/spot-fx-endpoints
Browse files Browse the repository at this point in the history
Feature/Integrated Spot FX endpoints
  • Loading branch information
silvianagh authored Sep 29, 2023
2 parents e35894f + 3307390 commit ec52c14
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 3 deletions.
70 changes: 70 additions & 0 deletions MangoPay.SDK.Tests/ApiInstantConversionTest.cs
Original file line number Diff line number Diff line change
@@ -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<InstantConversionDTO> CreateInstantConversion()
{
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 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);
}
}
}
6 changes: 5 additions & 1 deletion MangoPay.SDK/Core/APIs/ApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,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)}
};

/// <summary>Creates new API instance.</summary>
Expand Down
34 changes: 34 additions & 0 deletions MangoPay.SDK/Core/APIs/ApiInstantConversion.cs
Original file line number Diff line number Diff line change
@@ -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<ConversionRateDTO> GetConversionRate(string debitedCurrency, string creditedCurrency)
{
return await this.GetObjectAsync<ConversionRateDTO>(MethodKey.GetConversionRate,
entitiesId: new[] { debitedCurrency, creditedCurrency });
}

public async Task<InstantConversionDTO> CreateInstantConversion(InstantConversionPostDTO instantConversion,
string idempotentKey = null)
{
return await
this.CreateObjectAsync<InstantConversionDTO, InstantConversionPostDTO>(MethodKey.CreateInstantConversion,
instantConversion, idempotentKey);
}

public async Task<InstantConversionDTO> GetInstantConversion(string id)
{
return await this.GetObjectAsync<InstantConversionDTO>(MethodKey.GetInstantConversion,
entitiesId: id);
}
}
}
6 changes: 5 additions & 1 deletion MangoPay.SDK/Core/Enumerations/MethodKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ public enum MethodKey
DepositsCreate,
DepositsGet,
DepositsCancel,
PayInsCreateCardPreAuthorizedDeposit
PayInsCreateCardPreAuthorizedDeposit,

GetConversionRate,
CreateInstantConversion,
GetInstantConversion
}
}
5 changes: 4 additions & 1 deletion MangoPay.SDK/Core/Enumerations/TransactionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public enum TransactionType
TRANSFER = 0x04,

/// <summary>CARD_VALIDATION transaction type.</summary>
CARD_VALIDATION = 0x05
CARD_VALIDATION = 0x05,

/// <summary>CONVERSION transaction type.</summary>
CONVERSION = 0x06
}
}
18 changes: 18 additions & 0 deletions MangoPay.SDK/Entities/GET/ConversionRateDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace MangoPay.SDK.Entities.GET
{
public class ConversionRateDTO: EntityBase
{
/// <summary>The sell currency – the currency of the wallet to be debited</summary>
public string DebitedCurrency { get; set; }

/// <summary>The buy currency – the currency of the wallet to be credited.</summary>
public string CreditedCurrency { get; set; }

/// <summary>The market rate plus Mangopay's commission,
/// charged during the platform's billing cycle. This is an indicative rate.</summary>
public string ClientRate { get; set; }

/// <summary>The rate used for the conversion, excluding Mangopay's commission.</summary>
public string MarketRate { get; set; }
}
}
54 changes: 54 additions & 0 deletions MangoPay.SDK/Entities/GET/InstantConversionDTO.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>The unique identifier of the user at the source of the transaction.</summary>
public string AuthorId { get; set; }

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

/// <summary>The unique identifier of the credited wallet</summary>
public string CreditedWalletId { 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 ConversionRate { get; set; }

/// <summary>The status of the transaction.</summary>
[JsonConverter(typeof(StringEnumConverter))]
public TransactionStatus Status { get; set; }

/// <summary>The type of transaction</summary>
[JsonConverter(typeof(StringEnumConverter))]
public TransactionType Type { get; set; }

/// <summary>The nature of the transaction, providing more
/// information about the context in which the transaction occurred</summary>
[JsonConverter(typeof(StringEnumConverter))]
public TransactionNature Nature { get; set; }

/// <summary>The code indicates the result of the operation.
/// This information is mostly used to handle errors or for filtering purposes.</summary>
public string ResultCode { get; set; }

/// <summary>The explanation of the result code.</summary>
public string ResultMessage { get; set; }

/// <summary>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</summary>
[JsonConverter(typeof(Core.UnixDateTimeConverter))]
public DateTime ExecutionDate { get; set; }
}
}
33 changes: 33 additions & 0 deletions MangoPay.SDK/Entities/POST/InstantConversionPostDTO.cs
Original file line number Diff line number Diff line change
@@ -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;
}

/// <summary>The unique identifier of the user at the source of the transaction.</summary>
public string AuthorId { get; set; }

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

/// <summary>The unique identifier of the credited wallet</summary>
public string CreditedWalletId { get; set; }

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

/// <summary>The buy funds</summary>
public Money CreditedFunds { get; set; }
}
}
3 changes: 3 additions & 0 deletions MangoPay.SDK/MangoPayApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public MangoPayApi()
UboDeclarations = new ApiUboDeclarations(this);
Regulatory = new ApiRegulatory(this);
Deposits = new ApiDeposits(this);
InstantConversion = new ApiInstantConversion(this);
}

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

public ApiDeposits Deposits;

public ApiInstantConversion InstantConversion;

#endregion

#region Internal and private
Expand Down

0 comments on commit ec52c14

Please sign in to comment.