private fun checkZipCode() { val parameters = HashMap<String, String>() parameters["zipCode"] = uiState.value.addressFields.zipcode.value!! parameters["isoCountryCode"] = "US" viewModelScope.launch(Dispatchers.IO) { when(val result = getCountryDataUseCase.verifyZipCodeForUS( fullUrl = NetworkingService.instance.getOnboardingAPIURL("onboarding/states/") + (uiState.value.selectedStateAbb?.split("-".toRegex())?.toTypedArray() ?.get(1) ?: ""), queryMap = parameters )) { is RemoteResponse.Success -> { if (result.value.abbreviation.isNullOrEmpty()) { val zipCode = InputValidator.validZipCode(true) displayCompanyInfoErrors( InputErrors( companyNameErrorId = null, companyNameWarningId = null, address1 = null, address2 = null, address3 = null, city = null, state = null, zipCode = zipCode, country = null ) ) } else { // [displayInputErrors] is not required as there are no errors, but still implemented to keep the code in proper structure val zipCode = InputValidator.validZipCode(false) displayCompanyInfoErrors( InputErrors( companyNameErrorId = null, companyNameWarningId = null, address1 = null, address2 = null, address3 = null, city = null, state = null, zipCode = zipCode, country = null ), signInProcessing = true ) if (uiState.value.recommendedScreenSeen) { _uiState.value = uiState.value.copy( dotPagerList = listOf( Dot(completed = true), Dot(completed = true), Dot(), Dot() ), signInProcessing = false ) viewModelScope.launch(Dispatchers.Main) { navigationEvent.emit(RegistrationNavigationEvent.OpenAccountInformationScreen) } } else { getTokenForRecommendationApi() } } } is RemoteResponse.Failure -> { } } } }
This Api call method which validates the Zipcode enters by the user, this only runs if the input country is US