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

feat: Update Accounts Module and Integration Tests #451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public class OnboardEntityRequest

public ProcessingDetails ProcessingDetails { get; set; }

public bool Draft { get; set; }
public bool IsDraft { get; set; }
public bool? Draft { get; set; }

public bool? IsDraft { get; set; }

public Individual Individual { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Checkout.Accounts.Entities.Request
{
public class OnboardSubEntityRequest
{
[JsonExtensionData]
public IDictionary<string, object> Request { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ namespace Checkout.Accounts.Entities.Response
{
public enum OnboardingStatus
{
[EnumMember(Value = "draft")]
Draft,

[EnumMember(Value = "active")]
Active,

Expand Down
10 changes: 5 additions & 5 deletions test/CheckoutSdkTest/Accounts/AccountsClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ private async Task ShouldReinviteSubEntityMember()
{
Response = new Dictionary<string, object>
{
{ "custom_field_1", "value_1" },
{ "custom_field_2", 12345 }
{ "Id", "sub_entity_id" },
{ "custom_field_1", 12345 }
}
};

Expand All @@ -100,10 +100,10 @@ private async Task ShouldReinviteSubEntityMember()

response.ShouldNotBeNull();
response.Response.ShouldNotBeNull();
response.Response.ContainsKey("Id").ShouldBeTrue();
response.Response["Id"].ShouldBe("sub_entity_id");
response.Response.ContainsKey("custom_field_1").ShouldBeTrue();
response.Response["custom_field_1"].ShouldBe("value_1");
response.Response.ContainsKey("custom_field_2").ShouldBeTrue();
response.Response["custom_field_2"].ShouldBe(12345);
response.Response["custom_field_1"].ShouldBe(12345);
}

[Fact]
Expand Down
175 changes: 125 additions & 50 deletions test/CheckoutSdkTest/Accounts/AccountsIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,29 @@
using Checkout.Common;
using Checkout.Instruments;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mime;
using System.Reflection.Metadata;
using System.Threading.Tasks;
using Xunit;

namespace Checkout.Accounts
{
public class AccountsIntegrationTest : SandboxTestFixture
{
private static readonly Random Random = new Random();

public AccountsIntegrationTest() : base(PlatformType.DefaultOAuth)
{
}

[Fact(Skip = "beta")]
[Fact]
public async Task ShouldCreateHostedOnboardingInvitationRequest()
{
string randomReference = RandomString(15);
var entityRequest = new OnboardEntityRequest
{
Reference = randomReference,
IsDraft = false,
ContactDetails = new ContactDetails { Invitee = new Invitee { Email = "admin@superhero1234.com" } }
IsDraft = true,
ContactDetails = new ContactDetails { Invitee = new Invitee { Email = GenerateRandomEmail() } }
};

var response = await DefaultApi.AccountsClient().CreateEntity(entityRequest);
Expand All @@ -44,62 +39,149 @@ public async Task ShouldCreateHostedOnboardingInvitationRequest()
}

[Fact]
public async Task ShouldCreateCompany()
public async Task ShouldCreateCompanyV2()
{
string randomReference = RandomString(15);
var entityRequest = new OnboardEntityRequest
var request = new OnboardEntityRequest
{
Reference = randomReference,
Draft = true,
Profile =
new Profile
{
Urls = new List<string> { "http://example.com" },
Mccs = new List<string> { "4814" },
HoldingCurrencies = new List<Currency> { Currency.GBP }
},
ContactDetails =
new ContactDetails
Company =
new Company
{
Phone = new Phone { CountryCode = "GI", Number = "656453654" },
EmailAddresses = new EmailAddresses { Primary = null },
Invitee = new Invitee { Email = null }
LegalName = "Company " + RandomString(3),
TradingName = "Trading " + RandomString(3),
PrincipalAddress = GetAddress(),
RegisteredAddress = GetAddress(),
Representatives =
new List<Representative>
{
new Representative
{
FirstName = RandomString(5),
LastName = RandomString(5),
Address = GetAddress(),
Roles = new List<EntityRoles> { EntityRoles.Ubo },
DateOfBirth = new DateOfBirth { Day = 1, Month = 1, Year = 1980 },
},
},
BusinessRegistrationNumber = RandomBusinessRegistrationNumber(),
DateOfIncorporation = new DateOfIncorporation { Day = 1, Month = 1, Year = 2001 },

},
ContactDetails = new ContactDetails
{
Phone = new Phone { CountryCode = "GB", Number = RandomDigits(9) },
EmailAddresses = new EmailAddresses { Primary = GenerateRandomEmail() },
Invitee = new Invitee { Email = GenerateRandomEmail() }
},
Profile = new Profile
{
Urls = new List<string> { "http://example.com" },
Mccs = new List<string> { "4814" },
DefaultHoldingCurrency = Currency.GBP,
HoldingCurrencies = new List<Currency> { Currency.GBP }
},
IsDraft = true
};

var api = CheckoutSdk.Builder().OAuth()
.ClientCredentials(
System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_OAUTH_CLIENT_ID"),
System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET"))
.Scopes(OAuthScope.Accounts)
.Environment(Environment.Sandbox)
.HttpClientFactory(new CustomClientFactory("2.0"))
.Build();

var response = await api.AccountsClient().CreateEntity(request);

response.ShouldNotBeNull();
response.Id.ShouldNotBeNullOrEmpty();
response.Reference.ShouldBe(randomReference);
}

[Fact]
public async Task ShouldCreateCompanyV3()
{
string randomReference = RandomString(15);
var request = new OnboardEntityRequest
{
Reference = randomReference,
Company =
new Company
{
LegalName = "string",
TradingName = "string",
BusinessRegistrationNumber = "AC123456",
LegalName = "Company " + RandomString(3),
TradingName = "Trading " + RandomString(3),
BusinessRegistrationNumber = RandomBusinessRegistrationNumber(),
DateOfIncorporation = new DateOfIncorporation { Day = 1, Month = 1, Year = 2001 },
PrincipalAddress = GetAddress(),
RegisteredAddress = GetAddress(),
BusinessType = BusinessType.IndividualOrSoleProprietorship
},
ProcessingDetails =
new ProcessingDetails
{
SettlementCountry = "GB",
TargetCountries = new List<string> { "GB" },
Currency = Currency.GBP
Representatives =
new List<Representative>
{
new Representative
{
Company = new Company
{
LegalName = "Company " + RandomString(3),
TradingName = "Trading " + RandomString(3),
RegisteredAddress = GetAddress()
},
OwnershipPercentage = 25,
}
},
BusinessType = BusinessType.LimitedCompany
},
Documents = new Documents
Profile = new Profile
{
Urls = new List<string> { "http://example.com" },
Mccs = new List<string> { "4814" },
DefaultHoldingCurrency = Currency.GBP,
HoldingCurrencies = new List<Currency> { Currency.GBP }
},
ContactDetails = new ContactDetails
{
Phone = new Phone { CountryCode = "GB", Number = RandomDigits(9) },
EmailAddresses = new EmailAddresses { Primary = GenerateRandomEmail() },
Invitee = new Invitee { Email = GenerateRandomEmail() }
},
Documents = new Documents()
{
ArticlesOfAssociation =
new ArticlesOfAssociation()
{
Type = ArticlesOfAssociationType.ArticlesOfAssociation,
Front = "stringstringstringstringstrings"
Front = RandomIdentifier(26, "file_")
},
ShareholderStructure = new ShareholderStructure()
{
Type = ShareholderStructureType.CertifiedShareholderStructure,
Front = "stringstringstringstringstrings"
},
}
ShareholderStructure =
new ShareholderStructure()
{
Type = ShareholderStructureType.CertifiedShareholderStructure,
Front = RandomIdentifier(26, "file_")
},
},
ProcessingDetails = new ProcessingDetails
{
SettlementCountry = "GB",
TargetCountries = new List<string> { "GB" },
AnnualProcessingVolume = 0,
AverageTransactionValue = 0,
HighestTransactionValue = 0,
Currency = Currency.GBP
},
IsDraft = true
};

var response = await DefaultApi.AccountsClient().CreateEntity(entityRequest);
var api = CheckoutSdk.Builder().OAuth()
.ClientCredentials(
System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_OAUTH_CLIENT_ID"),
System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET"))
.Scopes(OAuthScope.Accounts)
.Environment(Environment.Sandbox)
//.HttpClientFactory(new CustomClientFactory("3.0"))
.Build();

var response = await api.AccountsClient().CreateEntity(request);

response.ShouldNotBeNull();
response.Id.ShouldNotBeNullOrEmpty();
Expand Down Expand Up @@ -412,13 +494,6 @@ private async Task ShouldCreateAndRetrievePaymentInstrumentCompany()
queryResponse.Data.ShouldNotBeNull();
}

private static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[Random.Next(s.Length)]).ToArray());
}

private static ContactDetails BuildContactDetails()
{
return new ContactDetails
Expand Down
48 changes: 48 additions & 0 deletions test/CheckoutSdkTest/SandboxTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Shouldly;
using System;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Xunit.Sdk;

Expand All @@ -23,6 +25,7 @@ protected SandboxTestFixture(PlatformType platformType)
{
var logFactory = new NLogLoggerFactory();
_log = logFactory.CreateLogger(typeof(SandboxTestFixture));

switch (platformType)
{
case PlatformType.Previous:
Expand Down Expand Up @@ -59,6 +62,7 @@ protected SandboxTestFixture(PlatformType platformType)
OAuthScope.TransfersView, OAuthScope.BalancesView, OAuthScope.VaultCardMetadata,
OAuthScope.FinancialActions)
.Environment(Environment.Sandbox)
//.HttpClientFactory(new CustomClientFactory("3.0"))
//.EnvironmentSubdomain(System.Environment.GetEnvironmentVariable("CHECKOUT_MERCHANT_SUBDOMAIN"))
.LogProvider(logFactory)
.Build();
Expand All @@ -68,6 +72,50 @@ protected SandboxTestFixture(PlatformType platformType)
throw new ArgumentOutOfRangeException(nameof(platformType), platformType, null);
}
}

protected class CustomClientFactory : IHttpClientFactory
{
private readonly string _schemaVersion;

public CustomClientFactory(string schemaVersion)
{
_schemaVersion = schemaVersion;
}

public HttpClient CreateClient()
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Accept", $"application/json;schema_version={_schemaVersion}");
return httpClient;
}
}

protected static string RandomString(int length, string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
{
var random = new Random();
var sb = new StringBuilder(length);
for (int i = 0; i < length; i++) sb.Append(chars[random.Next(chars.Length)]);
return sb.ToString();
}

protected static string RandomBusinessRegistrationNumber()
{
var random = new Random();
string[] gbPrefixes = { "OC", "LP", "SC", "AC", "CE", "GS" };

return random.Next(2) == 0
? RandomDigits(8)
: gbPrefixes[random.Next(gbPrefixes.Length)] + RandomDigits(6);
}

protected static string RandomIdentifier(int length, string prefix)
{
const string validChars = "abcdefghijklmnopqrstuvwxyz234567";
return prefix + RandomString(length, validChars);
}

protected static string RandomDigits(int length) => RandomString(length, "0123456789");
protected static string RandomAlphanumeric(int length) => RandomString(length, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");

protected static string GenerateRandomEmail()
{
Expand Down
Loading