mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
feat(v2): Add cell id in config for v2 (#5885)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -63,27 +63,29 @@ impl From<AlphaNumericIdError> for CellIdError {
|
||||
|
||||
impl CellId {
|
||||
/// Create a new cell id from a string
|
||||
fn from_str(cell_id_string: &str) -> Result<Self, CellIdError> {
|
||||
let trimmed_input_string = cell_id_string.trim().to_string();
|
||||
pub fn from_str(cell_id_string: impl AsRef<str>) -> Result<Self, CellIdError> {
|
||||
let trimmed_input_string = cell_id_string.as_ref().trim().to_string();
|
||||
let alphanumeric_id = AlphaNumericId::from(trimmed_input_string.into())?;
|
||||
let length_id = LengthId::from_alphanumeric_id(alphanumeric_id)?;
|
||||
Ok(Self(length_id))
|
||||
}
|
||||
|
||||
pub fn from_string(input_string: String) -> error_stack::Result<Self, errors::ValidationError> {
|
||||
Self::from_str(&input_string).change_context(
|
||||
errors::ValidationError::IncorrectValueProvided {
|
||||
field_name: "cell_id",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// Get the string representation of the cell id
|
||||
fn get_string_repr(&self) -> &str {
|
||||
&self.0 .0 .0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> serde::Deserialize<'de> for CellId {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let deserialized_string = String::deserialize(deserializer)?;
|
||||
Self::from_str(deserialized_string.as_str()).map_err(serde::de::Error::custom)
|
||||
}
|
||||
}
|
||||
|
||||
/// Error generated from violation of constraints for MerchantReferenceId
|
||||
#[derive(Debug, Error, PartialEq, Eq)]
|
||||
pub(crate) enum GlobalIdError {
|
||||
|
||||
@ -28,8 +28,10 @@ pub enum GlobalPaymentMethodIdError {
|
||||
|
||||
impl GlobalPaymentMethodId {
|
||||
/// Create a new GlobalPaymentMethodId from celll id information
|
||||
pub fn generate(cell_id: &str) -> error_stack::Result<Self, errors::ValidationError> {
|
||||
let cell_id = CellId::from_string(cell_id.to_string())?;
|
||||
pub fn generate(cell_id: &str) -> error_stack::Result<Self, GlobalPaymentMethodIdError> {
|
||||
let cell_id = CellId::from_str(cell_id)
|
||||
.change_context(GlobalPaymentMethodIdError::ConstructionError)
|
||||
.attach_printable("Failed to construct CellId from str")?;
|
||||
let global_id = GlobalId::generate(cell_id, GlobalEntity::PaymentMethod);
|
||||
Ok(Self(global_id))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user