mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	refactor(utils): use to_state_code of hyperswitch_connectors in router (#7278)
This commit is contained in:
		| @ -1,15 +1,12 @@ | ||||
| use std::collections::HashMap; | ||||
|  | ||||
| use common_utils::pii::Email; | ||||
| use hyperswitch_connectors::utils::AddressDetailsData; | ||||
| use masking::ExposeInterface; | ||||
| use serde::{Deserialize, Serialize}; | ||||
| use unidecode::unidecode; | ||||
|  | ||||
| use crate::{ | ||||
|     connector::utils::{AddressDetailsData, PhoneDetailsData}, | ||||
|     errors, | ||||
|     types::api::MessageCategory, | ||||
| }; | ||||
| use crate::{connector::utils::PhoneDetailsData, errors, types::api::MessageCategory}; | ||||
|  | ||||
| #[derive(Debug, Deserialize, Serialize, Clone)] | ||||
| #[serde(untagged)] | ||||
|  | ||||
| @ -4,6 +4,7 @@ use api_models::payments::{DeviceChannel, ThreeDsCompletionIndicator}; | ||||
| use base64::Engine; | ||||
| use common_utils::date_time; | ||||
| use error_stack::ResultExt; | ||||
| use hyperswitch_connectors::utils::AddressDetailsData; | ||||
| use iso_currency::Currency; | ||||
| use isocountry; | ||||
| use masking::{ExposeInterface, Secret}; | ||||
| @ -11,7 +12,7 @@ use serde::{Deserialize, Serialize}; | ||||
| use serde_json::{json, to_string}; | ||||
|  | ||||
| use crate::{ | ||||
|     connector::utils::{get_card_details, to_connector_meta, AddressDetailsData, CardData}, | ||||
|     connector::utils::{get_card_details, to_connector_meta, CardData}, | ||||
|     consts::{BASE64_ENGINE, NO_ERROR_MESSAGE}, | ||||
|     core::errors, | ||||
|     types::{ | ||||
|  | ||||
| @ -1857,8 +1857,6 @@ pub trait AddressDetailsData { | ||||
|     fn get_zip(&self) -> Result<&Secret<String>, Error>; | ||||
|     fn get_country(&self) -> Result<&api_models::enums::CountryAlpha2, Error>; | ||||
|     fn get_combined_address_line(&self) -> Result<Secret<String>, Error>; | ||||
|     fn to_state_code(&self) -> Result<Secret<String>, Error>; | ||||
|     fn to_state_code_as_optional(&self) -> Result<Option<Secret<String>>, Error>; | ||||
|     fn get_optional_line2(&self) -> Option<Secret<String>>; | ||||
|     fn get_optional_country(&self) -> Option<api_models::enums::CountryAlpha2>; | ||||
| } | ||||
| @ -1931,31 +1929,6 @@ impl AddressDetailsData for hyperswitch_domain_models::address::AddressDetails { | ||||
|             self.get_line2()?.peek() | ||||
|         ))) | ||||
|     } | ||||
|     fn to_state_code(&self) -> Result<Secret<String>, Error> { | ||||
|         let country = self.get_country()?; | ||||
|         let state = self.get_state()?; | ||||
|         match country { | ||||
|             api_models::enums::CountryAlpha2::US => Ok(Secret::new( | ||||
|                 UsStatesAbbreviation::foreign_try_from(state.peek().to_string())?.to_string(), | ||||
|             )), | ||||
|             api_models::enums::CountryAlpha2::CA => Ok(Secret::new( | ||||
|                 CanadaStatesAbbreviation::foreign_try_from(state.peek().to_string())?.to_string(), | ||||
|             )), | ||||
|             _ => Ok(state.clone()), | ||||
|         } | ||||
|     } | ||||
|     fn to_state_code_as_optional(&self) -> Result<Option<Secret<String>>, Error> { | ||||
|         self.state | ||||
|             .as_ref() | ||||
|             .map(|state| { | ||||
|                 if state.peek().len() == 2 { | ||||
|                     Ok(state.to_owned()) | ||||
|                 } else { | ||||
|                     self.to_state_code() | ||||
|                 } | ||||
|             }) | ||||
|             .transpose() | ||||
|     } | ||||
|  | ||||
|     fn get_optional_line2(&self) -> Option<Secret<String>> { | ||||
|         self.line2.clone() | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Sakil Mostak
					Sakil Mostak