fix(connector): accept state abbreviation in 2 letter (#4646)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
SamraatBansal
2024-05-15 16:39:53 +05:30
committed by GitHub
parent 24214bcfcd
commit 3cf840e486
2 changed files with 106 additions and 86 deletions

View File

@ -2010,7 +2010,9 @@ pub enum FileUploadProvider {
Checkout, Checkout,
} }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, strum::Display)] #[derive(
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, strum::Display, strum::EnumString,
)]
pub enum UsStatesAbbreviation { pub enum UsStatesAbbreviation {
AL, AL,
AK, AK,
@ -2073,7 +2075,9 @@ pub enum UsStatesAbbreviation {
WY, WY,
} }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, strum::Display)] #[derive(
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, strum::Display, strum::EnumString,
)]
pub enum CanadaStatesAbbreviation { pub enum CanadaStatesAbbreviation {
AB, AB,
BC, BC,

View File

@ -10,6 +10,7 @@ use base64::Engine;
use common_utils::{ use common_utils::{
date_time, date_time,
errors::ReportSwitchExt, errors::ReportSwitchExt,
ext_traits::StringExt,
pii::{self, Email, IpAddress}, pii::{self, Email, IpAddress},
}; };
use diesel_models::enums; use diesel_models::enums;
@ -1789,6 +1790,12 @@ pub fn get_webhook_merchant_secret_key(connector_label: &str, merchant_id: &str)
impl ForeignTryFrom<String> for UsStatesAbbreviation { impl ForeignTryFrom<String> for UsStatesAbbreviation {
type Error = error_stack::Report<errors::ConnectorError>; type Error = error_stack::Report<errors::ConnectorError>;
fn foreign_try_from(value: String) -> Result<Self, Self::Error> { fn foreign_try_from(value: String) -> Result<Self, Self::Error> {
let state_abbreviation_check =
StringExt::<Self>::parse_enum(value.to_uppercase().clone(), "UsStatesAbbreviation");
match state_abbreviation_check {
Ok(state_abbreviation) => Ok(state_abbreviation),
Err(_) => {
let binding = value.as_str().to_lowercase(); let binding = value.as_str().to_lowercase();
let state = binding.as_str(); let state = binding.as_str();
match state { match state {
@ -1858,10 +1865,17 @@ impl ForeignTryFrom<String> for UsStatesAbbreviation {
} }
} }
} }
}
}
impl ForeignTryFrom<String> for CanadaStatesAbbreviation { impl ForeignTryFrom<String> for CanadaStatesAbbreviation {
type Error = error_stack::Report<errors::ConnectorError>; type Error = error_stack::Report<errors::ConnectorError>;
fn foreign_try_from(value: String) -> Result<Self, Self::Error> { fn foreign_try_from(value: String) -> Result<Self, Self::Error> {
let state_abbreviation_check =
StringExt::<Self>::parse_enum(value.to_uppercase().clone(), "CanadaStatesAbbreviation");
match state_abbreviation_check {
Ok(state_abbreviation) => Ok(state_abbreviation),
Err(_) => {
let binding = value.as_str().to_lowercase(); let binding = value.as_str().to_lowercase();
let state = binding.as_str(); let state = binding.as_str();
match state { match state {
@ -1885,6 +1899,8 @@ impl ForeignTryFrom<String> for CanadaStatesAbbreviation {
} }
} }
} }
}
}
pub trait ConnectorErrorTypeMapping { pub trait ConnectorErrorTypeMapping {
fn get_connector_error_type( fn get_connector_error_type(