-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] identity verification (#244)
* added support for creating and fetching IdentityVerifications * support fetching identity verification checks and added missing event types --------- Co-authored-by: Iulian Masar <[email protected]>
- Loading branch information
Showing
11 changed files
with
247 additions
and
6 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,65 @@ | ||
using System.Threading.Tasks; | ||
using MangoPay.SDK.Entities.GET; | ||
using MangoPay.SDK.Entities.POST; | ||
using NUnit.Framework; | ||
|
||
namespace MangoPay.SDK.Tests | ||
{ | ||
[TestFixture] | ||
[Explicit] | ||
public class ApiIdentityVerifications : BaseTest | ||
{ | ||
private static IdentityVerificationDTO _identityVerification; | ||
|
||
[Test] | ||
public async Task Test_CreateIdentityVerification() | ||
{ | ||
await GetNewIdentityVerification(); | ||
|
||
Assert.IsNotNull(_identityVerification); | ||
Assert.IsNotNull(_identityVerification.ReturnUrl); | ||
Assert.IsNotNull(_identityVerification.HostedUrl); | ||
Assert.IsNotNull(_identityVerification.Status); | ||
} | ||
|
||
[Test] | ||
public async Task Test_GetIdentityVerification() | ||
{ | ||
await GetNewIdentityVerification(); | ||
IdentityVerificationDTO fetched = await Api.IdentityVerifications.GetAsync(_identityVerification.Id); | ||
|
||
Assert.IsNotNull(fetched); | ||
Assert.AreEqual(_identityVerification.HostedUrl, fetched.HostedUrl); | ||
Assert.AreEqual(_identityVerification.ReturnUrl, fetched.ReturnUrl); | ||
Assert.AreEqual(_identityVerification.Status, fetched.Status); | ||
} | ||
|
||
[Test] | ||
public async Task Test_GetIdentityVerificationChecks() | ||
{ | ||
await GetNewIdentityVerification(); | ||
IdentityVerificationCheckDTO check = | ||
await Api.IdentityVerifications.GetChecksAsync(_identityVerification.Id); | ||
|
||
Assert.IsNotNull(check); | ||
Assert.IsNotNull(check.SessionId); | ||
Assert.IsNotNull(check.Status); | ||
Assert.IsNotNull(check.LastUpdate); | ||
Assert.IsNotNull(check.CreationDate); | ||
Assert.IsNotNull(check.Checks); | ||
} | ||
|
||
private async Task GetNewIdentityVerification() | ||
{ | ||
if (_identityVerification == null) | ||
{ | ||
UserNaturalDTO john = await GetJohn(); | ||
IdentityVerificationPostDto postDto = new IdentityVerificationPostDto(); | ||
postDto.ReturnUrl = "https://example.com"; | ||
postDto.Tag = "Created by the .NET SDK"; | ||
|
||
_identityVerification = await Api.IdentityVerifications.CreateAsync(postDto, john.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Threading.Tasks; | ||
using MangoPay.SDK.Core.Enumerations; | ||
using MangoPay.SDK.Entities.GET; | ||
using MangoPay.SDK.Entities.POST; | ||
|
||
namespace MangoPay.SDK.Core.APIs | ||
{ | ||
/// <summary>API for identity verification.</summary> | ||
public class ApiIdentityVerifications : ApiBase | ||
{ | ||
/// <summary>Instantiates new ApiIdentityVerification object.</summary> | ||
/// <param name="root">Root/parent instance that holds the OAuthToken and Configuration instance.</param> | ||
public ApiIdentityVerifications(MangoPayApi root) : base(root) | ||
{ | ||
} | ||
|
||
/// <summary>Creates new identity verification.</summary> | ||
/// <param name="idempotentKey">Idempotent key for this request.</param> | ||
/// <param name="identityVerification">Object instance to be created.</param> | ||
/// <param name="userId">The user identifier.</param> | ||
/// <returns>Object instance returned from API.</returns> | ||
public async Task<IdentityVerificationDTO> CreateAsync(IdentityVerificationPostDto identityVerification, | ||
string userId, string idempotentKey = null) | ||
{ | ||
return await CreateObjectAsync<IdentityVerificationDTO, IdentityVerificationPostDto>( | ||
MethodKey.IdentityVerificationCreate, identityVerification, | ||
idempotentKey, userId); | ||
} | ||
|
||
/// <summary>See the status and basic details of an identity verification session</summary> | ||
/// <param name="id">Identity verification identitifer.</param> | ||
/// <returns>Object instance returned from API.</returns> | ||
public async Task<IdentityVerificationDTO> GetAsync(string id) | ||
{ | ||
return await this.GetObjectAsync<IdentityVerificationDTO>(MethodKey.IdentityVerificationGet, | ||
entitiesId: id); | ||
} | ||
|
||
/// <summary>Obtain verified user data and results of each check performed</summary> | ||
/// <param name="id">Identity verification identitifer.</param> | ||
/// <returns>Object instance returned from API.</returns> | ||
public async Task<IdentityVerificationCheckDTO> GetChecksAsync(string id) | ||
{ | ||
return await this.GetObjectAsync<IdentityVerificationCheckDTO>(MethodKey.IdentityVerificationGetChecks, | ||
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,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using MangoPay.SDK.Core; | ||
using Newtonsoft.Json; | ||
|
||
namespace MangoPay.SDK.Entities.GET | ||
{ | ||
public class CheckDTO | ||
{ | ||
/// <summary>The unique identifier of the verification check.</summary> | ||
public string CheckId { get; set; } | ||
|
||
/// <summary> | ||
/// Type of verification check performed: | ||
/// <para>BUSINESS_VERIFICATION - Verification of the business entity of a Legal User.</para> | ||
/// <para>IDENTITY_DOCUMENT_VERIFICATION - Verification of the identity document of a Natural User or the legal representative of a Legal User.</para> | ||
/// <para>PERSONS_SIGNIFICANT_CONTROL - Verification of a person of significant control of a Legal User.</para> | ||
/// </summary> | ||
public string Type { get; set; } | ||
|
||
/// <summary>Returned values: VALIDATED, REFUSED, REVIEW</summary> | ||
public string CheckStatus { get; set; } | ||
|
||
/// <summary>The date and time at which the check was created.</summary> | ||
[JsonConverter(typeof(UnixDateTimeConverter))] | ||
public DateTime CreationDate { get; set; } | ||
|
||
/// <summary>The date and time at which the check was last updated.</summary> | ||
[JsonConverter(typeof(UnixDateTimeConverter))] | ||
public DateTime LastUpdate { get; set; } | ||
|
||
/// <summary> | ||
/// The data points collected and verified during the check. | ||
/// </summary> | ||
public List<CheckDataDTO> Data { 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,11 @@ | ||
namespace MangoPay.SDK.Entities.GET | ||
{ | ||
public class CheckDataDTO | ||
{ | ||
/// <summary>The type of the data point.</summary> | ||
public string Type { get; set; } | ||
|
||
/// <summary>The value of the data point.</summary> | ||
public string Value { 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,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using MangoPay.SDK.Core; | ||
using Newtonsoft.Json; | ||
|
||
namespace MangoPay.SDK.Entities.GET | ||
{ | ||
public class IdentityVerificationCheckDTO : EntityBase | ||
{ | ||
/// <summary>Unique identifier for the entire verification session.</summary> | ||
public string SessionId { get; set; } | ||
|
||
/// <summary> | ||
/// The status of the identity verification session: | ||
/// <para>PENDING – The session is available on the HostedUrl, to which the user must be redirected to complete it.</para> | ||
/// <para>VALIDATED – The session was successful.</para> | ||
/// <para>REFUSED – The session was refused.</para> | ||
/// <para>REVIEW – The session is under manual review by Mangopay.</para> | ||
/// <para>OUTDATED – The session is no longer valid (likely due to expired documents used during the session).</para> | ||
/// <para>TIMEOUT – The session timed out due to inactivity.</para> | ||
/// <para>ERROR – The session was not completed because an error occurred.</para> | ||
/// </summary> | ||
public string Status { get; set; } | ||
|
||
/// <summary>The date and time at which the session was last updated.</summary> | ||
[JsonConverter(typeof(UnixDateTimeConverter))] | ||
public DateTime LastUpdate { get; set; } | ||
|
||
/// <summary> | ||
/// The details of the individual verification checks performed during the session. | ||
/// </summary> | ||
public List<CheckDTO> Checks { 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,23 @@ | ||
namespace MangoPay.SDK.Entities.GET | ||
{ | ||
public class IdentityVerificationDTO : EntityBase | ||
{ | ||
/// <summary>The URL to which the user is returned after the hosted identity verification session, regardless of the outcome.</summary> | ||
public string ReturnUrl { get; set; } | ||
|
||
/// <summary>The URL to redirect the user to for the hosted identity verification session.</summary> | ||
public string HostedUrl { get; set; } | ||
|
||
/// <summary> | ||
/// The status of the identity verification session: | ||
/// <para>PENDING – The session is available on the HostedUrl, to which the user must be redirected to complete it.</para> | ||
/// <para>VALIDATED – The session was successful.</para> | ||
/// <para>REFUSED – The session was refused.</para> | ||
/// <para>REVIEW – The session is under manual review by Mangopay.</para> | ||
/// <para>OUTDATED – The session is no longer valid (likely due to expired documents used during the session).</para> | ||
/// <para>TIMEOUT – The session timed out due to inactivity.</para> | ||
/// <para>ERROR – The session was not completed because an error occurred.</para> | ||
/// </summary> | ||
public string Status { 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,8 @@ | ||
namespace MangoPay.SDK.Entities.POST | ||
{ | ||
public class IdentityVerificationPostDto : EntityPostBase | ||
{ | ||
/// <summary>The URL to which the user is returned after the hosted identity verification session, regardless of the outcome.</summary> | ||
public string ReturnUrl { 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