@@ -29,17 +29,17 @@ public class SupplierService : ApplicationService, ISupplierService
2929 private readonly ILocalEventBus localEventBus ;
3030 private readonly IResilientHttpRequest resilientHttpRequest ;
3131 private readonly ICasTokenService iTokenService ;
32- public SupplierService ( ILocalEventBus localEventBus ,
32+ public SupplierService ( ILocalEventBus localEventBus ,
3333 IEndpointManagementAppService endpointManagementAppService ,
3434 IResilientHttpRequest resilientHttpRequest ,
3535 ICasTokenService iTokenService )
3636 {
37- this . localEventBus = localEventBus ;
38- this . resilientHttpRequest = resilientHttpRequest ;
39- this . iTokenService = iTokenService ;
37+ this . localEventBus = localEventBus ;
38+ this . resilientHttpRequest = resilientHttpRequest ;
39+ this . iTokenService = iTokenService ;
4040
41- // Initialize the base API URL once during construction
42- casBaseApiTask = InitializeBaseApiAsync ( endpointManagementAppService ) ;
41+ // Initialize the base API URL once during construction
42+ casBaseApiTask = InitializeBaseApiAsync ( endpointManagementAppService ) ;
4343 }
4444
4545 private static async Task < string > InitializeBaseApiAsync ( IEndpointManagementAppService endpointManagementAppService )
@@ -159,47 +159,42 @@ string GetProp(string name) =>
159159 }
160160
161161
162- protected static SiteEto GetSiteEto ( dynamic site )
162+ protected static SiteEto GetSiteEto ( JsonElement site )
163163 {
164- string supplierSiteCode = site [ "suppliersitecode" ] . ToString ( ) ;
165- string addressLine1 = site [ "addressline1" ] . ToString ( ) ;
166- string addressLine2 = site [ "addressline2" ] . ToString ( ) ;
167- string city = site [ "city" ] . ToString ( ) ;
168- string province = site [ "province" ] . ToString ( ) ;
169- string country = site [ "country" ] . ToString ( ) ;
170- string postalCode = site [ "postalcode" ] . ToString ( ) ;
171- string emailAddress = site [ "emailaddress" ] . ToString ( ) ;
172- string eftAdvicePref = site [ "eftadvicepref" ] . ToString ( ) ;
173- string accountNumber = site [ "accountnumber" ] . ToString ( ) ;
164+ string accountNumber = GetJsonProperty ( "accountnumber" , site ) ;
174165 string maskedAccountNumber = accountNumber . Length > 4
175166 ? new string ( '*' , accountNumber . Length - 4 ) + accountNumber [ ^ 4 ..]
176167 : accountNumber ;
177- string bankAccount = maskedAccountNumber ;
178- string providerId = site [ "providerid" ] . ToString ( ) ;
179- string siteStatus = site [ "status" ] . ToString ( ) ;
180- string siteProtected = site [ "siteprotected" ] . ToString ( ) ;
181- string siteLastUpdated = site [ "lastupdated" ] . ToString ( ) ;
182-
168+ string siteLastUpdated = GetJsonProperty ( "lastupdated" , site ) ;
183169 _ = DateTime . TryParse ( siteLastUpdated , System . Globalization . CultureInfo . InvariantCulture , System . Globalization . DateTimeStyles . None , out DateTime siteLastUpdatedDate ) ;
170+
184171 return new SiteEto
185172 {
186- SupplierSiteCode = supplierSiteCode ,
187- AddressLine1 = addressLine1 ,
188- AddressLine2 = addressLine2 ,
189- AddressLine3 = addressLine2 ,
190- City = city ,
191- Province = province ,
192- Country = country ,
193- PostalCode = postalCode ,
194- EmailAddress = emailAddress ,
195- EFTAdvicePref = eftAdvicePref ,
196- BankAccount = bankAccount ,
197- ProviderId = providerId ,
198- Status = siteStatus ,
199- SiteProtected = siteProtected ,
173+ SupplierSiteCode = GetJsonProperty ( "suppliersitecode" , site ) ,
174+ AddressLine1 = GetJsonProperty ( "addressline1" , site ) ,
175+ AddressLine2 = GetJsonProperty ( "addressline2" , site ) ,
176+ AddressLine3 = GetJsonProperty ( "addressline2" , site ) ,
177+ City = GetJsonProperty ( " city" , site ) ,
178+ Province = GetJsonProperty ( " province" , site ) ,
179+ Country = GetJsonProperty ( " country" , site ) ,
180+ PostalCode = GetJsonProperty ( "postalcode" , site ) ,
181+ EmailAddress = GetJsonProperty ( "emailaddress" , site ) ,
182+ EFTAdvicePref = GetJsonProperty ( "eftadvicepref" , site ) ,
183+ BankAccount = maskedAccountNumber ,
184+ ProviderId = GetJsonProperty ( "providerid" , site ) ,
185+ Status = GetJsonProperty ( "status" , site ) ,
186+ SiteProtected = GetJsonProperty ( "siteprotected" , site ) ,
200187 LastUpdated = siteLastUpdatedDate
201188 } ;
202189 }
190+
191+ private static string GetJsonProperty ( string name , JsonElement jsonElement )
192+ {
193+ return jsonElement . TryGetProperty ( name , out var prop ) && prop . ValueKind != JsonValueKind . Null
194+ ? prop . ToString ( )
195+ : string . Empty ;
196+ }
197+
203198 public async Task < dynamic > GetCasSupplierInformationAsync ( string ? supplierNumber )
204199 {
205200 if ( ! string . IsNullOrEmpty ( supplierNumber ) )
@@ -236,7 +231,7 @@ private async Task<dynamic> GetCasSupplierInformationByResourceAsync(string? res
236231 var authToken = await iTokenService . GetAuthTokenAsync ( ) ;
237232 try
238233 {
239- using var response = await resilientHttpRequest . HttpAsync ( HttpMethod . Get , resource , authToken ) ;
234+ using var response = await resilientHttpRequest . HttpAsync ( HttpMethod . Get , resource , body : null , authToken ) ;
240235 if ( response != null )
241236 {
242237 if ( response . Content != null && response . StatusCode != HttpStatusCode . NotFound )
0 commit comments