Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(customers): use domain type for customer ID (#12735)

Kashifaa2beff1e15d
diff --git a/crates/common_utils/src/id_type.rs b/crates/common_utils/src/id_type.rs
index dadfb2a9c5..8e6c5d5584 100644
--- a/crates/common_utils/src/id_type.rs
+++ b/crates/common_utils/src/id_type.rs
@@ -7,7 +7,6 @@ mod card_issuer;
mod client_secret;
mod client_session;
mod customer;
-#[cfg(feature = "v2")]
mod global_id;
mod invoice;
mod merchant;
@@ -39,12 +38,10 @@ use thiserror::Error;
#[cfg(feature = "v2")]
pub use self::global_id::{
- customer::GlobalCustomerId,
payment::{GlobalAttemptGroupId, GlobalAttemptId, GlobalPaymentId},
payment_methods::{GlobalPaymentMethodId, GlobalPaymentMethodSessionId},
refunds::GlobalRefundId,
token::GlobalTokenId,
- CellId,
};
pub use self::{
api_key::ApiKeyId,
@@ -53,6 +50,7 @@ pub use self::{
client_secret::ClientSecretId,
client_session::ClientSessionId,
customer::CustomerId,
+ global_id::{customer::GlobalCustomerId, CellId},
invoice::InvoiceId,
merchant::MerchantId,
merchant_connector_account::MerchantConnectorAccountId,
@@ -189,7 +187,6 @@ impl<const MAX_LENGTH: u8, const MIN_LENGTH: u8> LengthId<MAX_LENGTH, MIN_LENGTH
Self(alphanumeric_id)
}
- #[cfg(feature = "v2")]
/// Create a new LengthId from aplhanumeric id
pub(crate) fn from_alphanumeric_id(
alphanumeric_id: AlphaNumericId,
diff --git a/crates/common_utils/src/id_type/global_id.rs b/crates/common_utils/src/id_type/global_id.rs
index c1450ce7e1..d230734dbc 100644
--- a/crates/common_utils/src/id_type/global_id.rs
+++ b/crates/common_utils/src/id_type/global_id.rs
@@ -1,7 +1,11 @@
pub(super) mod customer;
+#[cfg(feature = "v2")]
pub(super) mod payment;
+#[cfg(feature = "v2")]
pub(super) mod payment_methods;
+#[cfg(feature = "v2")]
pub(super) mod refunds;
+#[cfg(feature = "v2")]
pub(super) mod token;
use diesel::{backend::Backend, deserialize::FromSql, serialize::ToSql, sql_types};
@@ -23,12 +27,19 @@ pub(crate) struct GlobalId(LengthId<MAX_GLOBAL_ID_LENGTH, MIN_GLOBAL_ID_LENGTH>)
/// Entities that can be identified by a global id
pub(crate) enum GlobalEntity {
Customer,
+ #[cfg(feature = "v2")]
Payment,
+ #[cfg(feature = "v2")]
Attempt,
+ #[cfg(feature = "v2")]
AttemptGroup,
+ #[cfg(feature = "v2")]
PaymentMethod,
+ #[cfg(feature = "v2")]
Refund,
+ #[cfg(feature = "v2")]
PaymentMethodSession,
+ #[cfg(feature = "v2")]
Token,
}
@@ -36,12 +47,19 @@ impl GlobalEntity {
fn prefix(self) -> &'static str {
match self {
Self::Customer => "cus",
+ #[cfg(feature = "v2")]
Self::Payment => "pay",
+ #[cfg(feature = "v2")]
Self::PaymentMethod => "pm",
+ #[cfg(feature = "v2")]
Self::Attempt => "att",
+ #[cfg(feature = "v2")]
Self::AttemptGroup => "atg",
+ #[cfg(feature = "v2")]
Self::Refund => "ref",
+ #[cfg(feature = "v2")]
Self::PaymentMethodSession => "pms",
+ #[cfg(feature = "v2")]
Self::Token => "tok",
}
}
diff --git a/crates/common_utils/src/id_type/global_id/customer.rs b/crates/common_utils/src/id_type/global_id/customer.rs
index f182530e83..9c096777cb 100644
--- a/crates/common_utils/src/id_type/global_id/customer.rs
+++ b/crates/common_utils/src/id_type/global_id/customer.rs
@@ -85,6 +85,7 @@ impl crate::id_type::TargetingKey for GlobalCustomerId {
}
}
+#[cfg(feature = "v2")]
impl crate::events::ApiEventMetric for GlobalCustomerId {
fn get_api_event_type(&self) -> Option<crate::events::ApiEventsType> {
Some(crate::events::ApiEventsType::Customer {
diff --git a/crates/diesel_models/src/customers.rs b/crates/diesel_models/src/customers.rs
index 22c49b0851..8254cc5973 100644
--- a/crates/diesel_models/src/customers.rs
+++ b/crates/diesel_models/src/customers.rs
@@ -34,7 +34,7 @@ pub struct CustomerNew {
pub created_by: Option<String>,
pub last_modified_by: Option<String>,
pub document_details: Option<Encryption>,
- pub id: Option<String>,
+ pub id: Option<common_utils::id_type::GlobalCustomerId>,
}
#[cfg(feature = "v1")]
@@ -166,7 +166,7 @@ pub struct Customer {
pub created_by: Option<String>,
pub last_modified_by: Option<String>,
pub document_details: Option<Encryption>,
- pub id: Option<String>,
+ pub id: Option<common_utils::id_type::GlobalCustomerId>,
}
#[cfg(feature = "v2")]
diff --git a/crates/hyperswitch_domain_models/src/customer.rs b/crates/hyperswitch_domain_models/src/customer.rs
index 8b1f36d9c7..4ff59b63c1 100644
--- a/crates/hyperswitch_domain_models/src/customer.rs
+++ b/crates/hyperswitch_domain_models/src/customer.rs
@@ -32,10 +32,24 @@ use crate::{
type_encryption::{self as types, AsyncLift},
};
+#[cfg(feature = "v1")]
+#[derive(Clone, Debug)]
+struct CustomerIdentifiers {
+ customer_id: id_type::CustomerId,
+ id: Option<id_type::GlobalCustomerId>,
+}
+
+#[cfg(feature = "v1")]
+impl CustomerIdentifiers {
+ fn new(customer_id: id_type::CustomerId, id: Option<id_type::GlobalCustomerId>) -> Self {
+ Self { customer_id, id }
+ }
+}
+
#[cfg(feature = "v1")]
#[derive(Clone, Debug, router_derive::ToEncryption)]
pub struct Customer {
- pub customer_id: id_type::CustomerId,
+ identifiers: CustomerIdentifiers,
pub merchant_id: id_type::MerchantId,
#[encrypt]
pub name: Option<Encryptable<Secret<String>>>,
@@ -58,7 +72,6 @@ pub struct Customer {
pub document_details: OptionalEncryptableValue,
pub created_by: Option<CreatedBy>,
pub last_modified_by: Option<CreatedBy>,
- key: Option<String>,
}
#[cfg(feature = "v2")]
@@ -110,11 +123,11 @@ impl Customer {
document_details: OptionalEncryptableValue,
created_by: Option<CreatedBy>,
last_modified_by: Option<CreatedBy>,
- key: String,
+ id: id_type::GlobalCustomerId,
) -> Self {
let now = date_time::now();
Self {
- customer_id,
+ identifiers: CustomerIdentifiers::new(customer_id, Some(id)),
merchant_id,
name,
email,
@@ -133,14 +146,19 @@ impl Customer {
document_details,
created_by,
last_modified_by,
- key: Some(key),
}
}
/// Get the unique identifier of Customer
#[cfg(feature = "v1")]
pub fn get_id(&self) -> &id_type::CustomerId {
- &self.customer_id
+ &self.identifiers.customer_id
+ }
+
+ /// Get the global identifier of Customer.
+ #[cfg(feature = "v1")]
+ pub fn get_global_id(&self) -> Option<&id_type::GlobalCustomerId> {
+ self.identifiers.id.as_ref()
}
/// Get the global identifier of Customer
@@ -196,11 +214,6 @@ impl Customer {
MerchantConnectorAccountTypeDetails::MerchantConnectorDetails(_) => None,
}
}
-
- #[cfg(feature = "v1")]
- pub fn get_global_customer_id(&self) -> &Option<String> {
- &self.key
- }
}
#[cfg(feature = "v1")]
@@ -210,7 +223,7 @@ impl behaviour::Conversion for Customer {
type NewDstType = diesel_models::customers::CustomerNew;
async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
Ok(diesel_models::customers::Customer {
- customer_id: self.customer_id.clone(),
+ customer_id: self.identifiers.customer_id.clone(),
merchant_id: self.merchant_id,
name: self.name.map(Encryption::from),
email: self.email.map(Encryption::from),
@@ -231,7 +244,7 @@ impl behaviour::Conversion for Customer {
last_modified_by: self
.last_modified_by
.map(|last_modified_by| last_modified_by.to_string()),
- id: self.key,
+ id: self.identifiers.id,
})
}
@@ -287,7 +300,7 @@ impl behaviour::Conversion for Customer {
})?;
Ok(Self {
- customer_id: item.customer_id,
+ identifiers: CustomerIdentifiers::new(item.customer_id, item.id),
merchant_id: item.merchant_id,
name: encryptable_customer.name,
email: encryptable_customer.email.map(|email| {
@@ -316,15 +329,14 @@ impl behaviour::Conversion for Customer {
last_modified_by: item
.last_modified_by
.and_then(|last_modified_by| last_modified_by.parse::<CreatedBy>().ok()),
- key: item.id,
})
}
async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
let now = date_time::now();
Ok(diesel_models::customers::CustomerNew {
- id: self.key,
- customer_id: self.customer_id,
+ id: self.identifiers.id,
+ customer_id: self.identifiers.customer_id,
merchant_id: self.merchant_id,
name: self.name.map(Encryption::from),
email: self.email.map(Encryption::from),
diff --git a/crates/payment_methods/src/client/create.rs b/crates/payment_methods/src/client/create.rs
index a991494c65..8911314ac7 100644
--- a/crates/payment_methods/src/client/create.rs
+++ b/crates/payment_methods/src/client/create.rs
@@ -26,7 +26,7 @@ pub struct CreatePaymentMethodV1Request {
pub payment_method: common_enums::PaymentMethod,
pub payment_method_type: Option<common_enums::PaymentMethodType>,
pub metadata: Option<pii::SecretSerdeValue>,
- pub customer_id: id_type::CustomerId, // Payment method data will be saved when customer acceptance is given, hence customer id will always be present
+ pub customer_id: id_type::GlobalCustomerId, // Payment method data will be saved when customer acceptance is given, hence customer id will always be present
/// The payment method data for the normal create flow. `None` for the external vault proxy
/// flow, where `proxy_card_data` is set instead.
pub payment_method_data: Option<PaymentMethodData>,
@@ -43,7 +43,7 @@ pub struct ModularPMCreateRequest {
pub payment_method_type: common_enums::PaymentMethod,
pub payment_method_subtype: Option<common_enums::PaymentMethodType>,
pub metadata: Option<pii::SecretSerdeValue>,
- pub customer_id: id_type::CustomerId, // Payment method data will be saved when customer acceptance is given, hence customer id will always be present
+ pub customer_id: id_type::GlobalCustomerId,
pub payment_method_data: PaymentMethodCreateData,
pub billing: Option<payments::Address>,
pub network_tokenization: Option<common_types::payment_methods::NetworkTokenization>,
diff --git a/crates/payment_methods/src/client/list.rs b/crates/payment_methods/src/client/list.rs
index aaf8952a4e..20c8277e3b 100644
--- a/crates/payment_methods/src/client/list.rs
+++ b/crates/payment_methods/src/client/list.rs
@@ -13,7 +13,7 @@ pub struct ListCustomerPaymentMethods;
/// V1-facing retrieve request payload.
#[derive(Debug)]
pub struct ListCustomerPaymentMethodsV1Request {
- pub customer_id: id_type::CustomerId,
+ pub customer_id: id_type::GlobalCustomerId,
pub query_params: PaymentMethodListRequest,
pub modular_service_prefix: String,
}
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs
index 64da24fe9e..682173115e 100644
--- a/crates/router/src/configs/settings.rs
+++ b/crates/router/src/configs/settings.rs
@@ -1386,27 +1386,11 @@ pub struct ServerTls {
pub certificate: PathBuf,
}
-#[cfg(feature = "v2")]
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
pub struct CellInformation {
pub id: id_type::CellId,
}
-#[cfg(feature = "v1")]
-#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
-pub struct CellInformation {
- pub id: String,
-}
-#[cfg(feature = "v1")]
-impl Default for CellInformation {
- fn default() -> Self {
- Self {
- id: String::from("00"),
- }
- }
-}
-
-#[cfg(feature = "v2")]
impl Default for CellInformation {
fn default() -> Self {
// We provide a static default cell id for constructing application settings.
diff --git a/crates/router/src/configs/validations.rs b/crates/router/src/configs/validations.rs
index 57c6b674e4..5263e7a49b 100644
--- a/crates/router/src/configs/validations.rs
+++ b/crates/router/src/configs/validations.rs
@@ -196,20 +196,6 @@ impl super::settings::GenericLinkEnvConfig {
}
}
-#[cfg(feature = "v2")]
-impl super::settings::CellInformation {
- pub fn validate(&self) -> Result<(), ApplicationError> {
- use common_utils::{fp_utils::when, id_type};
-
- when(self == &Self::default(), || {
- Err(ApplicationError::InvalidConfigurationValueError(
- "CellId cannot be set to a default".into(),
- ))
- })
- }
-}
-
-#[cfg(feature = "v1")]
impl super::settings::CellInformation {
pub fn validate(&self) -> Result<(), ApplicationError> {
use common_utils::fp_utils::when;
diff --git a/crates/router/src/core/customers.rs b/crates/router/src/core/customers.rs
index e889dfc5f1..db033cf536 100644
--- a/crates/router/src/core/customers.rs
+++ b/crates/router/src/core/customers.rs
@@ -47,11 +47,6 @@ use crate::{
pub const REDACTED: &str = "Redacted";
-pub fn generate_global_customer_id(cell_id: &str) -> String {
- let prefix = format!("{}_cus", cell_id);
- common_utils::generate_time_ordered_id(&prefix)
-}
-
pub fn is_global_customer_id_format(input: &str) -> bool {
let mut parts = input.split('_');
match (parts.next(), parts.next(), parts.next(), parts.next()) {
@@ -283,7 +278,7 @@ impl CustomerCreateBridge for customers::CustomerRequest {
document_details_encrypted,
initiator.and_then(|initiator| initiator.to_created_by()),
initiator.and_then(|initiator| initiator.to_created_by()),
- generate_global_customer_id(&state.conf.cell_information.id),
+ id_type::GlobalCustomerId::generate(&state.conf.cell_information.id),
))
}
@@ -1267,7 +1262,7 @@ impl AddressStructForDbUpdate<'_> {
.attach_printable(format!(
"Failed while updating address: merchant_id: {:?}, customer_id: {:?}",
self.merchant_account.get_id(),
- self.domain_customer.customer_id
+ self.domain_customer.get_id()
))?,
)
}
@@ -1280,7 +1275,7 @@ impl AddressStructForDbUpdate<'_> {
self.state,
customer_address,
self.merchant_account.get_id(),
- &self.domain_customer.customer_id,
+ self.domain_customer.get_id(),
self.key_store.key.get_inner().peek(),
self.merchant_account.storage_scheme,
)
@@ -1451,7 +1446,7 @@ impl CustomerUpdateBridge for customers::CustomerUpdateRequest {
let response = db
.update_customer_by_customer_id_merchant_id(
- domain_customer.customer_id.to_owned(),
+ domain_customer.get_id().to_owned(),
provider.get_account().get_id().to_owned(),
domain_customer.to_owned(),
storage::CustomerUpdate::Update {
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs
index 910b84ff5c..7fb9cf1e1e 100644
--- a/crates/router/src/core/payment_methods.rs
+++ b/crates/router/src/core/payment_methods.rs
@@ -389,7 +389,7 @@ pub async fn render_pm_collect_link(
publishable_key: Secret::new(provider.get_account().clone().publishable_key),
client_secret: link_data.client_secret.clone(),
pm_collect_link_id: pm_collect_link.link_id,
- customer_id: customer.customer_id,
+ customer_id: customer.get_id().clone(),
session_expiry: pm_collect_link.expiry,
return_url: pm_collect_link.return_url,
ui_config: ui_config_data,
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 63d6ac32e8..8ed4a20e70 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -1206,7 +1206,7 @@ impl PaymentMethodsController for PmCards<'_> {
},
)?;
- let customer_id = customer.customer_id.clone();
+ let customer_id = customer.get_id().clone();
let customer_update = CustomerUpdate::UpdateDefaultPaymentMethod {
default_payment_method_id: Some(Some(payment_method_id.to_owned())),
@@ -1777,13 +1777,17 @@ impl PaymentMethodsController for PmCards<'_> {
api_enums::PaymentMethod::BankDebit => match req.payment_method_data.clone() {
Some(api_models::payment_methods::PaymentMethodCreateData::BankDebit(
bank_debit_data,
- )) => Box::pin(self.add_bank_debit_to_locker(
- req.clone(),
- bank_debit_data,
- self.provider.get_key_store(),
- &customer_id,
- customer_obj.get_global_customer_id().clone(),
- ))
+ )) => Box::pin(
+ self.add_bank_debit_to_locker(
+ req.clone(),
+ bank_debit_data,
+ self.provider.get_key_store(),
+ &customer_id,
+ customer_obj
+ .get_global_id()
+ .map(|id| id.get_string_repr().to_owned()),
+ ),
+ )
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Add BankDebit Failed"),
diff --git a/crates/router/src/core/payment_methods/client.rs b/crates/router/src/core/payment_methods/client.rs
index 9cf6ecf949..329691d767 100644
--- a/crates/router/src/core/payment_methods/client.rs
+++ b/crates/router/src/core/payment_methods/client.rs
@@ -48,7 +48,7 @@ pub trait CustomerPaymentMethodsFetcher: Send + Sync {
state: &routes::SessionState,
platform: &domain::Platform,
payment_intent: Option<&storage::PaymentIntent>,
- customer_id: &id_type::CustomerId,
+ customer: &domain::Customer,
dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> errors::RouterResult<Vec<CustomerPaymentMethodForClient>>;
}
@@ -82,14 +82,14 @@ impl CustomerPaymentMethodsFetcher for DbCustomerPaymentMethodsFetcher {
state: &routes::SessionState,
platform: &domain::Platform,
payment_intent: Option<&storage::PaymentIntent>,
- customer_id: &id_type::CustomerId,
+ customer: &domain::Customer,
dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> errors::RouterResult<Vec<CustomerPaymentMethodForClient>> {
let customer_payment_methods_response = Box::pin(cards::list_customer_payment_method(
state,
platform.clone(),
payment_intent.cloned(),
- customer_id,
+ customer.get_id(),
None, // limit
dimensions,
))
@@ -168,16 +168,20 @@ impl CustomerPaymentMethodsFetcher for ModularCustomerPaymentMethodsFetcher {
state: &routes::SessionState,
platform: &domain::Platform,
_payment_intent: Option<&storage::PaymentIntent>,
- customer_id: &id_type::CustomerId,
+ customer: &domain::Customer,
dimensions: &dimension_state::DimensionsWithProcessorAndProviderMerchantId,
) -> errors::RouterResult<Vec<CustomerPaymentMethodForClient>> {
let merchant_id = platform.get_processor().get_account().get_id().clone();
+ let id = customer
+ .get_global_id()
+ .cloned()
+ .ok_or(errors::ApiErrorResponse::MissingRequiredField { field_name: "id" })?;
let items = list_customer_payment_methods_from_modular_service(
state,
&merchant_id,
&self.profile_id,
- customer_id.clone(),
+ id,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)?;
@@ -187,7 +191,7 @@ impl CustomerPaymentMethodsFetcher for ModularCustomerPaymentMethodsFetcher {
.get_requires_cvv(
state.store.as_ref(),
state.superposition_service.as_ref(),
- Some(customer_id),
+ Some(customer.get_id()),
)
.await;
@@ -467,68 +471,73 @@ async fn fetch_customer_payment_methods(
platform: &domain::Platform,
payment_intent_context: &PaymentIntentContext,
) -> errors::RouterResult<Vec<CustomerPaymentMethodForClient>> {
- let customer_id = match payment_intent_context.payment_intent.customer_id.as_ref() {
- Some(customer_id) => customer_id,
- None => return Ok(vec![]),
- };
-
- let dimensions = dimension_state::Dimensions::new()
- .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())
- .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id());
-
- let feature_config = crate::core::utils::get_feature_config(state, platform, &dimensions).await;
-
- if feature_config.is_payment_method_modular_allowed {
- logger::info!("Fetching customer payment methods from modular service");
-
- let profile_id = payment_intent_context
- .payment_intent
- .profile_id
- .clone()
- .ok_or(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("'profile_id' not set in payment intent")?;
-
- let intent_fulfillment_time = payment_intent_context
- .business_profile
- .get_order_fulfillment_time()
- .unwrap_or(consts::DEFAULT_INTENT_FULFILLMENT_TIME);
-
- let off_session_payment_flag = payment_intent_context
- .payment_intent
- .setup_future_usage
- .map(|future_usage| future_usage == common_enums::FutureUsage::OffSession)
- .unwrap_or(false);
-
- let is_connector_agnostic_mit_enabled = payment_intent_context
- .business_profile
- .is_connector_agnostic_mit_enabled
- .unwrap_or(false);
-
- ModularCustomerPaymentMethodsFetcher {
- profile_id,
- intent_fulfillment_time,
- off_session_payment_flag,
- is_connector_agnostic_mit_enabled,
+ match (
+ payment_intent_context.payment_intent.customer_id.as_ref(),
+ payment_intent_context.customer.as_ref(),
+ ) {
+ (None, _) => Ok(vec![]),
+ (Some(_), None) => Err(errors::ApiErrorResponse::CustomerNotFound.into()),
+ (Some(_), Some(customer)) => {
+ let dimensions = dimension_state::Dimensions::new()
+ .with_processor_merchant_id(platform.get_processor().get_processor_merchant_id())
+ .with_provider_merchant_id(platform.get_provider().get_provider_merchant_id());
+
+ let feature_config =
+ crate::core::utils::get_feature_config(state, platform, &dimensions).await;
+
+ if feature_config.is_payment_method_modular_allowed {
+ logger::info!("Fetching customer payment methods from modular service");
+
+ let profile_id = payment_intent_context
+ .payment_intent
+ .profile_id
+ .clone()
+ .ok_or(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("'profile_id' not set in payment intent")?;
+
+ let intent_fulfillment_time = payment_intent_context
+ .business_profile
+ .get_order_fulfillment_time()
+ .unwrap_or(consts::DEFAULT_INTENT_FULFILLMENT_TIME);
+
+ let off_session_payment_flag = payment_intent_context
+ .payment_intent
+ .setup_future_usage
+ .map(|future_usage| future_usage == common_enums::FutureUsage::OffSession)
+ .unwrap_or(false);
+
+ let is_connector_agnostic_mit_enabled = payment_intent_context
+ .business_profile
+ .is_connector_agnostic_mit_enabled
+ .unwrap_or(false);
+
+ ModularCustomerPaymentMethodsFetcher {
+ profile_id,
+ intent_fulfillment_time,
+ off_session_payment_flag,
+ is_connector_agnostic_mit_enabled,
+ }
+ .fetch(
+ state,
+ platform,
+ Some(&payment_intent_context.payment_intent),
+ customer,
+ &dimensions,
+ )
+ .await
+ } else {
+ logger::info!("Fetching customer payment methods from DB");
+ DbCustomerPaymentMethodsFetcher
+ .fetch(
+ state,
+ platform,
+ Some(&payment_intent_context.payment_intent),
+ customer,
+ &dimensions,
+ )
+ .await
+ }
}
- .fetch(
- state,
- platform,
- Some(&payment_intent_context.payment_intent),
- customer_id,
- &dimensions,
- )
- .await
- } else {
- logger::info!("Fetching customer payment methods from DB");
- DbCustomerPaymentMethodsFetcher
- .fetch(
- state,
- platform,
- Some(&payment_intent_context.payment_intent),
- customer_id,
- &dimensions,
- )
- .await
}
}
diff --git a/crates/router/src/core/payment_methods/tokenize/card_executor.rs b/crates/router/src/core/payment_methods/tokenize/card_executor.rs
index 8417a0e49c..88ded081a5 100644
--- a/crates/router/src/core/payment_methods/tokenize/card_executor.rs
+++ b/crates/router/src/core/payment_methods/tokenize/card_executor.rs
@@ -20,12 +20,9 @@ use super::{
NetworkTokenizationResponse, State, StoreLockerResponse, TransitionTo,
};
use crate::{
- core::{
- customers,
- payment_methods::{
- cards::{add_card_to_vault, PmCards},
- transformers as pm_transformers,
- },
+ core::payment_methods::{
+ cards::{add_card_to_vault, PmCards},
+ transformers as pm_transformers,
},
errors::{self, RouterResult},
types::{api, domain},
@@ -363,7 +360,7 @@ impl CardNetworkTokenizeExecutor<'_, domain::TokenizeCardRequest> {
// If found, send back CustomerDetails from DB
|optional_customer| {
Ok(optional_customer.map(|customer| api::CustomerDetails {
- id: Some(customer.customer_id.clone()),
+ id: Some(customer.get_id().clone()),
name: customer.name.clone().map(|name| name.into_inner()),
email: customer.email.clone().map(Email::from),
phone: customer.phone.clone().map(|phone| phone.into_inner()),
@@ -443,7 +440,7 @@ impl CardNetworkTokenizeExecutor<'_, domain::TokenizeCardRequest> {
None,
initiator.and_then(|initiator| initiator.to_created_by()),
initiator.and_then(|initiator| initiator.to_created_by()),
- customers::generate_global_customer_id(&self.state.conf.cell_information.id),
+ id_type::GlobalCustomerId::generate(&self.state.conf.cell_information.id),
);
db.insert_customer(
diff --git a/crates/router/src/core/payment_methods/tokenize/payment_method_executor.rs b/crates/router/src/core/payment_methods/tokenize/payment_method_executor.rs
index 4ac985cee2..b63ec2698d 100644
--- a/crates/router/src/core/payment_methods/tokenize/payment_method_executor.rs
+++ b/crates/router/src/core/payment_methods/tokenize/payment_method_executor.rs
@@ -377,7 +377,7 @@ impl CardNetworkTokenizeExecutor<'_, domain::TokenizePaymentMethodRequest> {
.change_context(errors::ApiErrorResponse::InternalServerError)?;
let customer_details = api::CustomerDetails {
- id: Some(customer.customer_id.clone()),
+ id: Some(customer.get_id().clone()),
name: customer.name.clone().map(|name| name.into_inner()),
email: customer.email.clone().map(Email::from),
phone: customer.phone.clone().map(|phone| phone.into_inner()),
diff --git a/crates/router/src/core/payment_methods/transformers.rs b/crates/router/src/core/payment_methods/transformers.rs
index 689ed2e5de..bf9ccdee6a 100644
--- a/crates/router/src/core/payment_methods/transformers.rs
+++ b/crates/router/src/core/payment_methods/transformers.rs
@@ -2060,7 +2060,7 @@ pub async fn create_payment_method_in_modular_service(
payment_method_type: Option<common_enums::PaymentMethodType>,
payment_method_data: domain::PaymentMethodData,
billing_address: Option<hyperswitch_domain_models::address::Address>,
- customer_id: id_type::CustomerId,
+ customer_id: id_type::GlobalCustomerId,
is_network_tokenization_enabled: bool,
) -> CustomResult<domain::PaymentMethod, errors::ApiErrorResponse> {
let payment_method_request = CreatePaymentMethodV1Request {
@@ -2107,7 +2107,7 @@ pub async fn create_proxy_card_payment_method_in_modular_service(
payment_method_type: Option<common_enums::PaymentMethodType>,
vault_card: hyperswitch_domain_models::payment_method_data::ExternalVaultCard,
billing_address: Option<hyperswitch_domain_models::address::Address>,
- customer_id: id_type::CustomerId,
+ customer_id: id_type::GlobalCustomerId,
) -> CustomResult<domain::PaymentMethod, errors::ApiErrorResponse> {
// Proxy flow: the card comes from `proxy_card_data`, so `payment_method_data` is None.
let payment_method_request = CreatePaymentMethodV1Request {
@@ -2205,7 +2205,7 @@ pub async fn list_customer_payment_methods_from_modular_service(
state: &routes::SessionState,
merchant_id: &id_type::MerchantId,
profile_id: &id_type::ProfileId,
- customer_id: id_type::CustomerId,
+ customer_id: id_type::GlobalCustomerId,
) -> CustomResult<Vec<payment_methods::types::PaymentMethodResponseItemV1>, errors::ApiErrorResponse>
{
let internal_api_key = &state
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index a871ceda7c..71e62628e5 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -733,18 +733,6 @@ where
&payment_data.get_payment_intent().clone(),
)?;
- operation
- .to_domain()?
- .create_payment_method(
- state,
- &req,
- platform,
- &mut payment_data,
- &business_profile,
- &feature_config,
- )
- .await?;
-
let (operation, customer) = operation
.to_domain()?
// get_customer_details
@@ -761,6 +749,19 @@ where
.to_not_found_response(errors::ApiErrorResponse::CustomerNotFound)
.attach_printable("Failed while fetching/creating customer")?;
+ operation
+ .to_domain()?
+ .create_payment_method(
+ state,
+ &req,
+ platform,
+ &mut payment_data,
+ customer.as_ref(),
+ &business_profile,
+ &feature_config,
+ )
+ .await?;
+
let connector_customer_map = customer
.as_ref()
.and_then(|customer| customer.connector_customer.as_ref());
@@ -2998,7 +2999,7 @@ where
let locale = header_payload.locale.clone();
- let (operation, _customer) = operation
+ let (operation, customer) = operation
.to_domain()?
.get_or_create_customer_details(
state,
@@ -3020,6 +3021,7 @@ where
&req,
&platform,
&mut payment_data,
+ customer.as_ref(),
&business_profile,
&feature_config,
)
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 563158fb2c..242e85018d 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -2193,7 +2193,7 @@ pub async fn create_customer_if_not_exist<'a, F: Clone, R, D>(
document_details,
initiator.and_then(|initiator| initiator.to_created_by()),
initiator.and_then(|initiator| initiator.to_created_by()),
- customers::generate_global_customer_id(&state.conf.cell_information.id),
+ id_type::GlobalCustomerId::generate(&state.conf.cell_information.id),
);
metrics::CUSTOMER_CREATED.add(1, &[]);
db.insert_customer(new_customer, key_store, storage_scheme)
@@ -2265,7 +2265,7 @@ pub async fn create_customer_if_not_exist<'a, F: Clone, R, D>(
.attach_printable("Unable to encrypt customer details")?,
);
- payment_data.payment_intent.customer_id = Some(customer.customer_id.clone());
+ payment_data.payment_intent.customer_id = Some(customer.get_id().clone());
Some(customer)
}
diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rs
index b3e499ed75..2c57d26803 100644
--- a/crates/router/src/core/payments/operations.rs
+++ b/crates/router/src/core/payments/operations.rs
@@ -350,12 +350,14 @@ pub trait Domain<F: Clone, R, D>: Send + Sync {
Ok(())
}
#[cfg(feature = "v1")]
+ #[allow(clippy::too_many_arguments)]
async fn create_payment_method(
&self,
_state: &SessionState,
_request: &R,
_platform: &domain::Platform,
_payment_data: &mut D,
+ _customer: Option<&domain::Customer>,
_business_profile: &domain::Profile,
_feature_config: &core_utils::FeatureConfig,
) -> RouterResult<()> {
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index edf3538642..7994c0c910 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -1035,7 +1035,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
.payment_intent
.customer_id
.as_ref()
- .is_some_and(|existing_id| existing_id != &cust.customer_id)
+ .is_some_and(|existing_id| existing_id != cust.get_id())
.then_some(errors::StorageError::ValueNotFound(
"Customer id mismatch between payment intent and request".to_string(),
))
@@ -1090,7 +1090,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
state
.store
.update_customer_by_customer_id_merchant_id(
- customer.customer_id.to_owned(),
+ customer.get_id().to_owned(),
customer.merchant_id.to_owned(),
customer,
updated_customer,
@@ -1111,6 +1111,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
req: &api::PaymentsRequest,
platform: &domain::Platform,
payment_data: &mut PaymentData<F>,
+ customer: Option<&domain::Customer>,
business_profile: &domain::Profile,
feature_config: &core_utils::FeatureConfig,
) -> RouterResult<()> {
@@ -1161,6 +1162,10 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
.ok_or(errors::ApiErrorResponse::MissingRequiredField {
field_name: "payment_method_data",
})?;
+ let customer =
+ customer.ok_or(errors::ApiErrorResponse::CustomerNotFound)?;
+ let global_customer_id =
+ customer.get_global_id().cloned().get_required_value("id")?;
match pm_transformers::create_payment_method_in_modular_service(
state,
@@ -1174,11 +1179,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
.address
.get_request_payment_method_billing()
.cloned(),
- payment_data
- .payment_intent
- .customer_id
- .clone()
- .get_required_value("customer_id")?,
+ global_customer_id,
business_profile.is_network_tokenization_enabled,
)
.await
diff --git a/crates/router/src/core/payments/operations/payment_confirm_external_vault_proxy.rs b/crates/router/src/core/payments/operations/payment_confirm_external_vault_proxy.rs
index 75ef8f104b..7f76920936 100644
--- a/crates/router/src/core/payments/operations/payment_confirm_external_vault_proxy.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm_external_vault_proxy.rs
@@ -639,6 +639,7 @@ impl<F: Clone + Send + Sync> Domain<F, PaymentsRequest, PaymentData<F>>
_req: &PaymentsRequest,
platform: &domain::Platform,
payment_data: &mut PaymentData<F>,
+ customer: Option<&domain::Customer>,
business_profile: &domain::Profile,
_feature_config: &core_utils::FeatureConfig,
) -> RouterResult<()> {
@@ -680,11 +681,11 @@ impl<F: Clone + Send + Sync> Domain<F, PaymentsRequest, PaymentData<F>>
return Ok(());
}
};
- let customer_id = payment_data
- .payment_intent
- .customer_id
- .clone()
- .get_required_value("customer_id")?;
+ let global_customer_id = customer
+ .ok_or(errors::ApiErrorResponse::CustomerNotFound)?
+ .get_global_id()
+ .cloned()
+ .get_required_value("id")?;
let payment_method = payment_data
.payment_attempt
.payment_method
@@ -758,7 +759,7 @@ impl<F: Clone + Send + Sync> Domain<F, PaymentsRequest, PaymentData<F>>
payment_method_type,
vault_card,
payment_data.address.get_payment_method_billing().cloned(),
- customer_id,
+ global_customer_id,
)
.await
{
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index 0703cb892d..288a3126e9 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -800,7 +800,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
)
.await?
.inspect(|cust| {
- payment_data.payment_intent.customer_id = Some(cust.customer_id.clone());
+ payment_data.payment_intent.customer_id = Some(cust.get_id().clone());
});
let op: PaymentCreateOperation<'a, F> = Box::new(self);
Ok((op, customer))
diff --git a/crates/router/src/core/payments/operations/payment_recurrence.rs b/crates/router/src/core/payments/operations/payment_recurrence.rs
index 27beb4e2ff..49ff73dcaa 100644
--- a/crates/router/src/core/payments/operations/payment_recurrence.rs
+++ b/crates/router/src/core/payments/operations/payment_recurrence.rs
@@ -433,7 +433,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
.payment_intent
.customer_id
.as_ref()
- .is_some_and(|existing_id| existing_id != &cust.customer_id)
+ .is_some_and(|existing_id| existing_id != cust.get_id())
.then_some(errors::StorageError::ValueNotFound(
"Customer id mismatch between payment intent and request".to_string(),
))
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index 0be232a5ba..52c0269dc8 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -639,7 +639,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
.payment_intent
.customer_id
.as_ref()
- .is_some_and(|existing_id| existing_id != &cust.customer_id)
+ .is_some_and(|existing_id| existing_id != cust.get_id())
.then_some(errors::StorageError::ValueNotFound(
"Customer id mismatch between payment intent and request".to_string(),
))
diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs
index 2d8a295540..229d9a1b9e 100644
--- a/crates/router/src/core/payments/tokenization.rs
+++ b/crates/router/src/core/payments/tokenization.rs
@@ -1320,13 +1320,17 @@ pub async fn save_in_locker_internal(
Some(api_models::payment_methods::PaymentMethodCreateData::BankDebit(
bank_debit_create_data,
)),
- ) => Box::pin(PmCards { state, provider }.add_bank_debit_to_locker(
- payment_method_request,
- bank_debit_create_data,
- provider.get_key_store(),
- &customer_id,
- customer_obj.get_global_customer_id().clone(),
- ))
+ ) => Box::pin(
+ PmCards { state, provider }.add_bank_debit_to_locker(
+ payment_method_request,
+ bank_debit_create_data,
+ provider.get_key_store(),
+ &customer_id,
+ customer_obj
+ .get_global_id()
+ .map(|id| id.get_string_repr().to_owned()),
+ ),
+ )
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Add Bank Debit Failed"),
@@ -1334,13 +1338,17 @@ pub async fn save_in_locker_internal(
None,
None,
Some(api_models::payment_methods::PaymentMethodCreateData::Wallet(wallet_create_data)),
- ) => Box::pin(PmCards { state, provider }.add_wallet_to_locker(
- payment_method_request,
- wallet_create_data,
- provider.get_key_store(),
- &customer_id,
- customer_obj.get_global_customer_id().clone(),
- ))
+ ) => Box::pin(
+ PmCards { state, provider }.add_wallet_to_locker(
+ payment_method_request,
+ wallet_create_data,
+ provider.get_key_store(),
+ &customer_id,
+ customer_obj
+ .get_global_id()
+ .map(|id| id.get_string_repr().to_owned()),
+ ),
+ )
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Add Wallet Failed"),
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 248239df5d..6c2b4f2b6c 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -80,6 +80,19 @@ use crate::{
utils::{OptionExt, ValueExt},
};
+#[cfg(feature = "v2")]
+fn get_customer_id_from_global_customer_id(
+ customer: &Option<domain::Customer>,
+) -> RouterResult<Option<common_utils::id_type::CustomerId>> {
+ let global_customer_id = customer.as_ref().map(|customer| customer.id.clone());
+
+ global_customer_id
+ .map(common_utils::id_type::CustomerId::try_from)
+ .transpose()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Invalid global customer generated, not able to convert to reference id")
+}
+
#[cfg(feature = "v2")]
pub async fn construct_router_data_to_update_calculated_tax<'a, F, T>(
state: &'a SessionState,
@@ -342,14 +355,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
.attach_printable("Failed while parsing value for ConnectorAuthType")?;
// TODO: Take Globalid and convert to connector reference id
- let customer_id = customer
- .to_owned()
- .map(|customer| common_utils::id_type::CustomerId::try_from(customer.id.clone()))
- .transpose()
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable(
- "Invalid global customer generated, not able to convert to reference id",
- )?;
+ let customer_id = get_customer_id_from_global_customer_id(customer)?;
let connector_customer_id =
payment_data.get_connector_customer_id(customer.as_ref(), merchant_connector_account);
@@ -619,14 +625,7 @@ pub async fn construct_external_vault_proxy_payment_router_data<'a>(
.attach_printable("Failed while parsing value for ConnectorAuthType")?;
// TODO: Take Globalid and convert to connector reference id
- let customer_id = customer
- .to_owned()
- .map(|customer| common_utils::id_type::CustomerId::try_from(customer.id.clone()))
- .transpose()
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable(
- "Invalid global customer generated, not able to convert to reference id",
- )?;
+ let customer_id = get_customer_id_from_global_customer_id(customer)?;
let connector_customer_id =
payment_data.get_connector_customer_id(customer.as_ref(), merchant_connector_account);
@@ -1037,14 +1036,7 @@ pub async fn construct_payment_router_data_for_capture<'a>(
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while parsing value for ConnectorAuthType")?;
- let customer_id = customer
- .to_owned()
- .map(|customer| common_utils::id_type::CustomerId::try_from(customer.id.clone()))
- .transpose()
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable(
- "Invalid global customer generated, not able to convert to reference id",
- )?;
+ let customer_id = get_customer_id_from_global_customer_id(customer)?;
let payment_method = payment_data.payment_attempt.payment_method_type;
@@ -1429,14 +1421,7 @@ pub async fn construct_router_data_for_cancel<'a>(
})?;
// TODO: Take Globalid and convert to connector reference id
- let customer_id = customer
- .to_owned()
- .map(|customer| common_utils::id_type::CustomerId::try_from(customer.id.clone()))
- .transpose()
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable(
- "Invalid global customer generated, not able to convert to reference id",
- )?;
+ let customer_id = get_customer_id_from_global_customer_id(customer)?;
let payment_intent = payment_data.get_payment_intent();
let attempt = payment_data.get_payment_attempt();
let connector_request_reference_id = payment_data
@@ -1513,14 +1498,7 @@ pub async fn construct_payment_router_data_for_sdk_session<'a>(
.attach_printable("Failed while parsing value for ConnectorAuthType")?;
// TODO: Take Globalid and convert to connector reference id
- let customer_id = customer
- .to_owned()
- .map(|customer| common_utils::id_type::CustomerId::try_from(customer.id.clone()))
- .transpose()
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable(
- "Invalid global customer generated, not able to convert to reference id",
- )?;
+ let customer_id = get_customer_id_from_global_customer_id(customer)?;
let billing_address = payment_data
.payment_intent
.billing_address
@@ -1719,14 +1697,7 @@ pub async fn construct_payment_router_data_for_setup_mandate<'a>(
.attach_printable("Failed while parsing value for ConnectorAuthType")?;
// TODO: Take Globalid and convert to connector reference id
- let customer_id = customer
- .to_owned()
- .map(|customer| common_utils::id_type::CustomerId::try_from(customer.id.clone()))
- .transpose()
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable(
- "Invalid global customer generated, not able to convert to reference id",
- )?;
+ let customer_id = get_customer_id_from_global_customer_id(customer)?;
let connector_customer_id = customer.as_ref().and_then(|customer| {
customer
diff --git a/crates/router/src/core/payout_link.rs b/crates/router/src/core/payout_link.rs
index f0bf66d22e..3b549da4f8 100644
--- a/crates/router/src/core/payout_link.rs
+++ b/crates/router/src/core/payout_link.rs
@@ -227,7 +227,7 @@ pub async fn initiate_payout_link(
client_secret: link_data.client_secret.clone(),
payout_link_id: payout_link.link_id,
payout_id: payout_link.primary_reference.clone(),
- customer_id: customer.customer_id,
+ customer_id: customer.get_id().clone(),
session_expiry: payout_link.expiry,
return_url: payout_link
.return_url
diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs
index b2384284e3..fbaf5ccaf2 100644
--- a/crates/router/src/core/payouts.rs
+++ b/crates/router/src/core/payouts.rs
@@ -788,7 +788,7 @@ pub async fn payouts_fulfill_core(
payout_data.customer_details.as_ref().map(|customer| {
#[cfg(feature = "v1")]
{
- customer.customer_id.clone()
+ customer.get_id().clone()
}
#[cfg(not(feature = "v1"))]
{
@@ -1256,7 +1256,7 @@ pub async fn call_connector_payout(
payout_data.customer_details.as_ref().map(|customer| {
#[cfg(feature = "v1")]
{
- customer.customer_id.clone()
+ customer.get_id().clone()
}
#[cfg(not(feature = "v1"))]
{
@@ -1428,7 +1428,7 @@ pub async fn create_recipient(
{
#[cfg(feature = "v1")]
{
- let customer_id = customer.customer_id.to_owned();
+ let customer_id = customer.get_id().to_owned();
payout_data.customer_details = Some(
db.update_customer_by_customer_id_merchant_id(
customer_id,
@@ -2470,7 +2470,7 @@ pub async fn create_recipient_disburse_account(
);
} else {
#[cfg(feature = "v1")]
- let customer_id = Some(customer_details.customer_id);
+ let customer_id = Some(customer_details.get_id().clone());
#[cfg(feature = "v2")]
let customer_id = customer_details.merchant_reference_id;
@@ -3044,7 +3044,7 @@ pub async fn payout_create_db_entries(
) -> RouterResult<PayoutData> {
let db = &*state.store;
let merchant_id = platform.get_processor().get_account().get_id();
- let customer_id = customer.map(|cust| cust.customer_id.clone());
+ let customer_id = customer.map(|cust| cust.get_id().clone());
// Validate whether profile_id passed in request is valid and is linked to the merchant
let business_profile =
@@ -3435,7 +3435,7 @@ pub async fn make_payout_data(
Some(payout_token) => {
let customer_id = customer_details
.as_ref()
- .map(|cd| cd.customer_id.to_owned())
+ .map(|cd| cd.get_id().to_owned())
.get_required_value("customer_id when payout_token is sent")?;
helpers::make_payout_method_data(
state,
@@ -3485,7 +3485,7 @@ pub async fn make_payout_data(
Some(source_bank_data_token) => {
let customer_id = customer_details
.as_ref()
- .map(|cd| cd.customer_id.to_owned())
+ .map(|cd| cd.get_id().to_owned())
.get_required_value("customer_id when payout_token is sent")?;
let source_bank_data =
helpers::SourceBankDataOperation::get_temp_source_bank_data(
diff --git a/crates/router/src/core/payouts/helpers.rs b/crates/router/src/core/payouts/helpers.rs
index 291baad992..df6e5c63ca 100644
--- a/crates/router/src/core/payouts/helpers.rs
+++ b/crates/router/src/core/payouts/helpers.rs
@@ -25,7 +25,6 @@ use crate::{
consts,
core::{
configs::dimension_state,
- customers,
errors::{self, RouterResult, StorageErrorExt},
payment_methods::{
cards,
@@ -1017,7 +1016,7 @@ pub(super) async fn get_or_create_customer_details(
platform
.get_initiator()
.and_then(|initiator| initiator.to_created_by()), // Same as created_by on creation
- customers::generate_global_customer_id(&state.conf.cell_information.id),
+ id_type::GlobalCustomerId::generate(&state.conf.cell_information.id),
);
Ok(Some(
@@ -1428,7 +1427,7 @@ pub async fn update_payouts_and_payout_attempt(
payout_data
.customer_details
.as_ref()
- .map(|customer| customer.customer_id.clone())
+ .map(|customer| customer.get_id().clone())
} else {
payout_data.payouts.customer_id.clone()
};
diff --git a/crates/router/src/core/payouts/transformers.rs b/crates/router/src/core/payouts/transformers.rs
index 90309a6a3f..a849a4fc58 100644
--- a/crates/router/src/core/payouts/transformers.rs
+++ b/crates/router/src/core/payouts/transformers.rs
@@ -75,7 +75,7 @@ impl
connector: payout_attempt.connector,
payout_type: payout.payout_type,
auto_fulfill: payout.auto_fulfill,
- customer_id: customer.as_ref().map(|cust| cust.customer_id.clone()),
+ customer_id: customer.as_ref().map(|cust| cust.get_id().clone()),
customer: customer.as_ref().map(|cust| cust.foreign_into()),
return_url: payout.return_url,
business_country: payout_attempt.business_country,
diff --git a/crates/router/src/core/payouts/validator.rs b/crates/router/src/core/payouts/validator.rs
index b0c8e6f7ff..33ad6522ff 100644
--- a/crates/router/src/core/payouts/validator.rs
+++ b/crates/router/src/core/payouts/validator.rs
@@ -190,7 +190,7 @@ pub async fn validate_create_request(
.clone()
.get_required_value("customer_id")?;
- utils::when(pm_customer_id != customer.customer_id, || {
+ utils::when(pm_customer_id != *customer.get_id(), || {
Err(report!(errors::ApiErrorResponse::InvalidRequestData {
message: "Payment method does not belong to this customer_id".to_string(),
})
@@ -221,7 +221,7 @@ pub async fn validate_create_request(
state,
req.payout_method_data.as_ref(),
Some(payout_token),
- &customer.customer_id,
+ customer.get_id(),
platform.get_processor().get_account().get_id(),
req.payout_type,
platform.get_processor().get_key_store(),
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index 650c7cb10b..df2fbe6a9e 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -242,12 +242,12 @@ pub async fn construct_payout_router_data<'a, F>(
let router_data = types::RouterData {
flow: PhantomData,
merchant_id: platform.get_processor().get_account().get_id().to_owned(),
- customer_id: customer_details.to_owned().map(|c| c.customer_id),
+ customer_id: customer_details.as_ref().map(|c| c.get_id().clone()),
tenant_id: state.tenant.tenant_id.clone(),
connector_customer: get_payout_connector_customer_id(
connector_data,
connector_customer_id.clone(),
- &customer_details.to_owned().map(|c| c.customer_id),
+ &customer_details.as_ref().map(|c| c.get_id().clone()),
&payout_data.payment_method,
&payout_data.payout_attempt,
)?,
@@ -282,7 +282,7 @@ pub async fn construct_payout_router_data<'a, F>(
customer_details: customer_details
.to_owned()
.map(|c| payments::CustomerDetails {
- customer_id: Some(c.customer_id),
+ customer_id: Some(c.get_id().clone()),
name: c.name.map(Encryptable::into_inner),
email: c.email.map(Email::from),
phone: c.phone.map(Encryptable::into_inner),
diff --git a/crates/router/src/routes/payment_methods/migrate.rs b/crates/router/src/routes/payment_methods/migrate.rs
index a23afc345e..27b0077e4e 100644
--- a/crates/router/src/routes/payment_methods/migrate.rs
+++ b/crates/router/src/routes/payment_methods/migrate.rs
@@ -460,12 +460,13 @@ impl MigrationBatch<EligibilityVerified> {
)
.await
{
- Ok(customer) => {
- customer.get_global_customer_id().clone().ok_or_else(|| {
+ Ok(customer) => customer
+ .get_global_id()
+ .map(|id| id.get_string_repr().to_owned())
+ .ok_or_else(|| {
"Customer global id is required for fingerprint migration"
.to_string()
- })
- }
+ }),
Err(error) => {
Err(format!("Failed to fetch customer record: {error:?}"))
}
diff --git a/crates/router/src/types/api/customers.rs b/crates/router/src/types/api/customers.rs
index d0fa059baa..28e26cd2a8 100644
--- a/crates/router/src/types/api/customers.rs
+++ b/crates/router/src/types/api/customers.rs
@@ -44,8 +44,9 @@ impl TryFrom<(domain::Customer, Option<payments::AddressDetails>)> for CustomerR
})
})
.transpose()?;
+ let customer_id = cust.get_id().clone();
Ok(Self(customers::CustomerResponse {
- customer_id: cust.customer_id,
+ customer_id,
name: cust.name,
email: cust.email,
phone: cust.phone,
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index 4264301cd9..2b904a3235 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -1986,7 +1986,7 @@ impl ForeignFrom<&domain::Customer> for payments::CustomerDetailsResponse {
impl ForeignFrom<&domain::Customer> for payments::CustomerDetailsResponse {
fn foreign_from(customer: &domain::Customer) -> Self {
Self {
- id: Some(customer.customer_id.clone()),
+ id: Some(customer.get_id().clone()),
name: customer
.name
.as_ref()
diff --git a/crates/storage_impl/src/customers.rs b/crates/storage_impl/src/customers.rs
index 3909a6cdaf..90695e842d 100644
--- a/crates/storage_impl/src/customers.rs
+++ b/crates/storage_impl/src/customers.rs
@@ -393,11 +393,12 @@ impl<T: DatabaseStore> domain::CustomerInterface for kv_router_store::KVRouterSt
storage_scheme: MerchantStorageScheme,
) -> CustomResult<domain::Customer, StorageError> {
let conn = pg_connection_write(self).await?;
+ let customer_id = customer_data.get_id().clone();
let key = PartitionKey::MerchantIdCustomerId {
merchant_id: &customer_data.merchant_id.clone(),
- customer_id: &customer_data.customer_id.clone(),
+ customer_id: &customer_id,
};
- let identifier = format!("cust_{}", customer_data.customer_id.get_string_repr());
+ let identifier = format!("cust_{}", customer_id.get_string_repr());
let mut new_customer = customer_data
.construct_new()
.await
diff --git a/crates/subscriptions/src/core/subscription_handler.rs b/crates/subscriptions/src/core/subscription_handler.rs
index 3293cfc663..f85606d276 100644
--- a/crates/subscriptions/src/core/subscription_handler.rs
+++ b/crates/subscriptions/src/core/subscription_handler.rs
@@ -146,9 +146,10 @@ impl<'a> SubscriptionHandler<'a> {
let merchant_id = platform.get_processor().get_account().get_id();
let db = state.store.as_ref();
+ let customer_id = customer.get_id().clone();
let updated_customer = db
.update_customer_by_customer_id_merchant_id(
- customer.customer_id.clone(),
+ customer_id,
merchant_id.clone(),
customer,
customer_update,