-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from Mangopay/feature/spot-fx-endpoints
Feature/Integrated Spot FX endpoints
- Loading branch information
Showing
9 changed files
with
226 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters