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 @@ -431,6 +431,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 @@ -466,13 +467,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 @@ -582,6 +582,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 @@ -615,6 +616,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 @@ -181,6 +181,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 @@ -191,6 +193,7 @@ where
&mut frm_info,
&customer,
&mut should_continue_transaction,
&mut should_continue_capture,
key_store.clone(),
)
.await?
Expand All @@ -199,12 +202,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 @@ -233,6 +249,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 @@ -284,6 +304,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 @@ -311,6 +335,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 @@ -996,6 +1024,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 @@ -1172,7 +1201,7 @@ where
merchant_account.storage_scheme,
updated_customer,
key_store,
None,
frm_suggestion,
header_payload,
)
.await?;
Expand Down Expand Up @@ -2109,6 +2138,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