feat(router): [V2] Return connector customer reference IDs in CustomerResponse (#7319)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Anurag Thakur
2025-03-21 17:10:00 +05:30
committed by GitHub
parent c3c4f50fcf
commit aedf460c70
8 changed files with 47 additions and 35 deletions

View File

@ -8853,6 +8853,11 @@
"maxLength": 64, "maxLength": 64,
"minLength": 1 "minLength": 1
}, },
"connector_customer_ids": {
"type": "object",
"description": "Connector specific customer reference ids",
"nullable": true
},
"name": { "name": {
"type": "string", "type": "string",
"description": "The customer's name", "description": "The customer's name",

View File

@ -17,7 +17,7 @@ olap = []
openapi = ["common_enums/openapi", "olap", "recon", "dummy_connector", "olap"] openapi = ["common_enums/openapi", "olap", "recon", "dummy_connector", "olap"]
recon = [] recon = []
v1 = ["common_utils/v1"] v1 = ["common_utils/v1"]
v2 = ["common_utils/v2", "customer_v2"] v2 = ["common_types/v2", "common_utils/v2", "customer_v2"]
customer_v2 = ["common_utils/customer_v2"] customer_v2 = ["common_utils/customer_v2"]
payment_methods_v2 = ["common_utils/payment_methods_v2"] payment_methods_v2 = ["common_utils/payment_methods_v2"]
dynamic_routing = [] dynamic_routing = []

View File

@ -182,6 +182,9 @@ pub struct CustomerResponse {
/// The identifier for the customer object /// The identifier for the customer object
#[schema(value_type = String, max_length = 64, min_length = 1, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")] #[schema(value_type = String, max_length = 64, min_length = 1, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")]
pub merchant_reference_id: Option<id_type::CustomerId>, pub merchant_reference_id: Option<id_type::CustomerId>,
/// Connector specific customer reference ids
#[schema(value_type = Option<Object>, example = json!({"mca_hwySG2NtpzX0qr7toOy8": "cus_Rnm2pDKGyQi506"}))]
pub connector_customer_ids: Option<common_types::customers::ConnectorCustomerMap>,
/// The customer's name /// The customer's name
#[schema(max_length = 255, value_type = Option<String>, example = "Jon Test")] #[schema(max_length = 255, value_type = Option<String>, example = "Jon Test")]
pub name: crypto::OptionalEncryptableName, pub name: crypto::OptionalEncryptableName,

View File

@ -0,0 +1,30 @@
//! Customer related types
/// HashMap containing MerchantConnectorAccountId and corresponding customer id
#[cfg(feature = "v2")]
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, diesel::AsExpression)]
#[diesel(sql_type = diesel::sql_types::Jsonb)]
#[serde(transparent)]
pub struct ConnectorCustomerMap(
std::collections::HashMap<common_utils::id_type::MerchantConnectorAccountId, String>,
);
#[cfg(feature = "v2")]
common_utils::impl_to_sql_from_sql_json!(ConnectorCustomerMap);
#[cfg(feature = "v2")]
impl std::ops::Deref for ConnectorCustomerMap {
type Target =
std::collections::HashMap<common_utils::id_type::MerchantConnectorAccountId, String>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[cfg(feature = "v2")]
impl std::ops::DerefMut for ConnectorCustomerMap {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

View File

@ -2,6 +2,7 @@
#![warn(missing_docs, missing_debug_implementations)] #![warn(missing_docs, missing_debug_implementations)]
pub mod customers;
pub mod domain; pub mod domain;
pub mod payment_methods; pub mod payment_methods;
pub mod payments; pub mod payments;

View File

@ -76,7 +76,7 @@ pub struct CustomerNew {
pub description: Option<Description>, pub description: Option<Description>,
pub created_at: PrimitiveDateTime, pub created_at: PrimitiveDateTime,
pub metadata: Option<pii::SecretSerdeValue>, pub metadata: Option<pii::SecretSerdeValue>,
pub connector_customer: Option<ConnectorCustomerMap>, pub connector_customer: Option<common_types::customers::ConnectorCustomerMap>,
pub modified_at: PrimitiveDateTime, pub modified_at: PrimitiveDateTime,
pub default_payment_method_id: Option<common_utils::id_type::GlobalPaymentMethodId>, pub default_payment_method_id: Option<common_utils::id_type::GlobalPaymentMethodId>,
pub updated_by: Option<String>, pub updated_by: Option<String>,
@ -158,7 +158,7 @@ pub struct Customer {
pub description: Option<Description>, pub description: Option<Description>,
pub created_at: PrimitiveDateTime, pub created_at: PrimitiveDateTime,
pub metadata: Option<pii::SecretSerdeValue>, pub metadata: Option<pii::SecretSerdeValue>,
pub connector_customer: Option<ConnectorCustomerMap>, pub connector_customer: Option<common_types::customers::ConnectorCustomerMap>,
pub modified_at: PrimitiveDateTime, pub modified_at: PrimitiveDateTime,
pub default_payment_method_id: Option<common_utils::id_type::GlobalPaymentMethodId>, pub default_payment_method_id: Option<common_utils::id_type::GlobalPaymentMethodId>,
pub updated_by: Option<String>, pub updated_by: Option<String>,
@ -236,7 +236,7 @@ pub struct CustomerUpdateInternal {
pub phone_country_code: Option<String>, pub phone_country_code: Option<String>,
pub metadata: Option<pii::SecretSerdeValue>, pub metadata: Option<pii::SecretSerdeValue>,
pub modified_at: PrimitiveDateTime, pub modified_at: PrimitiveDateTime,
pub connector_customer: Option<ConnectorCustomerMap>, pub connector_customer: Option<common_types::customers::ConnectorCustomerMap>,
pub default_payment_method_id: Option<Option<common_utils::id_type::GlobalPaymentMethodId>>, pub default_payment_method_id: Option<Option<common_utils::id_type::GlobalPaymentMethodId>>,
pub updated_by: Option<String>, pub updated_by: Option<String>,
pub default_billing_address: Option<Encryption>, pub default_billing_address: Option<Encryption>,
@ -283,31 +283,3 @@ impl CustomerUpdateInternal {
} }
} }
} }
#[cfg(all(feature = "v2", feature = "customer_v2"))]
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, diesel::AsExpression)]
#[diesel(sql_type = diesel::sql_types::Jsonb)]
#[serde(transparent)]
pub struct ConnectorCustomerMap(
std::collections::HashMap<common_utils::id_type::MerchantConnectorAccountId, String>,
);
#[cfg(all(feature = "v2", feature = "customer_v2"))]
common_utils::impl_to_sql_from_sql_json!(ConnectorCustomerMap);
#[cfg(all(feature = "v2", feature = "customer_v2"))]
impl std::ops::Deref for ConnectorCustomerMap {
type Target =
std::collections::HashMap<common_utils::id_type::MerchantConnectorAccountId, String>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[cfg(all(feature = "v2", feature = "customer_v2"))]
impl std::ops::DerefMut for ConnectorCustomerMap {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

View File

@ -56,7 +56,7 @@ pub struct Customer {
pub description: Option<Description>, pub description: Option<Description>,
pub created_at: PrimitiveDateTime, pub created_at: PrimitiveDateTime,
pub metadata: Option<pii::SecretSerdeValue>, pub metadata: Option<pii::SecretSerdeValue>,
pub connector_customer: Option<diesel_models::ConnectorCustomerMap>, pub connector_customer: Option<common_types::customers::ConnectorCustomerMap>,
pub modified_at: PrimitiveDateTime, pub modified_at: PrimitiveDateTime,
pub default_payment_method_id: Option<id_type::GlobalPaymentMethodId>, pub default_payment_method_id: Option<id_type::GlobalPaymentMethodId>,
pub updated_by: Option<String>, pub updated_by: Option<String>,
@ -334,7 +334,7 @@ pub struct CustomerGeneralUpdate {
pub description: Option<Description>, pub description: Option<Description>,
pub phone_country_code: Option<String>, pub phone_country_code: Option<String>,
pub metadata: Option<pii::SecretSerdeValue>, pub metadata: Option<pii::SecretSerdeValue>,
pub connector_customer: Box<Option<diesel_models::ConnectorCustomerMap>>, pub connector_customer: Box<Option<common_types::customers::ConnectorCustomerMap>>,
pub default_billing_address: Option<Encryption>, pub default_billing_address: Option<Encryption>,
pub default_shipping_address: Option<Encryption>, pub default_shipping_address: Option<Encryption>,
pub default_payment_method_id: Option<Option<id_type::GlobalPaymentMethodId>>, pub default_payment_method_id: Option<Option<id_type::GlobalPaymentMethodId>>,
@ -346,7 +346,7 @@ pub struct CustomerGeneralUpdate {
pub enum CustomerUpdate { pub enum CustomerUpdate {
Update(Box<CustomerGeneralUpdate>), Update(Box<CustomerGeneralUpdate>),
ConnectorCustomer { ConnectorCustomer {
connector_customer: Option<diesel_models::ConnectorCustomerMap>, connector_customer: Option<common_types::customers::ConnectorCustomerMap>,
}, },
UpdateDefaultPaymentMethod { UpdateDefaultPaymentMethod {
default_payment_method_id: Option<Option<id_type::GlobalPaymentMethodId>>, default_payment_method_id: Option<Option<id_type::GlobalPaymentMethodId>>,

View File

@ -50,6 +50,7 @@ impl ForeignFrom<customer::Customer> for CustomerResponse {
customers::CustomerResponse { customers::CustomerResponse {
id: cust.id, id: cust.id,
merchant_reference_id: cust.merchant_reference_id, merchant_reference_id: cust.merchant_reference_id,
connector_customer_ids: cust.connector_customer,
name: cust.name, name: cust.name,
email: cust.email, email: cust.email,
phone: cust.phone, phone: cust.phone,