Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(router): refactor ctp flow to fetch mca_id and get the connector creds instead of connector_name #6859

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ impl MerchantConnectorAccount {
pub fn get_id(&self) -> id_type::MerchantConnectorAccountId {
self.merchant_connector_id.clone()
}
pub fn get_connector_account_details(&self) -> Value {
self.connector_account_details.peek().to_owned()
}
pub fn get_connector_wallets_details(&self) -> Option<Secret<Value>> {
self.connector_wallets_details.as_deref().cloned()
}
}

#[cfg(feature = "v2")]
Expand Down
28 changes: 17 additions & 11 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,17 +386,23 @@ where
mandate_type,
)
.await?;
operation
.to_domain()?
.call_unified_authentication_service_if_eligible(
state,
&mut payment_data,
&mut should_continue_transaction,
&connector_details,
&business_profile,
&key_store,
)
.await?;

if let Some(ref authentication_product_ids) = business_profile.authentication_product_ids {
sahkal marked this conversation as resolved.
Show resolved Hide resolved
operation
.to_domain()?
.call_unified_authentication_service_if_eligible(
state,
&mut payment_data,
&mut should_continue_transaction,
&connector_details,
&business_profile,
&key_store,
authentication_product_ids,
)
.await?
} else {
tracing::info!("skipping unified authentication service call since no product authentication id's are present in business profile")
}

operation
.to_domain()?
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/payments/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ pub trait Domain<F: Clone, R, D>: Send + Sync {
Ok(())
}

#[allow(clippy::too_many_arguments)]
async fn call_unified_authentication_service_if_eligible<'a>(
&'a self,
_state: &SessionState,
Expand All @@ -303,6 +304,7 @@ pub trait Domain<F: Clone, R, D>: Send + Sync {
_connector_call_type: &ConnectorCallType,
_merchant_account: &domain::Profile,
_key_store: &domain::MerchantKeyStore,
_authentication_product_ids: &serde_json::Value,
) -> CustomResult<(), errors::ApiErrorResponse> {
Ok(())
}
Expand Down
67 changes: 41 additions & 26 deletions crates/router/src/core/payments/operations/payment_confirm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::marker::PhantomData;
use std::{collections::HashMap, marker::PhantomData};

// use api_models::{admin::ExtendedCardInfoConfig, enums::FrmSuggestion, payments::ExtendedCardInfo};
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
Expand Down Expand Up @@ -41,7 +41,7 @@ use crate::{
},
unified_authentication_service::{
self as uas_utils,
types::{ClickToPay, UnifiedAuthenticationService, CTP_MASTERCARD},
types::{ClickToPay, UnifiedAuthenticationService},
},
utils as core_utils,
},
Expand Down Expand Up @@ -1045,22 +1045,45 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
_connector_call_type: &ConnectorCallType,
business_profile: &domain::Profile,
key_store: &domain::MerchantKeyStore,
authentication_product_ids: &serde_json::Value,
) -> CustomResult<(), errors::ApiErrorResponse> {
if let Some(payment_method) = payment_data.payment_attempt.payment_method {
if payment_method == storage_enums::PaymentMethod::Card
&& business_profile.is_click_to_pay_enabled
{
let connector_name = CTP_MASTERCARD; // since the above checks satisfies the connector should be click to pay hence hardcoded the connector name
let connector_mca = helpers::get_merchant_connector_account(
state,
&business_profile.merchant_id,
None,
key_store,
business_profile.get_id(),
connector_name,
None,
)
.await?;
let authentication_product_ids: HashMap<
String,
common_utils::id_type::MerchantConnectorAccountId,
> = authentication_product_ids
.to_owned()
.parse_value("HashMap<String, MerchantConnectorAccountId>")
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Error while parsing authentication product ids")?;

sahkal marked this conversation as resolved.
Show resolved Hide resolved
let click_to_pay_mca_id = authentication_product_ids
.get(consts::CLICK_TO_PAY)
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable(
"Error while getting click_to_pay mca_id from business profile",
)?;

let key_manager_state = &(state).into();
let merchant_id = &business_profile.merchant_id;

let connector_mca = state
.store
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
key_manager_state,
merchant_id,
click_to_pay_mca_id,
key_store,
)
.await
.to_not_found_response(
errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
id: click_to_pay_mca_id.get_string_repr().to_string(),
},
)?;

let authentication_id =
common_utils::generate_id_with_default_len(consts::AUTHENTICATION_ID_PREFIX);
Expand All @@ -1071,21 +1094,13 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
},
)?;

let connector_transaction_id = connector_mca
.clone()
.get_mca_id()
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable(
"Error while finding mca_id from merchant_connector_account",
)?;

ClickToPay::pre_authentication(
state,
key_store,
business_profile,
payment_data,
&connector_mca,
connector_name,
&connector_mca.connector_name,
&authentication_id,
payment_method,
)
Expand All @@ -1099,7 +1114,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
business_profile,
payment_data,
&connector_mca,
connector_name,
&connector_mca.connector_name,
payment_method,
)
.await?;
Expand Down Expand Up @@ -1143,18 +1158,18 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
uas_utils::create_new_authentication(
state,
payment_data.payment_attempt.merchant_id.clone(),
connector_name.to_string(),
connector_mca.connector_name.to_string(),
business_profile.get_id().clone(),
Some(payment_data.payment_intent.get_id().clone()),
connector_transaction_id,
click_to_pay_mca_id.to_owned(),
&authentication_id,
payment_data.service_details.clone(),
authentication_status,
)
.await?;
}
}

tracing::debug!("skipping unified authentication service call since payment conditions {:?}, {:?} are not satisfied", payment_data.payment_attempt.payment_method, business_profile.is_click_to_pay_enabled);
Ok(())
sahkal marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
9 changes: 5 additions & 4 deletions crates/router/src/core/unified_authentication_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use hyperswitch_domain_models::{
},
};

use super::{errors::RouterResult, payments::helpers::MerchantConnectorAccountType};
use super::errors::RouterResult;
use crate::{
core::{
errors::utils::StorageErrorExt,
Expand All @@ -23,6 +23,7 @@ use crate::{
},
db::domain,
routes::SessionState,
types::domain::MerchantConnectorAccount,
};

#[cfg(feature = "v1")]
Expand All @@ -33,7 +34,7 @@ impl<F: Clone + Sync> UnifiedAuthenticationService<F> for ClickToPay {
_key_store: &domain::MerchantKeyStore,
_business_profile: &domain::Profile,
payment_data: &PaymentData<F>,
merchant_connector_account: &MerchantConnectorAccountType,
merchant_connector_account: &MerchantConnectorAccount,
connector_name: &str,
authentication_id: &str,
payment_method: common_enums::PaymentMethod,
Expand Down Expand Up @@ -67,7 +68,7 @@ impl<F: Clone + Sync> UnifiedAuthenticationService<F> for ClickToPay {
_key_store: &domain::MerchantKeyStore,
_business_profile: &domain::Profile,
payment_data: &PaymentData<F>,
merchant_connector_account: &MerchantConnectorAccountType,
merchant_connector_account: &MerchantConnectorAccount,
connector_name: &str,
payment_method: common_enums::PaymentMethod,
) -> RouterResult<hyperswitch_domain_models::types::UasPostAuthenticationRouterData> {
Expand Down Expand Up @@ -104,7 +105,7 @@ impl<F: Clone + Sync> UnifiedAuthenticationService<F> for ClickToPay {
_state: &SessionState,
_key_store: &domain::MerchantKeyStore,
_business_profile: &domain::Profile,
_merchant_connector_account: &MerchantConnectorAccountType,
_merchant_connector_account: &MerchantConnectorAccount,
) -> RouterResult<()> {
Ok(())
}
Expand Down
12 changes: 5 additions & 7 deletions crates/router/src/core/unified_authentication_service/types.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::{
core::{
errors::RouterResult,
payments::{helpers::MerchantConnectorAccountType, PaymentData},
},
core::{errors::RouterResult, payments::PaymentData},
db::domain,
routes::SessionState,
types::domain::MerchantConnectorAccount,
};

pub const CTP_MASTERCARD: &str = "ctp_mastercard";
Expand All @@ -27,7 +25,7 @@ pub trait UnifiedAuthenticationService<F: Clone + Sync> {
_key_store: &domain::MerchantKeyStore,
_business_profile: &domain::Profile,
_payment_data: &PaymentData<F>,
_merchant_connector_account: &MerchantConnectorAccountType,
_merchant_connector_account: &MerchantConnectorAccount,
_connector_name: &str,
_authentication_id: &str,
_payment_method: common_enums::PaymentMethod,
Expand All @@ -38,7 +36,7 @@ pub trait UnifiedAuthenticationService<F: Clone + Sync> {
_key_store: &domain::MerchantKeyStore,
_business_profile: &domain::Profile,
_payment_data: &PaymentData<F>,
_merchant_connector_account: &MerchantConnectorAccountType,
_merchant_connector_account: &MerchantConnectorAccount,
_connector_name: &str,
_payment_method: common_enums::PaymentMethod,
) -> RouterResult<hyperswitch_domain_models::types::UasPostAuthenticationRouterData>;
Expand All @@ -47,6 +45,6 @@ pub trait UnifiedAuthenticationService<F: Clone + Sync> {
_state: &SessionState,
_key_store: &domain::MerchantKeyStore,
_business_profile: &domain::Profile,
_merchant_connector_account: &MerchantConnectorAccountType,
_merchant_connector_account: &MerchantConnectorAccount,
) -> RouterResult<()>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ use crate::{
core::{
errors::{utils::ConnectorErrorExt, RouterResult},
payments,
unified_authentication_service::MerchantConnectorAccountType,
},
services::{self, execute_connector_processing_step},
types::api,
types::{api, domain::MerchantConnectorAccount},
SessionState,
};

Expand Down Expand Up @@ -108,10 +107,10 @@ pub fn construct_uas_router_data<F: Clone, Req, Res>(
merchant_id: common_utils::id_type::MerchantId,
address: Option<PaymentAddress>,
request_data: Req,
merchant_connector_account: &MerchantConnectorAccountType,
merchant_connector_account: &MerchantConnectorAccount,
authentication_id: Option<String>,
) -> RouterResult<RouterData<F, Req, Res>> {
let test_mode: Option<bool> = merchant_connector_account.is_test_mode_on();
let test_mode: Option<bool> = merchant_connector_account.test_mode;
let auth_type: ConnectorAuthType = merchant_connector_account
.get_connector_account_details()
.parse_value("ConnectorAuthType")
Expand All @@ -133,7 +132,7 @@ pub fn construct_uas_router_data<F: Clone, Req, Res>(
return_url: None,
address: address.unwrap_or_default(),
auth_type: common_enums::AuthenticationType::default(),
connector_meta_data: merchant_connector_account.get_metadata(),
connector_meta_data: merchant_connector_account.metadata.clone(),
connector_wallets_details: merchant_connector_account.get_connector_wallets_details(),
amount_captured: None,
minor_amount_captured: None,
Expand Down
Loading