mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
refactor: pass customer object to make_pm_data (#3246)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -244,12 +244,6 @@ impl TryFrom<String> for Email {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Secret<String, EmailStrategy>> for Email {
|
||||
fn from(value: Secret<String, EmailStrategy>) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::Deref for Email {
|
||||
type Target = Secret<String, EmailStrategy>;
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ use common_utils::{
|
||||
use error_stack::{report, FutureExt, IntoReport, ResultExt};
|
||||
use futures::future::try_join_all;
|
||||
use masking::{PeekInterface, Secret};
|
||||
use pm_auth::connector::plaid::transformers::PlaidAuthType;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
@ -1830,8 +1831,10 @@ pub(crate) fn validate_auth_and_metadata_type(
|
||||
riskified::transformers::RiskifiedAuthType::try_from(val)?;
|
||||
Ok(())
|
||||
}
|
||||
api_enums::Connector::Plaid => Err(report!(errors::ConnectorError::InvalidConnectorName)
|
||||
.attach_printable(format!("invalid connector name: {connector_name}"))),
|
||||
api_enums::Connector::Plaid => {
|
||||
PlaidAuthType::foreign_try_from(val)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -43,6 +43,7 @@ pub trait PaymentMethodRetrieve {
|
||||
token: &storage::PaymentTokenData,
|
||||
payment_intent: &PaymentIntent,
|
||||
card_token_data: Option<&CardToken>,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<Option<(payments::PaymentMethodData, enums::PaymentMethod)>>;
|
||||
}
|
||||
|
||||
@ -126,6 +127,7 @@ impl PaymentMethodRetrieve for Oss {
|
||||
token_data: &storage::PaymentTokenData,
|
||||
payment_intent: &PaymentIntent,
|
||||
card_token_data: Option<&CardToken>,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<Option<(payments::PaymentMethodData, enums::PaymentMethod)>> {
|
||||
match token_data {
|
||||
storage::PaymentTokenData::TemporaryGeneric(generic_token) => {
|
||||
@ -178,6 +180,7 @@ impl PaymentMethodRetrieve for Oss {
|
||||
merchant_key_store,
|
||||
auth_token,
|
||||
payment_intent,
|
||||
customer,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@ -166,6 +166,7 @@ where
|
||||
&mut payment_data,
|
||||
&validate_result,
|
||||
&key_store,
|
||||
&customer,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -1041,6 +1042,7 @@ where
|
||||
validate_result,
|
||||
&merchant_connector_account,
|
||||
key_store,
|
||||
customer,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -1754,6 +1756,7 @@ pub async fn get_connector_tokenization_action_when_confirm_true<F, Req, Ctx>(
|
||||
validate_result: &operations::ValidateResult<'_>,
|
||||
merchant_connector_account: &helpers::MerchantConnectorAccountType,
|
||||
merchant_key_store: &domain::MerchantKeyStore,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(PaymentData<F>, TokenizationAction)>
|
||||
where
|
||||
F: Send + Clone,
|
||||
@ -1821,6 +1824,7 @@ where
|
||||
payment_data,
|
||||
validate_result.storage_scheme,
|
||||
merchant_key_store,
|
||||
customer,
|
||||
)
|
||||
.await?;
|
||||
payment_data.payment_method_data = payment_method_data;
|
||||
@ -1836,6 +1840,7 @@ where
|
||||
payment_data,
|
||||
validate_result.storage_scheme,
|
||||
merchant_key_store,
|
||||
customer,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -1873,6 +1878,7 @@ pub async fn tokenize_in_router_when_confirm_false<F, Req, Ctx>(
|
||||
payment_data: &mut PaymentData<F>,
|
||||
validate_result: &operations::ValidateResult<'_>,
|
||||
merchant_key_store: &domain::MerchantKeyStore,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<PaymentData<F>>
|
||||
where
|
||||
F: Send + Clone,
|
||||
@ -1887,6 +1893,7 @@ where
|
||||
payment_data,
|
||||
validate_result.storage_scheme,
|
||||
merchant_key_store,
|
||||
customer,
|
||||
)
|
||||
.await?;
|
||||
payment_data.payment_method_data = payment_method_data;
|
||||
|
||||
@ -1532,6 +1532,7 @@ pub async fn make_pm_data<'a, F: Clone, R, Ctx: PaymentMethodRetrieve>(
|
||||
state: &'a AppState,
|
||||
payment_data: &mut PaymentData<F>,
|
||||
merchant_key_store: &domain::MerchantKeyStore,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'a, F, R, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
@ -1621,6 +1622,7 @@ pub async fn make_pm_data<'a, F: Clone, R, Ctx: PaymentMethodRetrieve>(
|
||||
&hyperswitch_token,
|
||||
&payment_data.payment_intent,
|
||||
card_token_data.as_ref(),
|
||||
customer,
|
||||
)
|
||||
.await
|
||||
.attach_printable("in 'make_pm_data'")?;
|
||||
|
||||
@ -131,6 +131,7 @@ pub trait Domain<F: Clone, R, Ctx: PaymentMethodRetrieve>: Send + Sync {
|
||||
payment_data: &mut PaymentData<F>,
|
||||
storage_scheme: enums::MerchantStorageScheme,
|
||||
merchant_key_store: &domain::MerchantKeyStore,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'a, F, R, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
@ -251,11 +252,19 @@ where
|
||||
payment_data: &mut PaymentData<F>,
|
||||
_storage_scheme: enums::MerchantStorageScheme,
|
||||
merchant_key_store: &domain::MerchantKeyStore,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'a, F, api::PaymentsRetrieveRequest, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
)> {
|
||||
helpers::make_pm_data(Box::new(self), state, payment_data, merchant_key_store).await
|
||||
helpers::make_pm_data(
|
||||
Box::new(self),
|
||||
state,
|
||||
payment_data,
|
||||
merchant_key_store,
|
||||
customer,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,6 +310,7 @@ where
|
||||
_payment_data: &mut PaymentData<F>,
|
||||
_storage_scheme: enums::MerchantStorageScheme,
|
||||
_merchant_key_store: &domain::MerchantKeyStore,
|
||||
_customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'a, F, api::PaymentsCaptureRequest, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
@ -363,6 +373,7 @@ where
|
||||
_payment_data: &mut PaymentData<F>,
|
||||
_storage_scheme: enums::MerchantStorageScheme,
|
||||
_merchant_key_store: &domain::MerchantKeyStore,
|
||||
_customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'a, F, api::PaymentsCancelRequest, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
@ -415,6 +426,7 @@ where
|
||||
_payment_data: &mut PaymentData<F>,
|
||||
_storage_scheme: enums::MerchantStorageScheme,
|
||||
_merchant_key_store: &domain::MerchantKeyStore,
|
||||
_customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'a, F, api::PaymentsRejectRequest, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
|
||||
@ -315,12 +315,19 @@ impl<F: Clone + Send, Ctx: PaymentMethodRetrieve> Domain<F, api::PaymentsRequest
|
||||
payment_data: &mut PaymentData<F>,
|
||||
_storage_scheme: storage_enums::MerchantStorageScheme,
|
||||
merchant_key_store: &domain::MerchantKeyStore,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'a, F, api::PaymentsRequest, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
)> {
|
||||
let (op, payment_method_data) =
|
||||
helpers::make_pm_data(Box::new(self), state, payment_data, merchant_key_store).await?;
|
||||
let (op, payment_method_data) = helpers::make_pm_data(
|
||||
Box::new(self),
|
||||
state,
|
||||
payment_data,
|
||||
merchant_key_store,
|
||||
customer,
|
||||
)
|
||||
.await?;
|
||||
|
||||
utils::when(payment_method_data.is_none(), || {
|
||||
Err(errors::ApiErrorResponse::PaymentMethodNotFound)
|
||||
|
||||
@ -311,12 +311,19 @@ impl<F: Clone + Send, Ctx: PaymentMethodRetrieve> Domain<F, api::PaymentsRequest
|
||||
payment_data: &mut PaymentData<F>,
|
||||
_storage_scheme: storage_enums::MerchantStorageScheme,
|
||||
merchant_key_store: &domain::MerchantKeyStore,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'a, F, api::PaymentsRequest, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
)> {
|
||||
let (op, payment_method_data) =
|
||||
helpers::make_pm_data(Box::new(self), state, payment_data, merchant_key_store).await?;
|
||||
let (op, payment_method_data) = helpers::make_pm_data(
|
||||
Box::new(self),
|
||||
state,
|
||||
payment_data,
|
||||
merchant_key_store,
|
||||
customer,
|
||||
)
|
||||
.await?;
|
||||
Ok((op, payment_method_data))
|
||||
}
|
||||
|
||||
|
||||
@ -527,12 +527,13 @@ impl<F: Clone + Send, Ctx: PaymentMethodRetrieve> Domain<F, api::PaymentsRequest
|
||||
payment_data: &mut PaymentData<F>,
|
||||
_storage_scheme: storage_enums::MerchantStorageScheme,
|
||||
key_store: &domain::MerchantKeyStore,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'a, F, api::PaymentsRequest, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
)> {
|
||||
let (op, payment_method_data) =
|
||||
helpers::make_pm_data(Box::new(self), state, payment_data, key_store).await?;
|
||||
helpers::make_pm_data(Box::new(self), state, payment_data, key_store, customer).await?;
|
||||
|
||||
utils::when(payment_method_data.is_none(), || {
|
||||
Err(errors::ApiErrorResponse::PaymentMethodNotFound)
|
||||
|
||||
@ -424,11 +424,19 @@ impl<F: Clone + Send, Ctx: PaymentMethodRetrieve> Domain<F, api::PaymentsRequest
|
||||
payment_data: &mut PaymentData<F>,
|
||||
_storage_scheme: enums::MerchantStorageScheme,
|
||||
merchant_key_store: &domain::MerchantKeyStore,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'a, F, api::PaymentsRequest, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
)> {
|
||||
helpers::make_pm_data(Box::new(self), state, payment_data, merchant_key_store).await
|
||||
helpers::make_pm_data(
|
||||
Box::new(self),
|
||||
state,
|
||||
payment_data,
|
||||
merchant_key_store,
|
||||
customer,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
|
||||
@ -312,6 +312,7 @@ where
|
||||
_payment_data: &mut PaymentData<F>,
|
||||
_storage_scheme: storage_enums::MerchantStorageScheme,
|
||||
_merchant_key_store: &domain::MerchantKeyStore,
|
||||
_customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'b, F, api::PaymentsSessionRequest, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
|
||||
@ -278,6 +278,7 @@ where
|
||||
payment_data: &mut PaymentData<F>,
|
||||
_storage_scheme: storage_enums::MerchantStorageScheme,
|
||||
merchant_key_store: &domain::MerchantKeyStore,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'a, F, api::PaymentsStartRequest, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
@ -289,7 +290,14 @@ where
|
||||
.map(|connector_name| connector_name == *"bluesnap".to_string())
|
||||
.unwrap_or(false)
|
||||
{
|
||||
helpers::make_pm_data(Box::new(self), state, payment_data, merchant_key_store).await
|
||||
helpers::make_pm_data(
|
||||
Box::new(self),
|
||||
state,
|
||||
payment_data,
|
||||
merchant_key_store,
|
||||
customer,
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
Ok((Box::new(self), None))
|
||||
}
|
||||
|
||||
@ -96,11 +96,19 @@ impl<F: Clone + Send, Ctx: PaymentMethodRetrieve> Domain<F, api::PaymentsRequest
|
||||
payment_data: &mut PaymentData<F>,
|
||||
_storage_scheme: enums::MerchantStorageScheme,
|
||||
merchant_key_store: &domain::MerchantKeyStore,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'a, F, api::PaymentsRequest, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
)> {
|
||||
helpers::make_pm_data(Box::new(self), state, payment_data, merchant_key_store).await
|
||||
helpers::make_pm_data(
|
||||
Box::new(self),
|
||||
state,
|
||||
payment_data,
|
||||
merchant_key_store,
|
||||
customer,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
|
||||
@ -428,11 +428,19 @@ impl<F: Clone + Send, Ctx: PaymentMethodRetrieve> Domain<F, api::PaymentsRequest
|
||||
payment_data: &mut PaymentData<F>,
|
||||
_storage_scheme: storage_enums::MerchantStorageScheme,
|
||||
merchant_key_store: &domain::MerchantKeyStore,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'a, F, api::PaymentsRequest, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
)> {
|
||||
helpers::make_pm_data(Box::new(self), state, payment_data, merchant_key_store).await
|
||||
helpers::make_pm_data(
|
||||
Box::new(self),
|
||||
state,
|
||||
payment_data,
|
||||
merchant_key_store,
|
||||
customer,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
|
||||
@ -309,6 +309,7 @@ impl<F: Clone + Send, Ctx: PaymentMethodRetrieve>
|
||||
_payment_data: &mut payments::PaymentData<F>,
|
||||
_storage_scheme: enums::MerchantStorageScheme,
|
||||
_merchant_key_store: &domain::MerchantKeyStore,
|
||||
_customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<(
|
||||
BoxedOperation<'a, F, PaymentsIncrementalAuthorizationRequest, Ctx>,
|
||||
Option<api::PaymentMethodData>,
|
||||
|
||||
@ -52,6 +52,7 @@ use crate::{
|
||||
storage,
|
||||
transformers::ForeignTryFrom,
|
||||
},
|
||||
utils::ext_traits::OptionExt,
|
||||
};
|
||||
|
||||
pub async fn create_link_token(
|
||||
@ -618,6 +619,7 @@ pub async fn retrieve_payment_method_from_auth_service(
|
||||
key_store: &domain::MerchantKeyStore,
|
||||
auth_token: &payment_methods::BankAccountConnectorDetails,
|
||||
payment_intent: &PaymentIntent,
|
||||
customer: &Option<domain::Customer>,
|
||||
) -> RouterResult<Option<(PaymentMethodData, enums::PaymentMethod)>> {
|
||||
let db = state.store.as_ref();
|
||||
|
||||
@ -710,10 +712,17 @@ pub async fn retrieve_payment_method_from_auth_service(
|
||||
last_name,
|
||||
}
|
||||
});
|
||||
|
||||
let email = customer
|
||||
.as_ref()
|
||||
.and_then(|customer| customer.email.clone())
|
||||
.map(common_utils::pii::Email::from)
|
||||
.get_required_value("email")?;
|
||||
|
||||
let payment_method_data = PaymentMethodData::BankDebit(BankDebitData::AchBankDebit {
|
||||
billing_details: BankDebitBilling {
|
||||
name: name.unwrap_or_default(),
|
||||
email: common_utils::pii::Email::from(masking::Secret::new("".to_string())),
|
||||
email,
|
||||
address: address_details,
|
||||
},
|
||||
account_number: masking::Secret::new(bank_account.account_number.clone()),
|
||||
|
||||
@ -458,7 +458,7 @@ pub trait ConnectorActions: Connector {
|
||||
customer_details: Some(payments::CustomerDetails {
|
||||
customer_id: core_utils::get_or_generate_id("customer_id", &None, "cust_").ok(),
|
||||
name: Some(Secret::new("John Doe".to_string())),
|
||||
email: TryFrom::try_from("john.doe@example".to_string()).ok(),
|
||||
email: Email::from_str("john.doe@example").ok(),
|
||||
phone: Some(Secret::new("620874518".to_string())),
|
||||
phone_country_code: Some("+31".to_string()),
|
||||
}),
|
||||
@ -996,7 +996,7 @@ impl Default for CustomerType {
|
||||
let data = types::ConnectorCustomerData {
|
||||
payment_method_data: types::api::PaymentMethodData::Card(CCardType::default().0),
|
||||
description: None,
|
||||
email: Some(Email::from(Secret::new("test@juspay.in".to_string()))),
|
||||
email: Email::from_str("test@juspay.in").ok(),
|
||||
phone: None,
|
||||
name: None,
|
||||
preprocessing_id: None,
|
||||
|
||||
Reference in New Issue
Block a user