Skip to content

Commit

Permalink
feat(core): send customer_name to connectors when creating customer (
Browse files Browse the repository at this point in the history
  • Loading branch information
Narayanbhat166 authored Jan 22, 2024
1 parent 6c46e9c commit 7813cee
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 18 deletions.
2 changes: 1 addition & 1 deletion crates/router/src/connector/stax/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub struct StaxCustomerRequest {
#[serde(skip_serializing_if = "Option::is_none")]
email: Option<Email>,
#[serde(skip_serializing_if = "Option::is_none")]
firstname: Option<String>,
firstname: Option<Secret<String>>,
}

impl TryFrom<&types::ConnectorCustomerRouterData> for StaxCustomerRequest {
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/stripe/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ impl TryFrom<&types::ConnectorCustomerRouterData> for CustomerRequest {
description: item.request.description.to_owned(),
email: item.request.email.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(),
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/core/payments/flows/authorize_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl<F> TryFrom<&types::RouterData<F, types::PaymentsAuthorizeData, types::Payme
payment_method_data: data.request.payment_method_data.clone(),
description: None,
phone: None,
name: None,
name: data.request.customer_name.clone(),
preprocessing_id: data.preprocessing_id.clone(),
})
}
Expand Down
28 changes: 27 additions & 1 deletion crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub async fn construct_payment_router_data<'a, F, T>(
connector_id: &str,
merchant_account: &domain::MerchantAccount,
_key_store: &domain::MerchantKeyStore,
customer: &Option<domain::Customer>,
customer: &'a Option<domain::Customer>,
merchant_connector_account: &helpers::MerchantConnectorAccountType,
) -> RouterResult<types::RouterData<F, T, types::PaymentsResponseData>>
where
Expand Down Expand Up @@ -89,6 +89,7 @@ where
connector_name: connector_id.to_string(),
payment_data: payment_data.clone(),
state,
customer_data: customer,
};

let customer_id = customer.to_owned().map(|customer| customer.customer_id);
Expand Down Expand Up @@ -968,6 +969,7 @@ where
connector_name: String,
payment_data: PaymentData<F>,
state: &'a AppState,
customer_data: &'a Option<domain::Customer>,
}
impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthorizeData {
type Error = error_stack::Report<errors::ApiErrorResponse>;
Expand Down Expand Up @@ -1048,6 +1050,17 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
.as_ref()
.map(|surcharge_details| surcharge_details.final_amount)
.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 {
payment_method_data: payment_method_data.get_required_value("payment_method_data")?,
setup_future_usage: payment_data.payment_intent.setup_future_usage,
Expand All @@ -1062,6 +1075,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
currency: payment_data.currency,
browser_info,
email: payment_data.email,
customer_name,
payment_experience: payment_data.payment_attempt.payment_experience,
order_details,
order_category,
Expand Down Expand Up @@ -1354,6 +1368,17 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::SetupMandateRequ
.change_context(errors::ApiErrorResponse::InvalidDataValue {
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 {
currency: payment_data.currency,
confirm: true,
Expand All @@ -1368,6 +1393,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::SetupMandateRequ
setup_mandate_details: payment_data.setup_mandate,
router_return_url,
email: payment_data.email,
customer_name,
return_url: payment_data.payment_intent.return_url,
browser_info,
payment_method_type: attempt.payment_method_type,
Expand Down
18 changes: 4 additions & 14 deletions crates/router/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ pub struct PaymentsAuthorizeData {
/// ```
pub amount: i64,
pub email: Option<Email>,
pub customer_name: Option<Secret<String>>,
pub currency: storage_enums::Currency,
pub confirm: bool,
pub statement_descriptor_suffix: Option<String>,
Expand Down Expand Up @@ -461,7 +462,7 @@ pub struct ConnectorCustomerData {
pub description: Option<String>,
pub email: Option<Email>,
pub phone: Option<Secret<String>>,
pub name: Option<String>,
pub name: Option<Secret<String>>,
pub preprocessing_id: Option<String>,
pub payment_method_data: payments::PaymentMethodData,
}
Expand Down Expand Up @@ -586,6 +587,7 @@ pub struct SetupMandateRequestData {
pub router_return_url: Option<String>,
pub browser_info: Option<BrowserInformation>,
pub email: Option<Email>,
pub customer_name: Option<Secret<String>>,
pub return_url: Option<String>,
pub payment_method_type: Option<storage_enums::PaymentMethodType>,
pub request_incremental_authorization: bool,
Expand Down Expand Up @@ -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>>
for PaymentMethodTokenizationData
{
Expand Down Expand Up @@ -1411,6 +1400,7 @@ impl From<&SetupMandateRouterData> for PaymentsAuthorizeData {
setup_mandate_details: data.request.setup_mandate_details.clone(),
router_return_url: data.request.router_return_url.clone(),
email: data.request.email.clone(),
customer_name: data.request.customer_name.clone(),
amount: 0,
statement_descriptor: None,
capture_method: None,
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/types/api/verify_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl VerifyConnectorData {
types::PaymentsAuthorizeData {
payment_method_data: api::PaymentMethodData::Card(self.card_details.clone()),
email: None,
customer_name: None,
amount: 1000,
confirm: true,
currency: storage_enums::Currency::USD,
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/aci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData {
order_details: None,
order_category: None,
email: None,
customer_name: None,
session_token: None,
enrolled_for_3ds: false,
related_transaction_id: None,
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/adyen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ impl AdyenTest {
order_details: None,
order_category: None,
email: None,
customer_name: None,
payment_experience: None,
payment_method_type: None,
session_token: None,
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/bitpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
order_details: None,
order_category: None,
email: None,
customer_name: None,
payment_experience: None,
payment_method_type: None,
session_token: None,
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/cashtocode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl CashtocodeTest {
order_details: None,
order_category: None,
email: None,
customer_name: None,
payment_experience: None,
payment_method_type,
session_token: None,
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
order_details: None,
order_category: None,
email: None,
customer_name: None,
payment_experience: None,
payment_method_type: None,
session_token: None,
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/cryptopay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
order_details: None,
order_category: None,
email: None,
customer_name: None,
payment_experience: None,
payment_method_type: None,
session_token: None,
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/opennode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
order_details: None,
order_category: None,
email: None,
customer_name: None,
payment_experience: None,
payment_method_type: None,
session_token: None,
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ impl Default for PaymentAuthorizeType {
order_details: None,
order_category: None,
email: None,
customer_name: None,
session_token: None,
enrolled_for_3ds: false,
related_transaction_id: None,
Expand Down
1 change: 1 addition & 0 deletions crates/router/tests/connectors/worldline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl WorldlineTest {
order_details: None,
order_category: None,
email: None,
customer_name: None,
session_token: None,
enrolled_for_3ds: false,
related_transaction_id: None,
Expand Down

0 comments on commit 7813cee

Please sign in to comment.