mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
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:
@ -8853,6 +8853,11 @@
|
||||
"maxLength": 64,
|
||||
"minLength": 1
|
||||
},
|
||||
"connector_customer_ids": {
|
||||
"type": "object",
|
||||
"description": "Connector specific customer reference ids",
|
||||
"nullable": true
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "The customer's name",
|
||||
|
||||
@ -17,7 +17,7 @@ olap = []
|
||||
openapi = ["common_enums/openapi", "olap", "recon", "dummy_connector", "olap"]
|
||||
recon = []
|
||||
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"]
|
||||
payment_methods_v2 = ["common_utils/payment_methods_v2"]
|
||||
dynamic_routing = []
|
||||
|
||||
@ -182,6 +182,9 @@ pub struct CustomerResponse {
|
||||
/// The identifier for the customer object
|
||||
#[schema(value_type = String, max_length = 64, min_length = 1, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")]
|
||||
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
|
||||
#[schema(max_length = 255, value_type = Option<String>, example = "Jon Test")]
|
||||
pub name: crypto::OptionalEncryptableName,
|
||||
|
||||
30
crates/common_types/src/customers.rs
Normal file
30
crates/common_types/src/customers.rs
Normal 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
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#![warn(missing_docs, missing_debug_implementations)]
|
||||
|
||||
pub mod customers;
|
||||
pub mod domain;
|
||||
pub mod payment_methods;
|
||||
pub mod payments;
|
||||
|
||||
@ -76,7 +76,7 @@ pub struct CustomerNew {
|
||||
pub description: Option<Description>,
|
||||
pub created_at: PrimitiveDateTime,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
pub connector_customer: Option<ConnectorCustomerMap>,
|
||||
pub connector_customer: Option<common_types::customers::ConnectorCustomerMap>,
|
||||
pub modified_at: PrimitiveDateTime,
|
||||
pub default_payment_method_id: Option<common_utils::id_type::GlobalPaymentMethodId>,
|
||||
pub updated_by: Option<String>,
|
||||
@ -158,7 +158,7 @@ pub struct Customer {
|
||||
pub description: Option<Description>,
|
||||
pub created_at: PrimitiveDateTime,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
pub connector_customer: Option<ConnectorCustomerMap>,
|
||||
pub connector_customer: Option<common_types::customers::ConnectorCustomerMap>,
|
||||
pub modified_at: PrimitiveDateTime,
|
||||
pub default_payment_method_id: Option<common_utils::id_type::GlobalPaymentMethodId>,
|
||||
pub updated_by: Option<String>,
|
||||
@ -236,7 +236,7 @@ pub struct CustomerUpdateInternal {
|
||||
pub phone_country_code: Option<String>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
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 updated_by: Option<String>,
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ pub struct Customer {
|
||||
pub description: Option<Description>,
|
||||
pub created_at: PrimitiveDateTime,
|
||||
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 default_payment_method_id: Option<id_type::GlobalPaymentMethodId>,
|
||||
pub updated_by: Option<String>,
|
||||
@ -334,7 +334,7 @@ pub struct CustomerGeneralUpdate {
|
||||
pub description: Option<Description>,
|
||||
pub phone_country_code: Option<String>,
|
||||
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_shipping_address: Option<Encryption>,
|
||||
pub default_payment_method_id: Option<Option<id_type::GlobalPaymentMethodId>>,
|
||||
@ -346,7 +346,7 @@ pub struct CustomerGeneralUpdate {
|
||||
pub enum CustomerUpdate {
|
||||
Update(Box<CustomerGeneralUpdate>),
|
||||
ConnectorCustomer {
|
||||
connector_customer: Option<diesel_models::ConnectorCustomerMap>,
|
||||
connector_customer: Option<common_types::customers::ConnectorCustomerMap>,
|
||||
},
|
||||
UpdateDefaultPaymentMethod {
|
||||
default_payment_method_id: Option<Option<id_type::GlobalPaymentMethodId>>,
|
||||
|
||||
@ -50,6 +50,7 @@ impl ForeignFrom<customer::Customer> for CustomerResponse {
|
||||
customers::CustomerResponse {
|
||||
id: cust.id,
|
||||
merchant_reference_id: cust.merchant_reference_id,
|
||||
connector_customer_ids: cust.connector_customer,
|
||||
name: cust.name,
|
||||
email: cust.email,
|
||||
phone: cust.phone,
|
||||
|
||||
Reference in New Issue
Block a user