Skip to content

Commit a9d676b

Browse files
iulian03Iulian Masar
and
Iulian Masar
authored
[feature] SCA users (#249)
* handle creation of SCA users * support for fetching SCA users * support for updating SCA users * handle categorize of SCA users * add support for enrolling into SCA * small fixes --------- Co-authored-by: Iulian Masar <[email protected]>
1 parent 10546ad commit a9d676b

20 files changed

+1327
-73
lines changed

MangoPay.SDK.Tests/ApiUsersTest.cs

+272-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
using MangoPay.SDK.Core;
1+
using System;
2+
using System.IO;
3+
using System.Reflection;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using MangoPay.SDK.Core;
27
using MangoPay.SDK.Core.Enumerations;
38
using MangoPay.SDK.Entities;
49
using MangoPay.SDK.Entities.GET;
510
using MangoPay.SDK.Entities.POST;
611
using MangoPay.SDK.Entities.PUT;
712
using NUnit.Framework;
8-
using System;
9-
using System.Linq;
10-
using System.Collections.Generic;
11-
using System.IO;
12-
using System.Reflection;
13-
using System.Text;
14-
using System.Threading;
15-
using System.Threading.Tasks;
1613

1714
namespace MangoPay.SDK.Tests
1815
{
@@ -33,6 +30,138 @@ public async Task Test_Users_CreateNatural()
3330
Assert.Fail(ex.Message);
3431
}
3532
}
33+
34+
[Test]
35+
public async Task Test_Users_EnrollIntoSca()
36+
{
37+
try
38+
{
39+
var john = await this.GetJohn();
40+
var enrollmentResult = await Api.Users.EnrollSca(john.Id);
41+
42+
Assert.IsNotNull(enrollmentResult.PendingUserAction.RedirectUrl);
43+
}
44+
catch (Exception ex)
45+
{
46+
Assert.Fail(ex.Message);
47+
}
48+
}
49+
50+
[Test]
51+
public async Task Test_Users_CreateNaturalScaPayer()
52+
{
53+
try
54+
{
55+
var john = await GetJohnScaPayer();
56+
Assert.IsTrue(john.Id.Length > 0);
57+
Assert.IsTrue(john.PersonType == PersonType.NATURAL);
58+
Assert.IsTrue(john.UserCategory == UserCategory.PAYER);
59+
Assert.IsTrue(john.UserStatus == UserStatus.ACTIVE);
60+
Assert.IsNotNull(john.PhoneNumber);
61+
Assert.IsNotNull(john.PhoneNumberCountry);
62+
}
63+
catch (Exception ex)
64+
{
65+
Assert.Fail(ex.Message);
66+
}
67+
}
68+
69+
[Test]
70+
public async Task Test_Users_CreateNaturalScaOwner()
71+
{
72+
try
73+
{
74+
var john = await GetJohnScaOwner();
75+
Assert.IsTrue(john.Id.Length > 0);
76+
Assert.IsTrue(john.PersonType == PersonType.NATURAL);
77+
Assert.IsTrue(john.UserCategory == UserCategory.OWNER);
78+
Assert.IsTrue(john.UserStatus == UserStatus.PENDING_USER_ACTION);
79+
Assert.IsNotNull(john.PhoneNumber);
80+
Assert.IsNotNull(john.PhoneNumberCountry);
81+
Assert.IsNotNull(john.PendingUserAction.RedirectUrl);
82+
}
83+
catch (Exception ex)
84+
{
85+
Assert.Fail(ex.Message);
86+
}
87+
}
88+
89+
[Test]
90+
public async Task Test_Users_CategorizeNaturalScaPayer()
91+
{
92+
try
93+
{
94+
var john = await GetJohnScaPayer();
95+
var categorize = new CategorizeUserNaturalPutDTO
96+
{
97+
TermsAndConditionsAccepted = true,
98+
UserCategory = UserCategory.OWNER,
99+
Email = "[email protected]",
100+
PhoneNumber = "+33611111111",
101+
PhoneNumberCountry = CountryIso.FR,
102+
Birthday = new DateTime(1975, 12, 21, 0, 0, 0),
103+
Nationality = CountryIso.FR,
104+
CountryOfResidence = CountryIso.FR,
105+
};
106+
107+
var response = await Api.Users.CategorizeNaturalAsync(categorize, john.Id);
108+
109+
Assert.IsTrue(response.Id.Length > 0);
110+
Assert.IsTrue(response.PersonType == PersonType.NATURAL);
111+
Assert.IsTrue(john.UserCategory == UserCategory.PAYER);
112+
Assert.IsTrue(response.UserCategory == UserCategory.OWNER);
113+
}
114+
catch (Exception ex)
115+
{
116+
Assert.Fail(ex.Message);
117+
}
118+
}
119+
120+
[Test]
121+
public async Task Test_Users_CategorizeLegalScaPayer()
122+
{
123+
try
124+
{
125+
var matrix = await GetMatrixScaPayer();
126+
var categorize = new CategorizeUserLegalPutDTO()
127+
{
128+
TermsAndConditionsAccepted = true,
129+
UserCategory = UserCategory.OWNER,
130+
LegalRepresentative = new LegalRepresentative()
131+
{
132+
Email = "[email protected]",
133+
FirstName = "John SCA",
134+
LastName = "Doe SCA Review",
135+
PhoneNumber = "+33611111111",
136+
PhoneNumberCountry = CountryIso.FR,
137+
Birthday = new DateTime(1975, 12, 21, 0, 0, 0),
138+
Nationality = CountryIso.FR,
139+
CountryOfResidence = CountryIso.FR
140+
},
141+
HeadquartersAddress = new Address
142+
{
143+
AddressLine1 = "Address line ubo 1",
144+
AddressLine2 = "Address line ubo 2",
145+
City = "CityUbo",
146+
Country = CountryIso.PL,
147+
PostalCode = "11222",
148+
Region = "RegionUbo"
149+
},
150+
CompanyNumber = "LU72HN11"
151+
};
152+
153+
var response = await Api.Users.CategorizeLegalAsync(categorize, matrix.Id);
154+
155+
Assert.IsTrue(response.Id.Length > 0);
156+
Assert.IsTrue(response.PersonType == PersonType.LEGAL);
157+
Assert.IsTrue(matrix.UserCategory == UserCategory.PAYER);
158+
Assert.IsTrue(response.UserCategory == UserCategory.OWNER);
159+
}
160+
catch (Exception ex)
161+
{
162+
Assert.Fail(ex.Message);
163+
}
164+
}
36165

37166
[Test]
38167
public async Task Test_Users_CreateLegal()
@@ -48,6 +177,45 @@ public async Task Test_Users_CreateLegal()
48177
Assert.Fail(ex.Message);
49178
}
50179
}
180+
181+
[Test]
182+
public async Task Test_Users_CreateLegalScaPayer()
183+
{
184+
try
185+
{
186+
var matrix = await this.GetMatrixScaPayer();
187+
Assert.IsTrue(matrix.Id.Length > 0);
188+
Assert.IsTrue(matrix.PersonType == PersonType.LEGAL);
189+
Assert.IsTrue(matrix.UserCategory == UserCategory.PAYER);
190+
Assert.IsTrue(matrix.UserStatus == UserStatus.ACTIVE);
191+
Assert.IsNotNull(matrix.LegalRepresentative);
192+
}
193+
catch (Exception ex)
194+
{
195+
Assert.Fail(ex.Message);
196+
}
197+
}
198+
199+
[Test]
200+
public async Task Test_Users_CreateLegalScaOwner()
201+
{
202+
try
203+
{
204+
var matrix = await this.GetMatrixScaOwner();
205+
Assert.IsTrue(matrix.Id.Length > 0);
206+
Assert.IsTrue(matrix.PersonType == PersonType.LEGAL);
207+
Assert.IsTrue(matrix.UserCategory == UserCategory.OWNER);
208+
Assert.IsTrue(matrix.UserStatus == UserStatus.PENDING_USER_ACTION);
209+
Assert.IsNotNull(matrix.LegalRepresentative);
210+
Assert.IsNotNull(matrix.HeadquartersAddress);
211+
Assert.IsNotNull(matrix.CompanyNumber);
212+
Assert.IsNotNull(matrix.PendingUserAction.RedirectUrl);
213+
}
214+
catch (Exception ex)
215+
{
216+
Assert.Fail(ex.Message);
217+
}
218+
}
51219

52220
[Test]
53221
public async Task Test_Users_CreateLegal_PassesIfRequiredPropsProvided()
@@ -98,6 +266,38 @@ public async Task Test_Users_GetNatural()
98266
Assert.Fail(ex.Message);
99267
}
100268
}
269+
270+
[Test]
271+
public async Task Test_Users_GetNaturalSca()
272+
{
273+
var john = await this.GetJohnScaOwner();
274+
var userNatural = await this.Api.Users.GetNaturalScaAsync(john.Id);
275+
var userNatural2 = await this.Api.Users.GetScaAsync(john.Id);
276+
277+
Assert.IsTrue(userNatural.PersonType == PersonType.NATURAL);
278+
Assert.IsTrue(userNatural.Id == john.Id);
279+
Assert.IsTrue(userNatural2.Id == john.Id);
280+
281+
Assert.IsTrue(userNatural.Email == userNatural2.Email);
282+
Assert.IsTrue(userNatural.Tag == userNatural2.Tag);
283+
Assert.IsTrue(userNatural.CreationDate == userNatural2.CreationDate);
284+
}
285+
286+
[Test]
287+
public async Task Test_Users_GetLegalSca()
288+
{
289+
var matrix = await this.GetMatrixScaOwner();
290+
var userLegal = await this.Api.Users.GetLegalScaAsync(matrix.Id);
291+
var userLegal2 = await this.Api.Users.GetScaAsync(matrix.Id);
292+
293+
Assert.IsTrue(userLegal.PersonType == PersonType.LEGAL);
294+
Assert.IsTrue(userLegal.Id == matrix.Id);
295+
Assert.IsTrue(userLegal2.Id == matrix.Id);
296+
297+
Assert.IsTrue(userLegal.Email == userLegal2.Email);
298+
Assert.IsTrue(userLegal.Tag == userLegal2.Tag);
299+
Assert.IsTrue(userLegal.CreationDate == userLegal2.CreationDate);
300+
}
101301

102302
[Test]
103303
public async Task Test_Users_GetNatural_FailsForLegalUser()
@@ -228,6 +428,69 @@ public async Task Test_Users_Save_Natural()
228428
Assert.Fail(ex.Message);
229429
}
230430
}
431+
432+
[Test]
433+
public async Task Test_Users_Save_NaturalSca()
434+
{
435+
try
436+
{
437+
var john = await GetJohnScaOwner();
438+
439+
var johnPut = new UserNaturalScaPutDTO
440+
{
441+
LastName = john.LastName + " - CHANGED",
442+
Nationality = CountryIso.DK,
443+
TermsAndConditionsAccepted = true
444+
};
445+
446+
var userSaved = await Api.Users.UpdateNaturalAsync(johnPut, john.Id);
447+
var userFetched = await Api.Users.GetNaturalScaAsync(john.Id);
448+
449+
Assert.AreEqual(johnPut.LastName, userSaved.LastName);
450+
Assert.AreEqual(johnPut.LastName, userFetched.LastName);
451+
}
452+
catch (Exception ex)
453+
{
454+
Assert.Fail(ex.Message);
455+
}
456+
}
457+
458+
[Test]
459+
public async Task Test_Users_Save_LegalSca()
460+
{
461+
try
462+
{
463+
var matrix = await GetMatrixScaOwner();
464+
465+
var matrixPut = new UserLegalScaPutDTO()
466+
{
467+
Name = matrix.Name + " - CHANGED",
468+
LegalPersonType = LegalPersonType.SOLETRADER,
469+
TermsAndConditionsAccepted = true,
470+
LegalRepresentative = new LegalRepresentative()
471+
{
472+
Email = "[email protected]",
473+
FirstName = "John SCA",
474+
LastName = "Doe SCA Review",
475+
PhoneNumber = "+33611111111",
476+
PhoneNumberCountry = CountryIso.FR,
477+
Birthday = new DateTime(1975, 12, 21, 0, 0, 0),
478+
Nationality = CountryIso.FR,
479+
CountryOfResidence = CountryIso.FR
480+
}
481+
};
482+
483+
var userSaved = await Api.Users.UpdateLegalAsync(matrixPut, matrix.Id);
484+
var userFetched = await Api.Users.GetLegalScaAsync(matrix.Id);
485+
486+
Assert.AreEqual(matrixPut.Name, userSaved.Name);
487+
Assert.AreEqual(matrixPut.Name, userFetched.Name);
488+
}
489+
catch (Exception ex)
490+
{
491+
Assert.Fail(ex.Message);
492+
}
493+
}
231494

232495
[Test]
233496
public async Task Test_Users_Save_Natural_NonASCII()

0 commit comments

Comments
 (0)