mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	feat(core): send customer_name to connectors when creating customer (#3380)
				
					
				
			This commit is contained in:
		| @ -147,7 +147,7 @@ pub struct StaxCustomerRequest { | |||||||
|     #[serde(skip_serializing_if = "Option::is_none")] |     #[serde(skip_serializing_if = "Option::is_none")] | ||||||
|     email: Option<Email>, |     email: Option<Email>, | ||||||
|     #[serde(skip_serializing_if = "Option::is_none")] |     #[serde(skip_serializing_if = "Option::is_none")] | ||||||
|     firstname: Option<String>, |     firstname: Option<Secret<String>>, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl TryFrom<&types::ConnectorCustomerRouterData> for StaxCustomerRequest { | impl TryFrom<&types::ConnectorCustomerRouterData> for StaxCustomerRequest { | ||||||
|  | |||||||
| @ -2018,7 +2018,7 @@ impl TryFrom<&types::ConnectorCustomerRouterData> for CustomerRequest { | |||||||
|             description: item.request.description.to_owned(), |             description: item.request.description.to_owned(), | ||||||
|             email: item.request.email.to_owned(), |             email: item.request.email.to_owned(), | ||||||
|             phone: item.request.phone.to_owned(), |             phone: item.request.phone.to_owned(), | ||||||
|             name: item.request.name.to_owned().map(Secret::new), |             name: item.request.name.to_owned(), | ||||||
|             source: item.request.preprocessing_id.to_owned(), |             source: item.request.preprocessing_id.to_owned(), | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -376,7 +376,7 @@ impl<F> TryFrom<&types::RouterData<F, types::PaymentsAuthorizeData, types::Payme | |||||||
|             payment_method_data: data.request.payment_method_data.clone(), |             payment_method_data: data.request.payment_method_data.clone(), | ||||||
|             description: None, |             description: None, | ||||||
|             phone: None, |             phone: None, | ||||||
|             name: None, |             name: data.request.customer_name.clone(), | ||||||
|             preprocessing_id: data.preprocessing_id.clone(), |             preprocessing_id: data.preprocessing_id.clone(), | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -34,7 +34,7 @@ pub async fn construct_payment_router_data<'a, F, T>( | |||||||
|     connector_id: &str, |     connector_id: &str, | ||||||
|     merchant_account: &domain::MerchantAccount, |     merchant_account: &domain::MerchantAccount, | ||||||
|     _key_store: &domain::MerchantKeyStore, |     _key_store: &domain::MerchantKeyStore, | ||||||
|     customer: &Option<domain::Customer>, |     customer: &'a Option<domain::Customer>, | ||||||
|     merchant_connector_account: &helpers::MerchantConnectorAccountType, |     merchant_connector_account: &helpers::MerchantConnectorAccountType, | ||||||
| ) -> RouterResult<types::RouterData<F, T, types::PaymentsResponseData>> | ) -> RouterResult<types::RouterData<F, T, types::PaymentsResponseData>> | ||||||
| where | where | ||||||
| @ -89,6 +89,7 @@ where | |||||||
|         connector_name: connector_id.to_string(), |         connector_name: connector_id.to_string(), | ||||||
|         payment_data: payment_data.clone(), |         payment_data: payment_data.clone(), | ||||||
|         state, |         state, | ||||||
|  |         customer_data: customer, | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     let customer_id = customer.to_owned().map(|customer| customer.customer_id); |     let customer_id = customer.to_owned().map(|customer| customer.customer_id); | ||||||
| @ -968,6 +969,7 @@ where | |||||||
|     connector_name: String, |     connector_name: String, | ||||||
|     payment_data: PaymentData<F>, |     payment_data: PaymentData<F>, | ||||||
|     state: &'a AppState, |     state: &'a AppState, | ||||||
|  |     customer_data: &'a Option<domain::Customer>, | ||||||
| } | } | ||||||
| impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthorizeData { | impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthorizeData { | ||||||
|     type Error = error_stack::Report<errors::ApiErrorResponse>; |     type Error = error_stack::Report<errors::ApiErrorResponse>; | ||||||
| @ -1048,6 +1050,17 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz | |||||||
|             .as_ref() |             .as_ref() | ||||||
|             .map(|surcharge_details| surcharge_details.final_amount) |             .map(|surcharge_details| surcharge_details.final_amount) | ||||||
|             .unwrap_or(payment_data.amount.into()); |             .unwrap_or(payment_data.amount.into()); | ||||||
|  |  | ||||||
|  |         let customer_name = additional_data | ||||||
|  |             .customer_data | ||||||
|  |             .as_ref() | ||||||
|  |             .and_then(|customer_data| { | ||||||
|  |                 customer_data | ||||||
|  |                     .name | ||||||
|  |                     .as_ref() | ||||||
|  |                     .map(|customer| customer.clone().into_inner()) | ||||||
|  |             }); | ||||||
|  |  | ||||||
|         Ok(Self { |         Ok(Self { | ||||||
|             payment_method_data: payment_method_data.get_required_value("payment_method_data")?, |             payment_method_data: payment_method_data.get_required_value("payment_method_data")?, | ||||||
|             setup_future_usage: payment_data.payment_intent.setup_future_usage, |             setup_future_usage: payment_data.payment_intent.setup_future_usage, | ||||||
| @ -1062,6 +1075,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz | |||||||
|             currency: payment_data.currency, |             currency: payment_data.currency, | ||||||
|             browser_info, |             browser_info, | ||||||
|             email: payment_data.email, |             email: payment_data.email, | ||||||
|  |             customer_name, | ||||||
|             payment_experience: payment_data.payment_attempt.payment_experience, |             payment_experience: payment_data.payment_attempt.payment_experience, | ||||||
|             order_details, |             order_details, | ||||||
|             order_category, |             order_category, | ||||||
| @ -1354,6 +1368,17 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::SetupMandateRequ | |||||||
|             .change_context(errors::ApiErrorResponse::InvalidDataValue { |             .change_context(errors::ApiErrorResponse::InvalidDataValue { | ||||||
|                 field_name: "browser_info", |                 field_name: "browser_info", | ||||||
|             })?; |             })?; | ||||||
|  |  | ||||||
|  |         let customer_name = additional_data | ||||||
|  |             .customer_data | ||||||
|  |             .as_ref() | ||||||
|  |             .and_then(|customer_data| { | ||||||
|  |                 customer_data | ||||||
|  |                     .name | ||||||
|  |                     .as_ref() | ||||||
|  |                     .map(|customer| customer.clone().into_inner()) | ||||||
|  |             }); | ||||||
|  |  | ||||||
|         Ok(Self { |         Ok(Self { | ||||||
|             currency: payment_data.currency, |             currency: payment_data.currency, | ||||||
|             confirm: true, |             confirm: true, | ||||||
| @ -1368,6 +1393,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::SetupMandateRequ | |||||||
|             setup_mandate_details: payment_data.setup_mandate, |             setup_mandate_details: payment_data.setup_mandate, | ||||||
|             router_return_url, |             router_return_url, | ||||||
|             email: payment_data.email, |             email: payment_data.email, | ||||||
|  |             customer_name, | ||||||
|             return_url: payment_data.payment_intent.return_url, |             return_url: payment_data.payment_intent.return_url, | ||||||
|             browser_info, |             browser_info, | ||||||
|             payment_method_type: attempt.payment_method_type, |             payment_method_type: attempt.payment_method_type, | ||||||
|  | |||||||
| @ -392,6 +392,7 @@ pub struct PaymentsAuthorizeData { | |||||||
|     /// ``` |     /// ``` | ||||||
|     pub amount: i64, |     pub amount: i64, | ||||||
|     pub email: Option<Email>, |     pub email: Option<Email>, | ||||||
|  |     pub customer_name: Option<Secret<String>>, | ||||||
|     pub currency: storage_enums::Currency, |     pub currency: storage_enums::Currency, | ||||||
|     pub confirm: bool, |     pub confirm: bool, | ||||||
|     pub statement_descriptor_suffix: Option<String>, |     pub statement_descriptor_suffix: Option<String>, | ||||||
| @ -461,7 +462,7 @@ pub struct ConnectorCustomerData { | |||||||
|     pub description: Option<String>, |     pub description: Option<String>, | ||||||
|     pub email: Option<Email>, |     pub email: Option<Email>, | ||||||
|     pub phone: Option<Secret<String>>, |     pub phone: Option<Secret<String>>, | ||||||
|     pub name: Option<String>, |     pub name: Option<Secret<String>>, | ||||||
|     pub preprocessing_id: Option<String>, |     pub preprocessing_id: Option<String>, | ||||||
|     pub payment_method_data: payments::PaymentMethodData, |     pub payment_method_data: payments::PaymentMethodData, | ||||||
| } | } | ||||||
| @ -586,6 +587,7 @@ pub struct SetupMandateRequestData { | |||||||
|     pub router_return_url: Option<String>, |     pub router_return_url: Option<String>, | ||||||
|     pub browser_info: Option<BrowserInformation>, |     pub browser_info: Option<BrowserInformation>, | ||||||
|     pub email: Option<Email>, |     pub email: Option<Email>, | ||||||
|  |     pub customer_name: Option<Secret<String>>, | ||||||
|     pub return_url: Option<String>, |     pub return_url: Option<String>, | ||||||
|     pub payment_method_type: Option<storage_enums::PaymentMethodType>, |     pub payment_method_type: Option<storage_enums::PaymentMethodType>, | ||||||
|     pub request_incremental_authorization: bool, |     pub request_incremental_authorization: bool, | ||||||
| @ -1342,19 +1344,6 @@ impl From<&&mut PaymentsAuthorizeRouterData> for AuthorizeSessionTokenData { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| impl From<&&mut PaymentsAuthorizeRouterData> for ConnectorCustomerData { |  | ||||||
|     fn from(data: &&mut PaymentsAuthorizeRouterData) -> Self { |  | ||||||
|         Self { |  | ||||||
|             email: data.request.email.to_owned(), |  | ||||||
|             preprocessing_id: data.preprocessing_id.to_owned(), |  | ||||||
|             payment_method_data: data.request.payment_method_data.to_owned(), |  | ||||||
|             description: None, |  | ||||||
|             phone: None, |  | ||||||
|             name: None, |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| impl<F> From<&RouterData<F, PaymentsAuthorizeData, PaymentsResponseData>> | impl<F> From<&RouterData<F, PaymentsAuthorizeData, PaymentsResponseData>> | ||||||
|     for PaymentMethodTokenizationData |     for PaymentMethodTokenizationData | ||||||
| { | { | ||||||
| @ -1411,6 +1400,7 @@ impl From<&SetupMandateRouterData> for PaymentsAuthorizeData { | |||||||
|             setup_mandate_details: data.request.setup_mandate_details.clone(), |             setup_mandate_details: data.request.setup_mandate_details.clone(), | ||||||
|             router_return_url: data.request.router_return_url.clone(), |             router_return_url: data.request.router_return_url.clone(), | ||||||
|             email: data.request.email.clone(), |             email: data.request.email.clone(), | ||||||
|  |             customer_name: data.request.customer_name.clone(), | ||||||
|             amount: 0, |             amount: 0, | ||||||
|             statement_descriptor: None, |             statement_descriptor: None, | ||||||
|             capture_method: None, |             capture_method: None, | ||||||
|  | |||||||
| @ -24,6 +24,7 @@ impl VerifyConnectorData { | |||||||
|         types::PaymentsAuthorizeData { |         types::PaymentsAuthorizeData { | ||||||
|             payment_method_data: api::PaymentMethodData::Card(self.card_details.clone()), |             payment_method_data: api::PaymentMethodData::Card(self.card_details.clone()), | ||||||
|             email: None, |             email: None, | ||||||
|  |             customer_name: None, | ||||||
|             amount: 1000, |             amount: 1000, | ||||||
|             confirm: true, |             confirm: true, | ||||||
|             currency: storage_enums::Currency::USD, |             currency: storage_enums::Currency::USD, | ||||||
|  | |||||||
| @ -59,6 +59,7 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData { | |||||||
|             order_details: None, |             order_details: None, | ||||||
|             order_category: None, |             order_category: None, | ||||||
|             email: None, |             email: None, | ||||||
|  |             customer_name: None, | ||||||
|             session_token: None, |             session_token: None, | ||||||
|             enrolled_for_3ds: false, |             enrolled_for_3ds: false, | ||||||
|             related_transaction_id: None, |             related_transaction_id: None, | ||||||
|  | |||||||
| @ -147,6 +147,7 @@ impl AdyenTest { | |||||||
|             order_details: None, |             order_details: None, | ||||||
|             order_category: None, |             order_category: None, | ||||||
|             email: None, |             email: None, | ||||||
|  |             customer_name: None, | ||||||
|             payment_experience: None, |             payment_experience: None, | ||||||
|             payment_method_type: None, |             payment_method_type: None, | ||||||
|             session_token: None, |             session_token: None, | ||||||
|  | |||||||
| @ -81,6 +81,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> { | |||||||
|         order_details: None, |         order_details: None, | ||||||
|         order_category: None, |         order_category: None, | ||||||
|         email: None, |         email: None, | ||||||
|  |         customer_name: None, | ||||||
|         payment_experience: None, |         payment_experience: None, | ||||||
|         payment_method_type: None, |         payment_method_type: None, | ||||||
|         session_token: None, |         session_token: None, | ||||||
|  | |||||||
| @ -57,6 +57,7 @@ impl CashtocodeTest { | |||||||
|             order_details: None, |             order_details: None, | ||||||
|             order_category: None, |             order_category: None, | ||||||
|             email: None, |             email: None, | ||||||
|  |             customer_name: None, | ||||||
|             payment_experience: None, |             payment_experience: None, | ||||||
|             payment_method_type, |             payment_method_type, | ||||||
|             session_token: None, |             session_token: None, | ||||||
|  | |||||||
| @ -83,6 +83,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> { | |||||||
|         order_details: None, |         order_details: None, | ||||||
|         order_category: None, |         order_category: None, | ||||||
|         email: None, |         email: None, | ||||||
|  |         customer_name: None, | ||||||
|         payment_experience: None, |         payment_experience: None, | ||||||
|         payment_method_type: None, |         payment_method_type: None, | ||||||
|         session_token: None, |         session_token: None, | ||||||
|  | |||||||
| @ -81,6 +81,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> { | |||||||
|         order_details: None, |         order_details: None, | ||||||
|         order_category: None, |         order_category: None, | ||||||
|         email: None, |         email: None, | ||||||
|  |         customer_name: None, | ||||||
|         payment_experience: None, |         payment_experience: None, | ||||||
|         payment_method_type: None, |         payment_method_type: None, | ||||||
|         session_token: None, |         session_token: None, | ||||||
|  | |||||||
| @ -82,6 +82,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> { | |||||||
|         order_details: None, |         order_details: None, | ||||||
|         order_category: None, |         order_category: None, | ||||||
|         email: None, |         email: None, | ||||||
|  |         customer_name: None, | ||||||
|         payment_experience: None, |         payment_experience: None, | ||||||
|         payment_method_type: None, |         payment_method_type: None, | ||||||
|         session_token: None, |         session_token: None, | ||||||
|  | |||||||
| @ -900,6 +900,7 @@ impl Default for PaymentAuthorizeType { | |||||||
|             order_details: None, |             order_details: None, | ||||||
|             order_category: None, |             order_category: None, | ||||||
|             email: None, |             email: None, | ||||||
|  |             customer_name: None, | ||||||
|             session_token: None, |             session_token: None, | ||||||
|             enrolled_for_3ds: false, |             enrolled_for_3ds: false, | ||||||
|             related_transaction_id: None, |             related_transaction_id: None, | ||||||
|  | |||||||
| @ -92,6 +92,7 @@ impl WorldlineTest { | |||||||
|             order_details: None, |             order_details: None, | ||||||
|             order_category: None, |             order_category: None, | ||||||
|             email: None, |             email: None, | ||||||
|  |             customer_name: None, | ||||||
|             session_token: None, |             session_token: None, | ||||||
|             enrolled_for_3ds: false, |             enrolled_for_3ds: false, | ||||||
|             related_transaction_id: None, |             related_transaction_id: None, | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Narayan Bhat
					Narayan Bhat