Skip to content

Commit

Permalink
feat(frm): Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jagan-jaya committed Sep 4, 2023
1 parent 307984a commit 721de06
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 61 deletions.
2 changes: 2 additions & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,7 @@ pub enum PayoutEntityType {
pub enum MerchantDecision {
Approved,
Rejected,
AutoRefunded,
}

#[derive(
Expand All @@ -1700,6 +1701,7 @@ pub enum FrmSuggestion {
#[default]
FrmCancelTransaction,
FrmManualReview,
FrmAutoRefund,
}

#[derive(
Expand Down
3 changes: 0 additions & 3 deletions crates/data_models/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ pub struct PaymentAttempt {
pub multiple_capture_count: Option<i16>,
// reference to the payment at connector side
pub connector_response_reference_id: Option<String>,
// Denotes the action(approve or reject) taken by merchant in case of manual review.
// Manual review can occur when the transaction is marked as risky by the frm_processor, payment processor or when there is underpayment/over payment incase of crypto payment
pub merchant_decision: Option<String>,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
Expand Down
26 changes: 26 additions & 0 deletions crates/data_models/src/payments/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ pub struct PaymentIntent {
pub feature_metadata: Option<serde_json::Value>,
pub attempt_count: i16,
pub profile_id: Option<String>,
// Denotes the action(approve or reject) taken by merchant in case of manual review.
// Manual review can occur when the transaction is marked as risky by the frm_processor, payment processor or when there is underpayment/over payment incase of crypto payment
pub merchant_decision: Option<String>,
}

#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -136,6 +139,7 @@ pub struct PaymentIntentNew {
pub feature_metadata: Option<serde_json::Value>,
pub attempt_count: i16,
pub profile_id: Option<String>,
pub merchant_decision: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -189,6 +193,13 @@ pub enum PaymentIntentUpdate {
active_attempt_id: String,
attempt_count: i16,
},
ApproveUpdate {
merchant_decision: Option<String>,
},
RejectUpdate {
status: storage_enums::IntentStatus,
merchant_decision: Option<String>,
},
}

#[derive(Clone, Debug, Default)]
Expand All @@ -213,6 +224,9 @@ pub struct PaymentIntentUpdateInternal {
pub statement_descriptor_suffix: Option<String>,
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
pub attempt_count: Option<i16>,
// Denotes the action(approve or reject) taken by merchant in case of manual review.
// Manual review can occur when the transaction is marked as risky by the frm_processor, payment processor or when there is underpayment/over payment incase of crypto payment
pub merchant_decision: Option<String>,
}

impl PaymentIntentUpdate {
Expand Down Expand Up @@ -352,6 +366,18 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
attempt_count: Some(attempt_count),
..Default::default()
},
PaymentIntentUpdate::ApproveUpdate { merchant_decision } => Self {
merchant_decision,
..Default::default()
},
PaymentIntentUpdate::RejectUpdate {
status,
merchant_decision,
} => Self {
status: Some(status),
merchant_decision,
..Default::default()
},
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ pub struct PaymentAttempt {
pub multiple_capture_count: Option<i16>,
// reference to the payment at connector side
pub connector_response_reference_id: Option<String>,
// Denotes the action(approve or reject) taken by merchant in case of manual review.
// Manual review can occur when the transaction is marked as risky by the payment processor, frm_processor or when there is underpayment/over payment incase of crypto payment
pub merchant_decision: Option<String>,
}

#[derive(Clone, Debug, Eq, PartialEq, Queryable, Serialize, Deserialize)]
Expand Down Expand Up @@ -163,12 +160,8 @@ pub enum PaymentAttemptUpdate {
status: storage_enums::AttemptStatus,
cancellation_reason: Option<String>,
},
ApproveUpdate {
merchant_decision: Option<Option<String>>,
},
RejectUpdate {
status: storage_enums::AttemptStatus,
merchant_decision: Option<Option<String>>,
error_code: Option<Option<String>>,
error_message: Option<Option<String>>,
},
Expand Down Expand Up @@ -249,7 +242,6 @@ pub struct PaymentAttemptUpdateInternal {
capture_method: Option<storage_enums::CaptureMethod>,
connector_response_reference_id: Option<String>,
multiple_capture_count: Option<i16>,
merchant_decision: Option<Option<String>>,
}

impl PaymentAttemptUpdate {
Expand Down Expand Up @@ -365,18 +357,12 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
cancellation_reason,
..Default::default()
},
PaymentAttemptUpdate::ApproveUpdate { merchant_decision } => Self {
merchant_decision,
..Default::default()
},
PaymentAttemptUpdate::RejectUpdate {
status,
merchant_decision,
error_code,
error_message,
} => Self {
status: Some(status),
merchant_decision,
error_code,
error_message,
..Default::default()
Expand Down
24 changes: 24 additions & 0 deletions crates/diesel_models/src/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ pub struct PaymentIntent {
pub feature_metadata: Option<serde_json::Value>,
pub attempt_count: i16,
pub profile_id: Option<String>,
// Denotes the action(approve or reject) taken by merchant in case of manual review.
// Manual review can occur when the transaction is marked as risky by the frm_processor, payment processor or when there is underpayment/over payment incase of crypto payment
pub merchant_decision: Option<String>,
}

#[derive(
Expand Down Expand Up @@ -92,6 +95,7 @@ pub struct PaymentIntentNew {
pub feature_metadata: Option<serde_json::Value>,
pub attempt_count: i16,
pub profile_id: Option<String>,
pub merchant_decision: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -145,6 +149,13 @@ pub enum PaymentIntentUpdate {
active_attempt_id: String,
attempt_count: i16,
},
ApproveUpdate {
merchant_decision: Option<String>,
},
RejectUpdate {
status: storage_enums::IntentStatus,
merchant_decision: Option<String>,
},
}

#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]
Expand Down Expand Up @@ -172,6 +183,7 @@ pub struct PaymentIntentUpdateInternal {
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
pub attempt_count: Option<i16>,
merchant_decision: Option<String>,
}

impl PaymentIntentUpdate {
Expand Down Expand Up @@ -311,6 +323,18 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
attempt_count: Some(attempt_count),
..Default::default()
},
PaymentIntentUpdate::ApproveUpdate { merchant_decision } => Self {
merchant_decision,
..Default::default()
},
PaymentIntentUpdate::RejectUpdate {
status,
merchant_decision,
} => Self {
status: Some(status),
merchant_decision,
..Default::default()
},
}
}
}
4 changes: 2 additions & 2 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,6 @@ diesel::table! {
multiple_capture_count -> Nullable<Int2>,
#[max_length = 128]
connector_response_reference_id -> Nullable<Varchar>,
#[max_length = 64]
merchant_decision -> Nullable<Varchar>,
}
}

Expand Down Expand Up @@ -597,6 +595,8 @@ diesel::table! {
attempt_count -> Int2,
#[max_length = 64]
profile_id -> Nullable<Varchar>,
#[max_length = 64]
merchant_decision -> Nullable<Varchar>,
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@ mod tests {
feature_metadata: None,
attempt_count: 1,
profile_id: None,
merchant_decision: None,
};
let req_cs = Some("1".to_string());
let merchant_fulfillment_time = Some(900);
Expand Down Expand Up @@ -2266,6 +2267,7 @@ mod tests {
feature_metadata: None,
attempt_count: 1,
profile_id: None,
merchant_decision: None,
};
let req_cs = Some("1".to_string());
let merchant_fulfillment_time = Some(10);
Expand Down Expand Up @@ -2311,6 +2313,7 @@ mod tests {
feature_metadata: None,
attempt_count: 1,
profile_id: None,
merchant_decision: None,
};
let req_cs = Some("1".to_string());
let merchant_fulfillment_time = Some(10);
Expand Down
18 changes: 4 additions & 14 deletions crates/router/src/core/payments/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,28 +355,18 @@ where
#[instrument(skip_all)]
async fn get_or_create_customer_details<'a>(
&'a self,
db: &dyn StorageInterface,
payment_data: &mut PaymentData<F>,
_db: &dyn StorageInterface,
_payment_data: &mut PaymentData<F>,
_request: Option<CustomerDetails>,
merchant_key_store: &domain::MerchantKeyStore,
_merchant_key_store: &domain::MerchantKeyStore,
) -> CustomResult<
(
BoxedOperation<'a, F, api::PaymentsRejectRequest>,
Option<domain::Customer>,
),
errors::StorageError,
> {
Ok((
Box::new(self),
helpers::get_customer_from_details(
db,
payment_data.payment_intent.customer_id.clone(),
&merchant_key_store.merchant_id,
payment_data,
merchant_key_store,
)
.await?,
))
Ok((Box::new(self), None))
}

#[instrument(skip_all)]
Expand Down
12 changes: 6 additions & 6 deletions crates/router/src/core/payments/operations/payment_approve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,13 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
where
F: 'b + Send,
{
let attempt_status_update = storage::PaymentAttemptUpdate::ApproveUpdate {
merchant_decision: Some(Some(storage_enums::MerchantDecision::Approved.to_string())),
let intent_status_update = storage::PaymentIntentUpdate::ApproveUpdate {
merchant_decision: Some(api_models::enums::MerchantDecision::Approved.to_string()),
};
payment_data.payment_attempt = db
.update_payment_attempt_with_attempt_id(
payment_data.payment_attempt.clone(),
attempt_status_update,
payment_data.payment_intent = db
.update_payment_intent(
payment_data.payment_intent,
intent_status_update,
storage_scheme,
)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
storage_enums::AttemptStatus::Unresolved,
(None, None),
),
None => (
_ => (
storage_enums::IntentStatus::Processing,
storage_enums::AttemptStatus::Pending,
(None, None),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ impl PaymentCreate {
feature_metadata,
attempt_count: 1,
profile_id,
merchant_decision: None,
})
}

Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/core/payments/operations/payment_reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, PaymentsRejectRequest> for Payme
where
F: 'b + Send,
{
let intent_status_update = storage::PaymentIntentUpdate::PGStatusUpdate {
let intent_status_update = storage::PaymentIntentUpdate::RejectUpdate {
status: enums::IntentStatus::Failed,
merchant_decision: Some(enums::MerchantDecision::Rejected.to_string()),
};
let (error_code, error_message) =
payment_data
Expand All @@ -188,7 +189,6 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, PaymentsRejectRequest> for Payme
});
let attempt_status_update = storage::PaymentAttemptUpdate::RejectUpdate {
status: enums::AttemptStatus::Failure,
merchant_decision: Some(Some(enums::MerchantDecision::Rejected.to_string())),
error_code,
error_message,
};
Expand Down
12 changes: 1 addition & 11 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ where
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "payment_method_data",
})?;
let merchant_decision = payment_attempt.merchant_decision.to_owned();
let merchant_decision = payment_intent.merchant_decision.to_owned();
let frm_message = fraud_check.map(FrmMessage::foreign_from);

let payment_method_data_response =
Expand Down Expand Up @@ -1089,19 +1089,9 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsRejectDa

fn try_from(additional_data: PaymentAdditionalData<'_, F>) -> Result<Self, Self::Error> {
let payment_data = additional_data.payment_data;
let connector = api::ConnectorData::get_connector_by_name(
&additional_data.state.conf.connectors,
&additional_data.connector_name,
api::GetToken::Connector,
)?;
Ok(Self {
amount: Some(payment_data.amount.into()),
currency: Some(payment_data.currency),
connector_transaction_id: connector
.connector
.connector_transaction_id(payment_data.payment_attempt.clone())?
.ok_or(errors::ApiErrorResponse::ResourceIdNotFound)?,
connector_meta: payment_data.payment_attempt.connector_metadata,
})
}
}
Expand Down
2 changes: 0 additions & 2 deletions crates/router/src/db/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ impl PaymentAttemptInterface for MockDb {
error_reason: payment_attempt.error_reason,
multiple_capture_count: payment_attempt.multiple_capture_count,
connector_response_reference_id: None,
merchant_decision: None,
};
payment_attempts.push(payment_attempt.clone());
Ok(payment_attempt)
Expand Down Expand Up @@ -569,7 +568,6 @@ mod storage {
error_reason: payment_attempt.error_reason.clone(),
multiple_capture_count: payment_attempt.multiple_capture_count,
connector_response_reference_id: None,
merchant_decision: None,
};

let field = format!("pa_{}", created_attempt.attempt_id);
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/db/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl PaymentIntentInterface for MockDb {
feature_metadata: new.feature_metadata,
attempt_count: new.attempt_count,
profile_id: new.profile_id,
merchant_decision: new.merchant_decision,
};
payment_intents.push(payment_intent.clone());
Ok(payment_intent)
Expand Down
2 changes: 0 additions & 2 deletions crates/router/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,6 @@ pub struct PaymentsCancelData {
pub struct PaymentsRejectData {
pub amount: Option<i64>,
pub currency: Option<storage_enums::Currency>,
pub connector_transaction_id: String,
pub connector_meta: Option<serde_json::Value>,
}

#[derive(Debug, Default, Clone)]
Expand Down
Loading

0 comments on commit 721de06

Please sign in to comment.