Skip to content

Commit

Permalink
fix(payment_methods): set requires_cvv to false when either `connec…
Browse files Browse the repository at this point in the history
…tor_mandate_details` or `network_transaction_id` is present during MITs (#5331)
  • Loading branch information
ShankarSinghC authored Jul 16, 2024
1 parent 23bfceb commit 29f8732
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
24 changes: 22 additions & 2 deletions crates/router/src/core/payment_methods/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3744,6 +3744,11 @@ pub async fn list_customer_payment_method(
)
.await?;

let is_connector_agnostic_mit_enabled = business_profile
.as_ref()
.and_then(|business_profile| business_profile.is_connector_agnostic_mit_enabled)
.unwrap_or(false);

for pm in resp.into_iter() {
let parent_payment_method_token = generate_id(consts::ID_LENGTH, "token");

Expand Down Expand Up @@ -3861,9 +3866,20 @@ pub async fn list_customer_payment_method(
state,
&key_store,
&merchant_account.merchant_id,
is_connector_agnostic_mit_enabled,
connector_mandate_details,
pm.network_transaction_id.as_ref(),
)
.await?;

let requires_cvv = if is_connector_agnostic_mit_enabled {
requires_cvv
&& !(off_session_payment_flag
&& (pm.connector_mandate_details.is_some()
|| pm.network_transaction_id.is_some()))
} else {
requires_cvv && !(off_session_payment_flag && pm.connector_mandate_details.is_some())
};
// Need validation for enabled payment method ,querying MCA
let pma = api::CustomerPaymentMethod {
payment_token: parent_payment_method_token.to_owned(),
Expand All @@ -3883,8 +3899,7 @@ pub async fn list_customer_payment_method(
bank_transfer: payment_method_retrieval_context.bank_transfer_details,
bank: bank_details,
surcharge_details: None,
requires_cvv: requires_cvv
&& !(off_session_payment_flag && pm.connector_mandate_details.is_some()),
requires_cvv,
last_used_at: Some(pm.last_used_at),
default_payment_method_set: customer.default_payment_method_id.is_some()
&& customer.default_payment_method_id == Some(pm.payment_method_id),
Expand Down Expand Up @@ -3982,8 +3997,13 @@ pub async fn get_mca_status(
state: &routes::SessionState,
key_store: &domain::MerchantKeyStore,
merchant_id: &str,
is_connector_agnostic_mit_enabled: bool,
connector_mandate_details: Option<storage::PaymentsMandateReference>,
network_transaction_id: Option<&String>,
) -> errors::RouterResult<bool> {
if is_connector_agnostic_mit_enabled && network_transaction_id.is_some() {
return Ok(true);
}
if let Some(connector_mandate_details) = connector_mandate_details {
let mcas = state
.store
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3503,7 +3503,8 @@ pub async fn decide_multiplex_connector_for_normal_or_recurring_payment<F: Clone
let merchant_connector_id = connector_data
.merchant_connector_id
.as_ref()
.ok_or(errors::ApiErrorResponse::InternalServerError)?;
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to find the merchant connector id")?;

if is_network_transaction_id_flow(
state,
Expand Down

0 comments on commit 29f8732

Please sign in to comment.