-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added entityDetailsResponse check * Mods at unit testing for USCompany * Removed line comment * Fixed breaking lines
- Loading branch information
1 parent
af1bea3
commit 808c043
Showing
13 changed files
with
364 additions
and
5 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
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,65 @@ | ||
using Checkout.Accounts.Regional.US; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace Checkout.Accounts.Regional | ||
{ | ||
public class CompanyTypeConverter : JsonConverter | ||
{ | ||
public override bool CanWrite => false; | ||
|
||
public override bool CanConvert(Type objectType) | ||
{ | ||
return typeof(OnboardEntityDetailsResponse).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()); | ||
} | ||
|
||
public override void WriteJson( | ||
JsonWriter writer, | ||
object value, | ||
Newtonsoft.Json.JsonSerializer serializer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override object ReadJson( | ||
JsonReader reader, | ||
Type objectType, | ||
object existingValue, | ||
Newtonsoft.Json.JsonSerializer serializer) | ||
{ | ||
|
||
if (reader.TokenType == JsonToken.Null) | ||
return null; | ||
|
||
var jObject = JToken.Load(reader); | ||
if (jObject.Type == JTokenType.Object) | ||
{ | ||
var businessTypeToken = jObject["company"]?["business_type"]; | ||
if (businessTypeToken != null && businessTypeToken.Type == JTokenType.String ) | ||
{ | ||
var enumString = businessTypeToken.Value<string>(); | ||
|
||
var businessType = CheckoutUtils.GetEnumFromStringMemberValue<BusinessType>(enumString); | ||
if (businessType != null) | ||
{ | ||
var target = new OnboardEntityDetailsResponse(); | ||
serializer.Populate(jObject.CreateReader(), target); | ||
return target; | ||
} | ||
|
||
var usBusinessType = CheckoutUtils.GetEnumFromStringMemberValue<USBusinessType>(enumString); | ||
if (usBusinessType != null) | ||
{ | ||
var target = new OnboardEntityDetailsUSCompanyResponse(); | ||
serializer.Populate(jObject.CreateReader(), target); | ||
return target; | ||
} | ||
} | ||
} | ||
|
||
throw new JsonSerializationException($"Unexpected token or value when parsing enum. Token: {reader.TokenType}, Value: {jObject}"); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/CheckoutSdk/Accounts/Regional/US/OnboardEntityDetailsUSCompanyResponse.cs
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,7 @@ | ||
namespace Checkout.Accounts.Regional.US | ||
{ | ||
public class OnboardEntityDetailsUSCompanyResponse : OnboardEntityDetailsResponse | ||
{ | ||
public new USCompany Company { 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
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
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
69 changes: 69 additions & 0 deletions
69
test/CheckoutSdkTest/Resources/OnBoardSubEntityCompanyResponse.json
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,69 @@ | ||
{ | ||
"id": "ent_saf19jffasdf", | ||
"contact_details": { | ||
"phone": { | ||
"number": "2345678910" | ||
}, | ||
"email_addresses": { | ||
"primary": "[email protected]" | ||
} | ||
}, | ||
"profile": { | ||
"urls": [ | ||
"https://www.superheroexample.com" | ||
], | ||
"mccs": [ | ||
"5311" | ||
], | ||
"default_holding_currency": "GBP", | ||
"holding_currencies": [ | ||
"GBP" | ||
] | ||
}, | ||
"company": { | ||
"business_registration_number": "12345678", | ||
"business_type": "public_limited_company", | ||
"legal_name": "Acme Corporation Inc.", | ||
"trading_name": "Acme Corporation", | ||
"principal_address": { | ||
"address_line1": "Flat 456", | ||
"city": "London", | ||
"zip": "SW1A 1AA", | ||
"country": "GB" | ||
}, | ||
"registered_address": { | ||
"address_line1": "Flat 456", | ||
"city": "London", | ||
"zip": "SW1A 1AA", | ||
"country": "GB" | ||
}, | ||
"representatives": [ | ||
{ | ||
"id": "rep_1d1j98j1h991dlkjdajsjd", | ||
"first_name": "John", | ||
"last_name": "Smith", | ||
"address": { | ||
"address_line1": "Flat 456", | ||
"city": "London", | ||
"zip": "SW1A 1AA", | ||
"country": "GB" | ||
}, | ||
"identification": { | ||
"national_id_number": "AB123456C", | ||
"document": { | ||
"type": "driving_license", | ||
"front": "file_wxglze3wwywujg4nna5fb7ldli", | ||
"back": "file_adglze3wwywujg4nna5fb7l1sg" | ||
} | ||
}, | ||
"phone": { | ||
"number": "2345678910" | ||
}, | ||
"roles": [ | ||
"authorised_signatory", | ||
"ubo" | ||
] | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.