Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check DTOs for VirtualAccounts #237

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions MangoPay.SDK.Tests/ApiVirtualAccountsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Threading.Tasks;
using NUnit.Framework;

namespace MangoPay.SDK.Tests
{
[TestFixture]
public class ApiVirtualAccountsTest : BaseTest
{
[Test]
public async Task Test_VirtualAccounts_Create()
{
var wallet = await GetJohnsWallet();
var virtualAccount = await GetJohnsVirtualAccount();

Assert.IsNotNull(virtualAccount);
Assert.AreEqual(virtualAccount.WalletId, wallet.Id);
}

[Test]
public async Task Test_VirtualAccounts_Get()
{
var virtualAccount = await GetJohnsVirtualAccount();
var wallet = await GetJohnsWallet();

var fetchedVirtualAccount = await Api.VirtualAccounts.GetAsync(wallet.Id, virtualAccount.Id);

Assert.IsNotNull(fetchedVirtualAccount);
Assert.AreEqual(fetchedVirtualAccount.Id, virtualAccount.Id);
}

[Test]
public async Task Test_VirtualAccounts_GetAll()
{
var virtualAccount = await GetJohnsVirtualAccount();
var wallet = await GetJohnsWallet();

var virtualAccounts = await Api.VirtualAccounts.GetAllAsync(wallet.Id);

Assert.IsNotNull(virtualAccounts);
Assert.AreEqual(1, virtualAccounts.Count);
Assert.AreEqual(virtualAccount.Id, virtualAccounts[0].Id);
}

[Test]
public async Task Test_VirtualAccounts_GetAvailabilities()
{
var availabilities = await Api.VirtualAccounts.GetAvailabilitiesAsync();

Assert.IsNotNull(availabilities);
Assert.IsTrue(availabilities.Collection.GetType().IsArray);
Assert.IsTrue(availabilities.UserOwned.GetType().IsArray);
Assert.IsNotEmpty(availabilities.Collection);
Assert.IsNotEmpty(availabilities.UserOwned);
}

[Test]
public async Task Test_VirtualAccounts_Deactivate()
{
var virtualAccount = await GetJohnsVirtualAccount();
var wallet = await GetJohnsWallet();
var deactivatedVirtualAccount = await Api.VirtualAccounts.DeactivateAsync(wallet.Id, virtualAccount.Id);

Assert.AreEqual(virtualAccount.Id, deactivatedVirtualAccount.Id);
Assert.IsFalse(deactivatedVirtualAccount.Active);
Assert.AreEqual("CLOSED", deactivatedVirtualAccount.Status);
}
}
}
17 changes: 17 additions & 0 deletions MangoPay.SDK.Tests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public abstract class BaseTest
private static BankAccountIbanDTO _johnsAccount;
private static WalletDTO _johnsWallet;
private static WalletDTO _johnsWalletWithMoney;
private static VirtualAccountDTO _johnsVirtualAccount;
private static PayInCardWebDTO _johnsPayInCardWeb;
private static PayOutBankWireDTO _johnsPayOutBankWire;
private static CardRegistrationDTO _johnsCardRegistration;
Expand Down Expand Up @@ -324,6 +325,22 @@ protected async Task<Tuple<string, WalletDTO>> GetNewJohnsWalletWithMoneyAndCard
return new Tuple<string, WalletDTO>(card.Id, createdWallet);
}

protected async Task<VirtualAccountDTO> GetJohnsVirtualAccount()
{
if (_johnsVirtualAccount != null) return _johnsVirtualAccount;

var wallet = await GetJohnsWallet();
var virtualAccount = new VirtualAccountPostDTO
{
Country = "FR",
VirtualAccountPurpose = "Collection",
Tag = "create virtual account tag"
};
_johnsVirtualAccount = await Api.VirtualAccounts.CreateAsync(wallet.Id, virtualAccount);

return _johnsVirtualAccount;
}

protected async Task<PayInCardWebDTO> GetJohnsPayInCardWeb()
{
if (BaseTest._johnsPayInCardWeb != null) return BaseTest._johnsPayInCardWeb;
Expand Down
6 changes: 6 additions & 0 deletions MangoPay.SDK/Core/APIs/ApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ public abstract class ApiBase
{ MethodKey.GetConversion,new ApiEndPoint("/conversions/{0}",RequestType.GET)},
{ MethodKey.CreateConversionQuote,new ApiEndPoint("/conversions/quote",RequestType.POST)},
{ MethodKey.GetConversionQuote, new ApiEndPoint("/conversions/quote/{0}", RequestType.GET) },

{ MethodKey.VirtualAccountCreate, new ApiEndPoint("/wallets/{0}/virtual-accounts", RequestType.POST) },
{ MethodKey.VirtualAccountDeactivate, new ApiEndPoint("/wallets/{0}/virtual-accounts/{1}", RequestType.PUT) },
{ MethodKey.VirtualAccountGet, new ApiEndPoint("/wallets/{0}/virtual-accounts/{1}", RequestType.GET) },
{ MethodKey.VirtualAccountGetAll, new ApiEndPoint("/wallets/{0}/virtual-accounts", RequestType.GET) },
{ MethodKey.VirtualAccountGetAvailabilities, new ApiEndPoint("/virtual-accounts/availability", RequestType.GET) }
};

/// <summary>Creates new API instance.</summary>
Expand Down
58 changes: 58 additions & 0 deletions MangoPay.SDK/Core/APIs/ApiVirtualAccounts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Threading.Tasks;
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities;
using MangoPay.SDK.Entities.GET;
using MangoPay.SDK.Entities.POST;
using MangoPay.SDK.Entities.PUT;

namespace MangoPay.SDK.Core.APIs
{
/// <summary>API for VirtualAccounts</summary>
public class ApiVirtualAccounts : ApiBase
{
/// <summary>Instantiates new ApiVirtualAccounts object.</summary>
/// <param name="root">Root/parent instance that holds the OAuthToken and Configuration instance.</param>
public ApiVirtualAccounts(MangoPayApi root) : base(root) { }

public async Task<VirtualAccountDTO> CreateAsync(string walletId, VirtualAccountPostDTO virtualAccount, string idempotentKey = null)
{
return await this.CreateObjectAsync<VirtualAccountDTO, VirtualAccountPostDTO>(MethodKey.VirtualAccountCreate, virtualAccount, idempotentKey, entitiesId: walletId);
}

/// <summary>Gets given VirtualAccount associated with wallet</summary>
/// <param name="walletId">Wallet identifier.</param>
/// <param name="virtualAccountId">Virtual Account identifier.</param>
/// <returns>VirtualAccount Object</returns>
public async Task<VirtualAccountDTO> GetAsync(string walletId, string virtualAccountId)
{
return await this.GetObjectAsync<VirtualAccountDTO>(MethodKey.VirtualAccountGet, entitiesId: new[] { walletId, virtualAccountId });
}

/// <summary>Gets all VirtualAccounts associated with wallet</summary>
/// <param name="walletId">Wallet identifier.</param>
/// <param name="pagination">Pagination.</param>
/// <param name="filter">Filter.</param>
/// <param name="sort">Sort.</param>
/// <returns>All related Virtual Account Object</returns>
public async Task<ListPaginated<VirtualAccountDTO>> GetAllAsync(string walletId, Pagination pagination = null, FilterTransactions filter = null, Sort sort = null)
{
return await this.GetListAsync<VirtualAccountDTO>(MethodKey.VirtualAccountGetAll, pagination, sort, filter?.GetValues(), entitiesId: walletId);
}

/// <summary>Deactivates given VirtualAccount</summary>
/// <param name="walletId">Wallet identifier.</param>
/// <param name="virtualAccountId">Virtual Account identifier.</param>
/// <returns>Deactivated VirtualAccount Object</returns>
public async Task<VirtualAccountDTO> DeactivateAsync(string walletId, string virtualAccountId)
{
return await this.UpdateObjectAsync<VirtualAccountDTO, VirtualAccountPutDTO>(methodKey: MethodKey.VirtualAccountDeactivate, entity: new VirtualAccountPutDTO(), entitiesId: new[] { walletId, virtualAccountId });
}

/// <summary>Gets all virtual account availabilities.</summary>
/// <returns>VirtualAccountAvailabilities Object</returns>
public async Task<VirtualAccountAvailabilitiesDTO> GetAvailabilitiesAsync()
{
return await this.GetObjectAsync<VirtualAccountAvailabilitiesDTO>(MethodKey.VirtualAccountGetAvailabilities);
}
}
}
7 changes: 6 additions & 1 deletion MangoPay.SDK/Core/Enumerations/EventType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public enum EventType
CARD_VALIDATION_SUCCEEDED,

LEGAL_COMPANY_NUMBER_VALIDATION_SUCCEEDED,
LEGAL_COMPANY_NUMBER_VALIDATION_FAILED
LEGAL_COMPANY_NUMBER_VALIDATION_FAILED,

VIRTUAL_ACCOUNT_ACTIVE,
VIRTUAL_ACCOUNT_BLOCKED,
VIRTUAL_ACCOUNT_CLOSED,
VIRTUAL_ACCOUNT_FAILED
}
}
8 changes: 7 additions & 1 deletion MangoPay.SDK/Core/Enumerations/MethodKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ public enum MethodKey
GetConversion,
CreateConversionQuote,
GetConversionQuote,
PayInsAddTrackingInformation
PayInsAddTrackingInformation,

VirtualAccountCreate,
VirtualAccountGet,
VirtualAccountGetAll,
VirtualAccountDeactivate,
VirtualAccountGetAvailabilities,
}
}
17 changes: 17 additions & 0 deletions MangoPay.SDK/Entities/GET/VirtualAccountAvailabilitiesDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;

namespace MangoPay.SDK.Entities.GET
{
public class VirtualAccountAvailabilitiesDTO : EntityBase
{
public VirtualAccountAvailabilitiesDTO()
{
Collection = new List<VirtualAccountAvailability>();
UserOwned = new List<VirtualAccountAvailability>();
}

public List<VirtualAccountAvailability> Collection;

public List<VirtualAccountAvailability> UserOwned;
}
}
27 changes: 27 additions & 0 deletions MangoPay.SDK/Entities/GET/VirtualAccountDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;

namespace MangoPay.SDK.Entities.GET
{
public class VirtualAccountDTO : EntityBase
{
public string WalletId { get; set; }

public string CreditedUserId { get; set; }

public string VirtualAccountPurpose { get; set; }

public string Country { get; set; }

public string Status { get; set; }

public bool Active { get; set; }

public string AccountOwner { get; set; }

public LocalAccountDetails LocalAccountDetails { get; set; }

public List<InternationalAccountDetails> InternationalAccountDetails { get; set; }

public VirtualAccountCapabilities Capabilities { get; set; }
}
}
9 changes: 9 additions & 0 deletions MangoPay.SDK/Entities/InternationalAccount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MangoPay.SDK.Entities
{
public class InternationalAccount
{
public string IBAN { get; set; }

public string BIC { get; set; }
}
}
9 changes: 9 additions & 0 deletions MangoPay.SDK/Entities/InternationalAccountDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MangoPay.SDK.Entities
{
public class InternationalAccountDetails
{
public VirtualAccountAddress Address { get; set; }

public InternationalAccount Account { get; set; }
}
}
9 changes: 9 additions & 0 deletions MangoPay.SDK/Entities/LocalAccount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MangoPay.SDK.Entities
{
public class LocalAccount
{
public string AccountNumber { get; set; }

public string SortCode { get; set; }
}
}
9 changes: 9 additions & 0 deletions MangoPay.SDK/Entities/LocalAccountDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MangoPay.SDK.Entities
{
public class LocalAccountDetails
{
public VirtualAccountAddress Address { get; set; }

public LocalAccount Account { get; set; }
}
}
32 changes: 32 additions & 0 deletions MangoPay.SDK/Entities/POST/VirtualAccountPostDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections.Generic;

namespace MangoPay.SDK.Entities.POST
{
public class VirtualAccountPostDTO : EntityPostBase
{
public VirtualAccountPostDTO()
{

}

public string WalletId { get; set; }

public string CreditedUserId { get; set; }

public string VirtualAccountPurpose { get; set; }

public string Country { get; set; }

public string Status { get; set; }

public bool Active { get; set; }

public string AccountOwner { get; set; }

public LocalAccountDetails LocalAccountDetails { get; set; }

public List<InternationalAccountDetails> InternationalAccountDetails { get; set; }

public VirtualAccountCapabilities Capabilities { get; set; }
}
}
7 changes: 7 additions & 0 deletions MangoPay.SDK/Entities/PUT/VirtualAccountPutDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace MangoPay.SDK.Entities.PUT
{
public class VirtualAccountPutDTO : EntityPutBase
{

}
}
29 changes: 29 additions & 0 deletions MangoPay.SDK/Entities/VirtualAccountAddress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace MangoPay.SDK.Entities
{
public class VirtualAccountAddress
{
public VirtualAccountAddress(
string streetName,
string postCode,
string townName,
string countrySubDivision,
string country)
{
StreetName = streetName;
PostCode = postCode;
TownName = townName;
CountrySubDivision = countrySubDivision;
Country = country;
}

private string StreetName { get; set; }

private string PostCode { get; set; }

private string TownName { get; set; }

private string CountrySubDivision { get; set; }

private string Country { get; set; }
}
}
27 changes: 27 additions & 0 deletions MangoPay.SDK/Entities/VirtualAccountAvailability.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using MangoPay.SDK.Core.Enumerations;

namespace MangoPay.SDK.Entities
{
public class VirtualAccountAvailability
{

public VirtualAccountAvailability()
{
Currencies = new List<CurrencyIso>();
}

public VirtualAccountAvailability(string country, bool available)
{
Country = country;
Available = available;
Currencies = new List<CurrencyIso>();
}

private string Country { get; set; }

private bool Available { get; set; }

public List<CurrencyIso> Currencies;
}
}
Loading
Loading