Skip to content

Commit d1afa03

Browse files
iulian03Iulian Masar
and
Iulian Masar
authored
[release] 3.27.0 (#261)
* [feature] recipients (#251) * recipients integration: - create recipient - get recipient - get all recipients for a user - get payout methods - add recipients event types * handle fetching recipient schema * handle validation of recipients * handle deactivation of recipients * updated RecipientSchemaDTO.cs * updated RecipientPropertySchema.cs * updated RecipientDTO.cs and RecipientPostDTO.cs properties * updated the deactivation method --------- Co-authored-by: Iulian Masar <iulian.masar@codegile.com> * handle sca context on transfers (#255) Co-authored-by: Iulian Masar <iulian.masar@codegile.com> * added support for close user endpoints (#260) Co-authored-by: Iulian Masar <iulian.masar@codegile.com> --------- Co-authored-by: Iulian Masar <iulian.masar@codegile.com>
1 parent f9632f2 commit d1afa03

29 files changed

+780
-90
lines changed
+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using MangoPay.SDK.Core.Enumerations;
5+
using MangoPay.SDK.Entities;
6+
using MangoPay.SDK.Entities.GET;
7+
using MangoPay.SDK.Entities.PUT;
8+
using NUnit.Framework;
9+
10+
namespace MangoPay.SDK.Tests
11+
{
12+
[TestFixture]
13+
[Explicit]
14+
public class ApiRecipientsTest : BaseTest
15+
{
16+
private static RecipientDTO _recipient;
17+
18+
[Test]
19+
public async Task Test_CreateRecipient()
20+
{
21+
await GetNewRecipient();
22+
23+
Assert.IsNotNull(_recipient);
24+
Assert.IsNotNull(_recipient.Status);
25+
Assert.IsNotNull(_recipient.DisplayName);
26+
Assert.IsNotNull(_recipient.PayoutMethodType);
27+
Assert.IsNotNull(_recipient.RecipientType);
28+
Assert.IsNotNull(_recipient.RecipientScope);
29+
Assert.IsNotNull(_recipient.UserId);
30+
Assert.IsNotNull(_recipient.IndividualRecipient);
31+
Assert.IsNotNull(_recipient.LocalBankTransfer);
32+
Assert.IsNotNull(_recipient.LocalBankTransfer["GBP"].SortCode);
33+
Assert.IsNotNull(_recipient.LocalBankTransfer["GBP"].AccountNumber);
34+
Assert.IsNotNull(_recipient.PendingUserAction);
35+
}
36+
37+
[Test]
38+
public async Task Test_GetRecipient()
39+
{
40+
await GetNewRecipient();
41+
RecipientDTO fetched = await Api.Recipients.GetAsync(_recipient.Id);
42+
Assert.IsNotNull(fetched);
43+
Assert.AreEqual(_recipient.Id, fetched.Id);
44+
Assert.AreEqual(_recipient.Status, fetched.Status);
45+
}
46+
47+
[Test]
48+
public async Task Test_GetUserRecipients()
49+
{
50+
await GetNewRecipient();
51+
UserNaturalScaDTO john = await GetJohnScaOwner();
52+
ListPaginated<RecipientDTO> recipients = await Api.Recipients.GetUserRecipientsAsync(john.Id);
53+
Assert.IsNotEmpty(recipients);
54+
}
55+
56+
[Test]
57+
public async Task Test_GetPayoutMethods()
58+
{
59+
PayoutMethods payoutMethods = await Api.Recipients.GetPayoutMethodsAsync(CountryIso.DE, CurrencyIso.EUR);
60+
Assert.IsNotNull(payoutMethods);
61+
Assert.IsNotEmpty(payoutMethods.AvailablePayoutMethods);
62+
}
63+
64+
[Test]
65+
public async Task Test_GetSchema_LocalBankTransfer_Individual()
66+
{
67+
RecipientSchemaDTO schema =
68+
await Api.Recipients.GetSchemaAsync("LocalBankTransfer", "Individual",
69+
CurrencyIso.GBP);
70+
Assert.IsNotNull(schema);
71+
Assert.IsNotNull(schema.DisplayName);
72+
Assert.IsNotNull(schema.Currency);
73+
Assert.IsNotNull(schema.RecipientType);
74+
Assert.IsNotNull(schema.PayoutMethodType);
75+
Assert.IsNotNull(schema.RecipientScope);
76+
Assert.IsNotNull(schema.Tag);
77+
Assert.IsNotNull(schema.LocalBankTransfer);
78+
Assert.IsNotNull(schema.IndividualRecipient);
79+
Assert.IsNull(schema.InternationalBankTransfer);
80+
Assert.IsNull(schema.BusinessRecipient);
81+
}
82+
83+
[Test]
84+
public async Task Test_GetSchema_InternationalBankTransfer_Business()
85+
{
86+
RecipientSchemaDTO schema =
87+
await Api.Recipients.GetSchemaAsync("InternationalBankTransfer", "Business",
88+
CurrencyIso.GBP);
89+
Assert.IsNotNull(schema);
90+
Assert.IsNotNull(schema.DisplayName);
91+
Assert.IsNotNull(schema.Currency);
92+
Assert.IsNotNull(schema.RecipientType);
93+
Assert.IsNotNull(schema.PayoutMethodType);
94+
Assert.IsNotNull(schema.RecipientScope);
95+
Assert.IsNotNull(schema.Tag);
96+
Assert.IsNotNull(schema.InternationalBankTransfer);
97+
Assert.IsNotNull(schema.BusinessRecipient);
98+
Assert.IsNull(schema.LocalBankTransfer);
99+
Assert.IsNull(schema.IndividualRecipient);
100+
}
101+
102+
[Test]
103+
public async Task Test_ValidateRecipient()
104+
{
105+
RecipientPostDTO postDto = GetPostDto();
106+
UserNaturalScaDTO john = await GetJohnScaOwner();
107+
// should pass
108+
await Api.Recipients.ValidateAsync(postDto, john.Id);
109+
110+
// should fail
111+
postDto.DisplayName = null;
112+
try
113+
{
114+
await Api.Recipients.ValidateAsync(postDto, john.Id);
115+
}
116+
catch (Exception e)
117+
{
118+
Assert.True(e.Message.Contains("One or several required parameters are missing or incorrect"));
119+
}
120+
}
121+
122+
[Test]
123+
[Ignore("The recipient needs to be manually activated before running the test")]
124+
public async Task Test_DeactivateRecipient()
125+
{
126+
await GetNewRecipient();
127+
Assert.AreEqual("PENDING", _recipient.Status);
128+
RecipientPutDTO putDto = new RecipientPutDTO() { Status = "DEACTIVATED" };
129+
130+
RecipientDTO deactivated = await Api.Recipients.DeactivateAsync(putDto, _recipient.Id);
131+
RecipientDTO fetched = await Api.Recipients.GetAsync(_recipient.Id);
132+
Assert.AreEqual("DEACTIVATED", deactivated.Status);
133+
Assert.AreEqual("DEACTIVATED", fetched.Status);
134+
}
135+
136+
private async Task GetNewRecipient()
137+
{
138+
if (_recipient == null)
139+
{
140+
UserNaturalScaDTO john = await GetJohnScaOwner();
141+
RecipientPostDTO postDto = GetPostDto();
142+
_recipient = await Api.Recipients.CreateAsync(postDto, john.Id);
143+
}
144+
}
145+
146+
private RecipientPostDTO GetPostDto()
147+
{
148+
RecipientPostDTO postDto = new RecipientPostDTO();
149+
150+
Dictionary<string, object> localBankTransfer = new Dictionary<string, object>();
151+
Dictionary<string, object> gbpDetails = new Dictionary<string, object>();
152+
gbpDetails.Add("SortCode", "010039");
153+
gbpDetails.Add("AccountNumber", "11696419");
154+
localBankTransfer.Add(CurrencyIso.GBP.ToString(), gbpDetails);
155+
156+
postDto.DisplayName = "My DB account";
157+
postDto.PayoutMethodType = "LocalBankTransfer";
158+
postDto.RecipientType = "Individual";
159+
postDto.Currency = CurrencyIso.GBP;
160+
postDto.IndividualRecipient = new IndividualRecipient()
161+
{
162+
FirstName = "Payout",
163+
LastName = "Team",
164+
Address = new Address
165+
{
166+
AddressLine1 = "Address line 1",
167+
AddressLine2 = "Address line 2",
168+
City = "Paris",
169+
Country = CountryIso.FR,
170+
PostalCode = "11222",
171+
Region = "Paris"
172+
}
173+
};
174+
postDto.LocalBankTransfer = localBankTransfer;
175+
176+
return postDto;
177+
}
178+
}
179+
}

MangoPay.SDK.Tests/ApiTransfersTest.cs

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
using MangoPay.SDK.Core.Enumerations;
2-
using MangoPay.SDK.Entities.GET;
1+
using System.Threading.Tasks;
2+
using MangoPay.SDK.Core.Enumerations;
33
using NUnit.Framework;
4-
using System.Threading.Tasks;
54

65
namespace MangoPay.SDK.Tests
76
{
@@ -22,6 +21,29 @@ public async Task Test_Transfers_Create()
2221
Assert.AreEqual(transfer.CreditedUserId, john.Id);
2322
Assert.AreEqual(100, creditedWallet.Balance.Amount);
2423
}
24+
25+
[Test]
26+
public async Task Test_Transfers_CreateSca()
27+
{
28+
string validUserNaturalScaId = "user_m_01JRFJJN9BR864A4KG7MH1WCZG";
29+
string validUserLegalScaId = "user_m_01JRG4ZWZ85RNZDKKTSFRMG6ZW";
30+
var debitedWallet = await GetNewJohnsWalletWithMoney(10000, validUserNaturalScaId);
31+
var transferUserPresent = await this.GetNewTransferSca(debitedWallet.Id, validUserNaturalScaId, validUserLegalScaId,
32+
3001, "USER_PRESENT");
33+
var transferUserPresentLowAmount = await this.GetNewTransferSca(debitedWallet.Id, validUserNaturalScaId, validUserLegalScaId,
34+
20, "USER_PRESENT");
35+
var transferUserNotPresent = await this.GetNewTransferSca(debitedWallet.Id, validUserNaturalScaId, validUserLegalScaId,
36+
3001, "USER_NOT_PRESENT");
37+
38+
Assert.AreEqual(TransactionStatus.CREATED, transferUserPresent.Status);
39+
Assert.IsNotNull(transferUserPresent.PendingUserAction);
40+
41+
Assert.AreEqual(TransactionStatus.SUCCEEDED, transferUserPresentLowAmount.Status);
42+
Assert.IsNull(transferUserPresentLowAmount.PendingUserAction);
43+
44+
Assert.AreEqual(TransactionStatus.SUCCEEDED, transferUserNotPresent.Status);
45+
Assert.IsNull(transferUserNotPresent.PendingUserAction);
46+
}
2547

2648
[Test]
2749
public async Task Test_Transfers_Get()

MangoPay.SDK.Tests/ApiUsersTest.cs

+87
Original file line numberDiff line numberDiff line change
@@ -1390,5 +1390,92 @@ public async Task TestLegallUserPayerFails()
13901390
Assert.IsTrue(e.Message.Contains("The CompanyNumber field is required"), e.Message);
13911391
}
13921392
}
1393+
1394+
[Test]
1395+
public async Task Test_Users_CloseNatural()
1396+
{
1397+
try
1398+
{
1399+
var user = new UserNaturalOwnerPostDTO
1400+
{
1401+
Email = "john.doe@sample.org",
1402+
FirstName = "John",
1403+
LastName = "Doe",
1404+
Birthday = new DateTime(1975, 12, 21, 0, 0, 0),
1405+
Nationality = CountryIso.FR,
1406+
CountryOfResidence = CountryIso.FR,
1407+
Occupation = "programmer",
1408+
IncomeRange = 3,
1409+
Address = new Address
1410+
{
1411+
AddressLine1 = "Address line 1", AddressLine2 = "Address line 2", City = "City",
1412+
Country = CountryIso.PL, PostalCode = "11222", Region = "Region"
1413+
}
1414+
};
1415+
1416+
var john = await this.Api.Users.CreateOwnerAsync(user);
1417+
await Api.Users.CloseNaturalAsync(john.Id);
1418+
var closed = await Api.Users.GetAsync(john.Id);
1419+
1420+
Assert.IsTrue(john.UserStatus == UserStatus.ACTIVE);
1421+
Assert.IsTrue(closed.UserStatus == UserStatus.CLOSED);
1422+
}
1423+
catch (Exception ex)
1424+
{
1425+
Assert.Fail(ex.Message);
1426+
}
1427+
}
1428+
1429+
[Test]
1430+
public async Task Test_Users_CloseLegal()
1431+
{
1432+
try
1433+
{
1434+
var user = new UserLegalOwnerPostDTO
1435+
{
1436+
Name = "MartixSampleOrg",
1437+
LegalPersonType = LegalPersonType.BUSINESS,
1438+
UserCategory = UserCategory.OWNER,
1439+
TermsAndConditionsAccepted = true,
1440+
LegalRepresentativeFirstName = "JohnUbo",
1441+
LegalRepresentativeLastName = "DoeUbo",
1442+
LegalRepresentativeCountryOfResidence = CountryIso.PL,
1443+
LegalRepresentativeNationality = CountryIso.PL,
1444+
HeadquartersAddress = new Address
1445+
{
1446+
AddressLine1 = "Address line ubo 1",
1447+
AddressLine2 = "Address line ubo 2",
1448+
City = "CityUbo",
1449+
Country = CountryIso.PL,
1450+
PostalCode = "11222",
1451+
Region = "RegionUbo"
1452+
},
1453+
LegalRepresentativeAddress = new Address
1454+
{
1455+
AddressLine1 = "Address line ubo 1",
1456+
AddressLine2 = "Address line ubo 2",
1457+
City = "CityUbo",
1458+
Country = CountryIso.PL,
1459+
PostalCode = "11222",
1460+
Region = "RegionUbo"
1461+
},
1462+
LegalRepresentativeEmail = "john.doe@sample.org",
1463+
LegalRepresentativeBirthday = new DateTime(1975, 12, 21, 0, 0, 0),
1464+
Email = "john.doe@sample.org",
1465+
CompanyNumber = "LU72HN11"
1466+
};
1467+
1468+
var matrix = await this.Api.Users.CreateOwnerAsync(user);
1469+
await Api.Users.CloseLegalAsync(matrix.Id);
1470+
var closed = await Api.Users.GetAsync(matrix.Id);
1471+
1472+
Assert.IsTrue(matrix.UserStatus == UserStatus.ACTIVE);
1473+
Assert.IsTrue(closed.UserStatus == UserStatus.CLOSED);
1474+
}
1475+
catch (Exception ex)
1476+
{
1477+
Assert.Fail(ex.Message);
1478+
}
1479+
}
13931480
}
13941481
}

MangoPay.SDK.Tests/BaseTest.cs

+36-22
Original file line numberDiff line numberDiff line change
@@ -402,39 +402,39 @@ protected async Task<WalletDTO> GetJohnsWalletWithMoney(int amount)
402402
protected async Task<WalletDTO> GetNewJohnsWalletWithMoney(int amount, UserNaturalDTO user = null)
403403
{
404404
var john = user ?? await this.GetJohn();
405+
return await GetNewJohnsWalletWithMoney(amount, john.Id);
406+
}
407+
408+
protected async Task<WalletDTO> GetNewJohnsWalletWithMoney(int amount, string userId)
409+
{
410+
var walletPost = new WalletPostDTO(new List<string> { userId }, "WALLET IN EUR WITH MONEY", CurrencyIso.EUR);
411+
var wallet = await this.Api.Wallets.CreateAsync(walletPost);
412+
var cardRegistration = await createNewCardRegistration(userId);
413+
await createNewPayInCardDirect(userId, wallet.Id, cardRegistration.CardId, amount);
414+
return await this.Api.Wallets.GetAsync(wallet.Id);
415+
}
405416

406-
// create wallet with money
407-
var wallet = new WalletPostDTO(new List<string> { john.Id }, "WALLET IN EUR WITH MONEY", CurrencyIso.EUR);
408-
409-
var johnsWalletWithMoney = await this.Api.Wallets.CreateAsync(wallet);
410-
411-
var cardRegistrationPost = new CardRegistrationPostDTO(johnsWalletWithMoney.Owners[0], CurrencyIso.EUR);
417+
protected async Task<CardRegistrationDTO> createNewCardRegistration(string userId)
418+
{
419+
var cardRegistrationPost = new CardRegistrationPostDTO(userId, CurrencyIso.EUR);
412420
var cardRegistration = await this.Api.CardRegistrations.CreateAsync(cardRegistrationPost);
413421

414422
var cardRegistrationPut = new CardRegistrationPutDTO
415423
{
416-
RegistrationData = await this.GetPaylineCorrectRegistartionData(cardRegistration)
424+
RegistrationData = await GetPaylineCorrectRegistartionData(cardRegistration)
417425
};
418-
cardRegistration = await this.Api.CardRegistrations.UpdateAsync(cardRegistrationPut, cardRegistration.Id);
419-
420-
var card = await this.Api.Cards.GetAsync(cardRegistration.CardId);
426+
return await Api.CardRegistrations.UpdateAsync(cardRegistrationPut, cardRegistration.Id);
427+
}
421428

422-
// create pay-in CARD DIRECT
423-
var payIn = new PayInCardDirectPostDTO(cardRegistration.UserId, cardRegistration.UserId,
429+
protected async Task createNewPayInCardDirect(string userId, string walletId, string cardId, int amount)
430+
{
431+
var payIn = new PayInCardDirectPostDTO(userId, userId,
424432
new Money { Amount = amount, Currency = CurrencyIso.EUR },
425433
new Money { Amount = 0, Currency = CurrencyIso.EUR },
426-
johnsWalletWithMoney.Id, "http://test.com", card.Id)
427-
{
428-
CardType = card.CardType
429-
};
430-
434+
walletId, "http://test.com", cardId);
431435
payIn.BrowserInfo = getBrowserInfo();
432436
payIn.IpAddress = "2001:0620:0000:0000:0211:24FF:FE80:C12C";
433-
434-
// create Pay-In
435-
var result = await this.Api.PayIns.CreateCardDirectAsync(payIn);
436-
437-
return await this.Api.Wallets.GetAsync(johnsWalletWithMoney.Id);
437+
await Api.PayIns.CreateCardDirectAsync(payIn);
438438
}
439439

440440
protected async Task<Tuple<string, WalletDTO>> GetNewJohnsWalletWithMoneyAndCardId(int amount,
@@ -1217,6 +1217,20 @@ protected async Task<TransferDTO> GetNewTransfer(WalletDTO walletIn = null)
12171217
return await this.Api.Transfers.CreateAsync(transfer);
12181218
}
12191219

1220+
protected async Task<TransferDTO> GetNewTransferSca(string debitedWalletId, string userId, string creditedUserId, int amount,
1221+
string scaContext)
1222+
{
1223+
var walletPost = new WalletPostDTO(new List<string> { creditedUserId }, "WALLET IN EUR FOR TRANSFER",
1224+
CurrencyIso.EUR);
1225+
var creditedWallet = await this.Api.Wallets.CreateAsync(walletPost);
1226+
var transfer = new TransferPostDTO(userId, creditedUserId, new Money { Amount = amount, Currency = CurrencyIso.EUR },
1227+
new Money { Amount = 0, Currency = CurrencyIso.EUR }, debitedWalletId, creditedWallet.Id)
1228+
{
1229+
ScaContext = scaContext
1230+
};
1231+
return await Api.Transfers.CreateAsync(transfer);
1232+
}
1233+
12201234
/// <summary>Creates refund object for transfer.</summary>
12211235
/// <param name="transfer">Transfer.</param>
12221236
/// <returns>Refund instance returned from API.</returns>

0 commit comments

Comments
 (0)