mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 13:30:39 +08:00
refactor(FRM): refactor frm configs (#4581)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -25,7 +25,7 @@ use crate::{
|
||||
services::{self, api},
|
||||
types::{
|
||||
api::{
|
||||
enums::{AttemptStatus, FrmAction, IntentStatus},
|
||||
enums::{AttemptStatus, IntentStatus},
|
||||
fraud_check as frm_api, payments as payment_types, Capture, Void,
|
||||
},
|
||||
domain,
|
||||
@ -186,7 +186,7 @@ impl<F: Send + Clone> Domain<F> for FraudCheckPost {
|
||||
req_state: ReqState,
|
||||
frm_data: &mut FrmData,
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
frm_configs: FrmConfigsObject,
|
||||
_frm_configs: FrmConfigsObject,
|
||||
frm_suggestion: &mut Option<FrmSuggestion>,
|
||||
key_store: domain::MerchantKeyStore,
|
||||
payment_data: &mut payments::PaymentData<F>,
|
||||
@ -194,7 +194,6 @@ impl<F: Send + Clone> Domain<F> for FraudCheckPost {
|
||||
_should_continue_capture: &mut bool,
|
||||
) -> RouterResult<Option<FrmData>> {
|
||||
if matches!(frm_data.fraud_check.frm_status, FraudCheckStatus::Fraud)
|
||||
&& matches!(frm_configs.frm_action, FrmAction::CancelTxn)
|
||||
&& matches!(
|
||||
frm_data.fraud_check.last_step,
|
||||
FraudCheckLastStep::CheckoutOrSale
|
||||
@ -242,9 +241,10 @@ impl<F: Send + Clone> Domain<F> for FraudCheckPost {
|
||||
)
|
||||
.await?;
|
||||
frm_data.fraud_check.last_step = FraudCheckLastStep::TransactionOrRecordRefund;
|
||||
} else if matches!(frm_data.fraud_check.frm_status, FraudCheckStatus::Fraud)
|
||||
&& matches!(frm_configs.frm_action, FrmAction::ManualReview)
|
||||
{
|
||||
} else if matches!(
|
||||
frm_data.fraud_check.frm_status,
|
||||
FraudCheckStatus::ManualReview
|
||||
) {
|
||||
*frm_suggestion = Some(FrmSuggestion::FrmManualReview);
|
||||
} else if matches!(frm_data.fraud_check.frm_status, FraudCheckStatus::Legit)
|
||||
&& matches!(
|
||||
@ -477,25 +477,34 @@ impl<F: Clone + Send> UpdateTracker<FrmData, F> for FraudCheckPost {
|
||||
};
|
||||
|
||||
if let Some(frm_suggestion) = frm_suggestion {
|
||||
let (payment_attempt_status, payment_intent_status) = match frm_suggestion {
|
||||
FrmSuggestion::FrmCancelTransaction => {
|
||||
(AttemptStatus::Failure, IntentStatus::Failed)
|
||||
}
|
||||
FrmSuggestion::FrmManualReview => (
|
||||
AttemptStatus::Unresolved,
|
||||
IntentStatus::RequiresMerchantAction,
|
||||
),
|
||||
FrmSuggestion::FrmAuthorizeTransaction => {
|
||||
(AttemptStatus::Authorized, IntentStatus::RequiresCapture)
|
||||
}
|
||||
};
|
||||
let (payment_attempt_status, payment_intent_status, merchant_decision, error_message) =
|
||||
match frm_suggestion {
|
||||
FrmSuggestion::FrmCancelTransaction => (
|
||||
AttemptStatus::Failure,
|
||||
IntentStatus::Failed,
|
||||
Some(MerchantDecision::Rejected.to_string()),
|
||||
Some(Some(CANCEL_INITIATED.to_string())),
|
||||
),
|
||||
FrmSuggestion::FrmManualReview => (
|
||||
AttemptStatus::Unresolved,
|
||||
IntentStatus::RequiresMerchantAction,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
FrmSuggestion::FrmAuthorizeTransaction => (
|
||||
AttemptStatus::Authorized,
|
||||
IntentStatus::RequiresCapture,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
};
|
||||
payment_data.payment_attempt = db
|
||||
.update_payment_attempt_with_attempt_id(
|
||||
payment_data.payment_attempt.clone(),
|
||||
PaymentAttemptUpdate::RejectUpdate {
|
||||
status: payment_attempt_status,
|
||||
error_code: Some(Some(frm_data.fraud_check.frm_status.to_string())),
|
||||
error_message: Some(Some(CANCEL_INITIATED.to_string())),
|
||||
error_message,
|
||||
updated_by: frm_data.merchant_account.storage_scheme.to_string(),
|
||||
},
|
||||
frm_data.merchant_account.storage_scheme,
|
||||
@ -508,7 +517,7 @@ impl<F: Clone + Send> UpdateTracker<FrmData, F> for FraudCheckPost {
|
||||
payment_data.payment_intent.clone(),
|
||||
PaymentIntentUpdate::RejectUpdate {
|
||||
status: payment_intent_status,
|
||||
merchant_decision: Some(MerchantDecision::Rejected.to_string()),
|
||||
merchant_decision,
|
||||
updated_by: frm_data.merchant_account.storage_scheme.to_string(),
|
||||
},
|
||||
frm_data.merchant_account.storage_scheme,
|
||||
|
||||
@ -5,7 +5,7 @@ use api_models::{
|
||||
refunds::RefundResponse,
|
||||
};
|
||||
use common_enums::FrmSuggestion;
|
||||
use common_utils::pii::Email;
|
||||
use common_utils::pii::{Email, SecretSerdeValue};
|
||||
use hyperswitch_domain_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent};
|
||||
use masking::Serialize;
|
||||
use serde::Deserialize;
|
||||
@ -56,7 +56,7 @@ pub struct FrmData {
|
||||
pub connector_details: ConnectorDetailsCore,
|
||||
pub order_details: Option<Vec<api_models::payments::OrderDetailsWithAmount>>,
|
||||
pub refund: Option<RefundResponse>,
|
||||
pub frm_metadata: Option<serde_json::Value>,
|
||||
pub frm_metadata: Option<SecretSerdeValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -80,15 +80,13 @@ pub struct PaymentToFrmData {
|
||||
pub address: PaymentAddress,
|
||||
pub connector_details: ConnectorDetailsCore,
|
||||
pub order_details: Option<Vec<api_models::payments::OrderDetailsWithAmount>>,
|
||||
pub frm_metadata: Option<serde_json::Value>,
|
||||
pub frm_metadata: Option<SecretSerdeValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct FrmConfigsObject {
|
||||
pub frm_enabled_pm: Option<PaymentMethod>,
|
||||
pub frm_enabled_pm_type: Option<PaymentMethodType>,
|
||||
pub frm_enabled_gateway: Option<api_models::enums::Connector>,
|
||||
pub frm_action: api_enums::FrmAction,
|
||||
pub frm_preferred_flow_type: api_enums::FrmPreferredFlowTypes,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user