mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 11:24:45 +08:00
refactor(customers_v2): address panics and some bugs in customers v2 endpoints (#6836)
This commit is contained in:
@ -42,7 +42,7 @@ pub enum ApiEventsType {
|
||||
PaymentMethodCreate,
|
||||
#[cfg(all(feature = "v2", feature = "customer_v2"))]
|
||||
Customer {
|
||||
id: String,
|
||||
customer_id: Option<id_type::GlobalCustomerId>,
|
||||
},
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
Customer {
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
//! Common ID types
|
||||
//! The id type can be used to create specific id types with custom behaviour
|
||||
|
||||
use std::{borrow::Cow, fmt::Debug};
|
||||
|
||||
mod api_key;
|
||||
mod customer;
|
||||
#[cfg(feature = "v2")]
|
||||
mod global_id;
|
||||
mod merchant;
|
||||
mod merchant_connector_account;
|
||||
mod organization;
|
||||
@ -14,11 +14,8 @@ mod refunds;
|
||||
mod routing;
|
||||
mod tenant;
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
mod global_id;
|
||||
use std::{borrow::Cow, fmt::Debug};
|
||||
|
||||
pub use api_key::ApiKeyId;
|
||||
pub use customer::CustomerId;
|
||||
use diesel::{
|
||||
backend::Backend,
|
||||
deserialize::FromSql,
|
||||
@ -26,24 +23,29 @@ use diesel::{
|
||||
serialize::{Output, ToSql},
|
||||
sql_types,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
pub use global_id::{
|
||||
pub use self::global_id::{
|
||||
customer::GlobalCustomerId,
|
||||
payment::{GlobalAttemptId, GlobalPaymentId},
|
||||
payment_methods::GlobalPaymentMethodId,
|
||||
refunds::GlobalRefundId,
|
||||
CellId,
|
||||
};
|
||||
pub use merchant::MerchantId;
|
||||
pub use merchant_connector_account::MerchantConnectorAccountId;
|
||||
pub use organization::OrganizationId;
|
||||
pub use payment::{PaymentId, PaymentReferenceId};
|
||||
pub use profile::ProfileId;
|
||||
pub use refunds::RefundReferenceId;
|
||||
pub use routing::RoutingId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
pub use tenant::TenantId;
|
||||
use thiserror::Error;
|
||||
|
||||
pub use self::{
|
||||
api_key::ApiKeyId,
|
||||
customer::CustomerId,
|
||||
merchant::MerchantId,
|
||||
merchant_connector_account::MerchantConnectorAccountId,
|
||||
organization::OrganizationId,
|
||||
payment::{PaymentId, PaymentReferenceId},
|
||||
profile::ProfileId,
|
||||
refunds::RefundReferenceId,
|
||||
routing::RoutingId,
|
||||
tenant::TenantId,
|
||||
};
|
||||
use crate::{fp_utils::when, generate_id_with_default_len};
|
||||
|
||||
#[inline]
|
||||
|
||||
@ -13,3 +13,12 @@ crate::impl_generate_id_id_type!(CustomerId, "cus");
|
||||
crate::impl_serializable_secret_id_type!(CustomerId);
|
||||
crate::impl_queryable_id_type!(CustomerId);
|
||||
crate::impl_to_sql_from_sql_id_type!(CustomerId);
|
||||
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
impl crate::events::ApiEventMetric for CustomerId {
|
||||
fn get_api_event_type(&self) -> Option<crate::events::ApiEventsType> {
|
||||
Some(crate::events::ApiEventsType::Customer {
|
||||
customer_id: self.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
pub mod payment;
|
||||
pub mod payment_methods;
|
||||
pub mod refunds;
|
||||
pub(super) mod customer;
|
||||
pub(super) mod payment;
|
||||
pub(super) mod payment_methods;
|
||||
pub(super) mod refunds;
|
||||
|
||||
use diesel::{backend::Backend, deserialize::FromSql, serialize::ToSql, sql_types};
|
||||
use error_stack::ResultExt;
|
||||
|
||||
45
crates/common_utils/src/id_type/global_id/customer.rs
Normal file
45
crates/common_utils/src/id_type/global_id/customer.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use error_stack::ResultExt;
|
||||
|
||||
use crate::{errors, generate_id_with_default_len, generate_time_ordered_id_without_prefix, types};
|
||||
|
||||
crate::global_id_type!(
|
||||
GlobalCustomerId,
|
||||
"A global id that can be used to identify a customer.
|
||||
|
||||
The format will be `<cell_id>_<entity_prefix>_<time_ordered_id>`.
|
||||
|
||||
Example: `cell1_cus_uu1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p`"
|
||||
);
|
||||
|
||||
// Database related implementations so that this field can be used directly in the database tables
|
||||
crate::impl_queryable_id_type!(GlobalCustomerId);
|
||||
crate::impl_to_sql_from_sql_global_id_type!(GlobalCustomerId);
|
||||
|
||||
impl GlobalCustomerId {
|
||||
/// Get string representation of the id
|
||||
pub fn get_string_repr(&self) -> &str {
|
||||
self.0.get_string_repr()
|
||||
}
|
||||
|
||||
/// Generate a new GlobalCustomerId from a cell id
|
||||
pub fn generate(cell_id: &crate::id_type::CellId) -> Self {
|
||||
let global_id = super::GlobalId::generate(cell_id, super::GlobalEntity::Customer);
|
||||
Self(global_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<GlobalCustomerId> for crate::id_type::CustomerId {
|
||||
type Error = error_stack::Report<crate::errors::ValidationError>;
|
||||
|
||||
fn try_from(value: GlobalCustomerId) -> Result<Self, Self::Error> {
|
||||
Self::try_from(std::borrow::Cow::from(value.get_string_repr().to_owned()))
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::events::ApiEventMetric for GlobalCustomerId {
|
||||
fn get_api_event_type(&self) -> Option<crate::events::ApiEventsType> {
|
||||
Some(crate::events::ApiEventsType::Customer {
|
||||
customer_id: Some(self.clone()),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -4,9 +4,11 @@ use crate::{errors, generate_id_with_default_len, generate_time_ordered_id_witho
|
||||
|
||||
crate::global_id_type!(
|
||||
GlobalPaymentId,
|
||||
"A global id that can be used to identify a payment
|
||||
The format will be `<cell_id>_<entity_prefix>_<time_ordered_id>`
|
||||
example - cell1_pay_uu1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p"
|
||||
"A global id that can be used to identify a payment.
|
||||
|
||||
The format will be `<cell_id>_<entity_prefix>_<time_ordered_id>`.
|
||||
|
||||
Example: `cell1_pay_uu1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p`"
|
||||
);
|
||||
|
||||
// Database related implementations so that this field can be used directly in the database tables
|
||||
|
||||
Reference in New Issue
Block a user