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

fix(frm): update FRM manual review flow #3176

Merged
merged 7 commits into from
Jan 19, 2024
10 changes: 6 additions & 4 deletions crates/router/src/core/fraud_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ pub async fn pre_payment_frm_core<'a, F>(
frm_configs: FrmConfigsObject,
customer: &Option<domain::Customer>,
should_continue_transaction: &mut bool,
should_continue_capture: &mut bool,
key_store: domain::MerchantKeyStore,
) -> RouterResult<Option<FrmData>>
where
Expand Down Expand Up @@ -467,13 +468,12 @@ where
.await?;
let frm_fraud_check = frm_data_updated.fraud_check.clone();
payment_data.frm_message = Some(frm_fraud_check.clone());
if matches!(frm_fraud_check.frm_status, FraudCheckStatus::Fraud)
//DontTakeAction
{
*should_continue_transaction = false;
if matches!(frm_fraud_check.frm_status, FraudCheckStatus::Fraud) {
if matches!(frm_configs.frm_action, api_enums::FrmAction::CancelTxn) {
*should_continue_transaction = false;
frm_info.suggested_action = Some(FrmSuggestion::FrmCancelTransaction);
} else if matches!(frm_configs.frm_action, api_enums::FrmAction::ManualReview) {
*should_continue_capture = false;
frm_info.suggested_action = Some(FrmSuggestion::FrmManualReview);
}
}
Expand Down Expand Up @@ -583,6 +583,7 @@ pub async fn call_frm_before_connector_call<'a, F, Req, Ctx>(
frm_info: &mut Option<FrmInfo<F>>,
customer: &Option<domain::Customer>,
should_continue_transaction: &mut bool,
should_continue_capture: &mut bool,
key_store: domain::MerchantKeyStore,
) -> RouterResult<Option<FrmConfigsObject>>
where
Expand Down Expand Up @@ -616,6 +617,7 @@ where
frm_configs,
customer,
should_continue_transaction,
should_continue_capture,
key_store,
)
.await?;
Expand Down
36 changes: 33 additions & 3 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ where
#[allow(unused_variables, unused_mut)]
let mut should_continue_transaction: bool = true;
#[cfg(feature = "frm")]
let mut should_continue_capture: bool = true;
#[cfg(feature = "frm")]
let frm_configs = if state.conf.frm.enabled {
frm_core::call_frm_before_connector_call(
db,
Expand All @@ -190,6 +192,7 @@ where
&mut frm_info,
&customer,
&mut should_continue_transaction,
&mut should_continue_capture,
key_store.clone(),
)
.await?
Expand All @@ -198,12 +201,25 @@ where
};
#[cfg(feature = "frm")]
logger::debug!(
"should_cancel_transaction: {:?} {:?} ",
"frm_configs: {:?}\nshould_cancel_transaction: {:?}\nshould_continue_capture: {:?}",
frm_configs,
should_continue_transaction
should_continue_transaction,
should_continue_capture,
);

if should_continue_transaction {
#[cfg(feature = "frm")]
match (
should_continue_capture,
payment_data.payment_attempt.capture_method,
) {
(false, Some(storage_enums::CaptureMethod::Automatic))
| (false, Some(storage_enums::CaptureMethod::Scheduled)) => {
payment_data.payment_attempt.capture_method =
Some(storage_enums::CaptureMethod::Manual);
}
_ => (),
};
payment_data = match connector_details {
api::ConnectorCallType::PreDetermined(connector) => {
let schedule_time = if should_add_task_to_process_tracker {
Expand Down Expand Up @@ -232,6 +248,10 @@ where
&validate_result,
schedule_time,
header_payload,
#[cfg(feature = "frm")]
frm_info.as_ref().and_then(|fi| fi.suggested_action),
#[cfg(not(feature = "frm"))]
None,
)
.await?;
let operation = Box::new(PaymentResponse);
Expand Down Expand Up @@ -283,6 +303,10 @@ where
&validate_result,
schedule_time,
header_payload,
#[cfg(feature = "frm")]
frm_info.as_ref().and_then(|fi| fi.suggested_action),
#[cfg(not(feature = "frm"))]
None,
)
.await?;

Expand Down Expand Up @@ -310,6 +334,10 @@ where
&customer,
&validate_result,
schedule_time,
#[cfg(feature = "frm")]
frm_info.as_ref().and_then(|fi| fi.suggested_action),
#[cfg(not(feature = "frm"))]
None,
)
.await?;
};
Expand Down Expand Up @@ -994,6 +1022,7 @@ pub async fn call_connector_service<F, RouterDReq, ApiRequest, Ctx>(
validate_result: &operations::ValidateResult<'_>,
schedule_time: Option<time::PrimitiveDateTime>,
header_payload: HeaderPayload,
frm_suggestion: Option<storage_enums::FrmSuggestion>,
) -> RouterResult<router_types::RouterData<F, RouterDReq, router_types::PaymentsResponseData>>
where
F: Send + Clone + Sync,
Expand Down Expand Up @@ -1169,7 +1198,7 @@ where
merchant_account.storage_scheme,
updated_customer,
key_store,
None,
frm_suggestion,
header_payload,
)
.await?;
Expand Down Expand Up @@ -2077,6 +2106,7 @@ pub fn should_call_connector<Op: Debug, F: Clone>(
}
"CompleteAuthorize" => true,
"PaymentApprove" => true,
"PaymentReject" => true,
"PaymentSession" => true,
"PaymentIncrementalAuthorization" => matches!(
payment_data.payment_intent.status,
Expand Down
Loading
Loading