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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(router): [V2] Return connector customer reference IDs in `CustomerResponse` (#7319)
Anurag Thakuraedf460c7016
diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.jsonindex a2440cfccd..9467ac0820 100644--- a/api-reference-v2/openapi_spec.json+++ b/api-reference-v2/openapi_spec.json@@ -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",diff --git a/crates/api_models/Cargo.toml b/crates/api_models/Cargo.tomlindex 2b84c50bba..f89558e626 100644--- a/crates/api_models/Cargo.toml+++ b/crates/api_models/Cargo.toml@@ -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 = []diff --git a/crates/api_models/src/customers.rs b/crates/api_models/src/customers.rsindex d78564ae53..eb61cae6e4 100644--- a/crates/api_models/src/customers.rs+++ b/crates/api_models/src/customers.rs@@ -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,diff --git a/crates/common_types/src/customers.rs b/crates/common_types/src/customers.rsnew file mode 100644index 0000000000..1d53630cad--- /dev/null+++ b/crates/common_types/src/customers.rs@@ -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+ }+}diff --git a/crates/common_types/src/lib.rs b/crates/common_types/src/lib.rsindex 4d3d2380e2..589a77e3a5 100644--- a/crates/common_types/src/lib.rs+++ b/crates/common_types/src/lib.rs@@ -2,6 +2,7 @@#![warn(missing_docs, missing_debug_implementations)]+pub mod customers;pub mod domain;pub mod payment_methods;pub mod payments;diff --git a/crates/diesel_models/src/customers.rs b/crates/diesel_models/src/customers.rsindex b0d4535ddb..24fe34c15d 100644--- a/crates/diesel_models/src/customers.rs+++ b/crates/diesel_models/src/customers.rs@@ -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- }-}diff --git a/crates/hyperswitch_domain_models/src/customer.rs b/crates/hyperswitch_domain_models/src/customer.rsindex 02c25d722c..384bc5ab42 100644--- a/crates/hyperswitch_domain_models/src/customer.rs+++ b/crates/hyperswitch_domain_models/src/customer.rs@@ -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>>,diff --git a/crates/router/src/types/api/customers.rs b/crates/router/src/types/api/customers.rsindex 5b37fb2add..63ebfe4993 100644--- a/crates/router/src/types/api/customers.rs+++ b/crates/router/src/types/api/customers.rs@@ -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,