mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 09:38:33 +08:00
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:
@ -2010,7 +2010,9 @@ pub enum FileUploadProvider {
|
||||
Checkout,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, strum::Display)]
|
||||
#[derive(
|
||||
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, strum::Display, strum::EnumString,
|
||||
)]
|
||||
pub enum UsStatesAbbreviation {
|
||||
AL,
|
||||
AK,
|
||||
@ -2073,7 +2075,9 @@ pub enum UsStatesAbbreviation {
|
||||
WY,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, strum::Display)]
|
||||
#[derive(
|
||||
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, strum::Display, strum::EnumString,
|
||||
)]
|
||||
pub enum CanadaStatesAbbreviation {
|
||||
AB,
|
||||
BC,
|
||||
|
||||
@ -10,6 +10,7 @@ use base64::Engine;
|
||||
use common_utils::{
|
||||
date_time,
|
||||
errors::ReportSwitchExt,
|
||||
ext_traits::StringExt,
|
||||
pii::{self, Email, IpAddress},
|
||||
};
|
||||
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 {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
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 state = binding.as_str();
|
||||
match state {
|
||||
@ -1857,11 +1864,18 @@ impl ForeignTryFrom<String> for UsStatesAbbreviation {
|
||||
.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ForeignTryFrom<String> for CanadaStatesAbbreviation {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
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 state = binding.as_str();
|
||||
match state {
|
||||
@ -1884,6 +1898,8 @@ impl ForeignTryFrom<String> for CanadaStatesAbbreviation {
|
||||
.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ConnectorErrorTypeMapping {
|
||||
|
||||
Reference in New Issue
Block a user