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

feat(FRM): Revise post FRM core flows #4394

Merged
merged 28 commits into from Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e960e0c
revise post frm core flows
srujanchikke Apr 18, 2024
785ee7f
Merge branch 'main' of github.com:juspay/hyperswitch into frm_core_flows
srujanchikke Apr 18, 2024
1cb716c
chore: run formatter
hyperswitch-bot[bot] Apr 18, 2024
e790e6e
fix clippy
srujanchikke Apr 19, 2024
f99e030
Merge branch 'main' of github.com:juspay/hyperswitch into frm_core_flows
srujanchikke Apr 19, 2024
164fbb8
Merge branch 'frm_core_flows' of github.com:juspay/hyperswitch into f…
srujanchikke Apr 19, 2024
069baca
chore: run formatter
hyperswitch-bot[bot] Apr 19, 2024
b8c5821
refactor approve incase of manual capture
srujanchikke Apr 24, 2024
c975c55
Merge branch 'main' of github.com:juspay/hyperswitch into frm_core_flows
srujanchikke Apr 24, 2024
08da3ea
Merge branch 'frm_core_flows' of github.com:juspay/hyperswitch into f…
srujanchikke Apr 24, 2024
3fa28af
chore: run formatter
hyperswitch-bot[bot] Apr 24, 2024
3190345
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Apr 24, 2024
1ce254c
migrations for fraud_check and payment status
srujanchikke Apr 24, 2024
5405235
Merge branch 'frm_core_flows' of github.com:juspay/hyperswitch into f…
srujanchikke Apr 24, 2024
5f9633c
minor change on down.sql
srujanchikke Apr 24, 2024
296cee1
fix cargo hack by adding frm feature flag
srujanchikke Apr 24, 2024
f12d080
chore: run formatter
hyperswitch-bot[bot] Apr 24, 2024
e72b38b
add transaction flow after checkout flow for pre frm
srujanchikke Apr 25, 2024
c6f46ce
Merge branch 'frm_core_flows' of github.com:juspay/hyperswitch into f…
srujanchikke Apr 25, 2024
3203ffc
Merge branch 'main' of github.com:juspay/hyperswitch into frm_core_flows
srujanchikke Apr 25, 2024
e9fd863
resolve comments
srujanchikke Apr 25, 2024
cd68352
minor changes
srujanchikke Apr 25, 2024
4b290c6
minor refactor
srujanchikke Apr 25, 2024
ff304d6
rename frm_capture_method to payment_capture_method in frm data
srujanchikke Apr 26, 2024
5605ff3
resolve comments and revert frm_requires_merchant_action enum
srujanchikke Apr 26, 2024
8aebbbd
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Apr 26, 2024
91320db
Merge branch 'main' into frm_core_flows
srujanchikke Apr 26, 2024
8cc5265
Merge branch 'main' into frm_core_flows
srujanchikke Apr 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/common_enums/src/enums.rs
Expand Up @@ -55,6 +55,7 @@ pub enum AttemptStatus {
PartialCharged,
PartialChargedAndChargeable,
Unresolved,
FrmUnresolved,
#[default]
Pending,
Failure,
Expand Down Expand Up @@ -193,6 +194,7 @@ impl AttemptStatus {
| Self::CaptureInitiated
| Self::PartialChargedAndChargeable
| Self::Unresolved
| Self::FrmUnresolved
| Self::Pending
| Self::PaymentMethodAwaited
| Self::ConfirmationAwaited
Expand Down Expand Up @@ -281,6 +283,7 @@ pub enum AuthorizationStatus {
Processing,
// Requires merchant action
Unresolved,
FrmUnresolved,
}

#[derive(
Expand Down Expand Up @@ -1176,6 +1179,7 @@ pub enum IntentStatus {
Processing,
RequiresCustomerAction,
RequiresMerchantAction,
FrmRequiresMerchantAction,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use RequiresMerchantAction, this is meant to indicate that there is some MerhantAction that is required based on the frm message or some additional fields

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Narayanbhat166 , We have introduced this status to not interfere with payments which doesn't go through FRM. In future there might decisions/actions we might take based on FrmRequiredMerchantAction status for FRM webhooks which doesn't apply for payment connectors.

cc: @kashif-m @AnandKGanesh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this status is introduced for explicitly specifying the fact that merchant needs to take an FRM related action on the payment. Using existing variant RequiresMerchantAction does not give enough context about what exactly merchant needs to do. This variant is being used in one of the flows for some crypto connector cc: @srujanchikke

Having a separate variant in this case gives us full context about the type of actions that can be taken by the merchant (payment approval / cancellation in this case)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc : @jarnura

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not introduce the same status RequiresMerchantAction with some prefix again because the merchant wants to do something different by this. If RequiresMerchantAction is the status, then always the merchant should go to some details field or reason field, which tells what is issue and what merchant needs do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add the feasibility to be able to list only the fraudulent transactions in payments list / filter APIs using the details / reason field

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do that it in subsequent PR

RequiresPaymentMethod,
#[default]
RequiresConfirmation,
Expand Down Expand Up @@ -1274,6 +1278,7 @@ impl From<AttemptStatus> for PaymentMethodStatus {
| AttemptStatus::Started
| AttemptStatus::Pending
| AttemptStatus::Unresolved
| AttemptStatus::FrmUnresolved
| AttemptStatus::CodInitiated
| AttemptStatus::Authorizing
| AttemptStatus::VoidInitiated
Expand Down Expand Up @@ -2249,7 +2254,6 @@ pub enum FrmSuggestion {
#[default]
FrmCancelTransaction,
FrmManualReview,
FrmAutoRefund,
}

#[derive(
Expand Down
1 change: 1 addition & 0 deletions crates/data_models/src/payments/payment_attempt.rs
Expand Up @@ -303,6 +303,7 @@ pub enum PaymentAttemptUpdate {
currency: storage_enums::Currency,
status: storage_enums::AttemptStatus,
authentication_type: Option<storage_enums::AuthenticationType>,
capture_method: Option<storage_enums::CaptureMethod>,
payment_method: Option<storage_enums::PaymentMethod>,
browser_info: Option<serde_json::Value>,
connector: Option<String>,
Expand Down
3 changes: 3 additions & 0 deletions crates/data_models/src/payments/payment_intent.rs
Expand Up @@ -182,6 +182,7 @@ pub enum PaymentIntentUpdate {
updated_by: String,
},
ApproveUpdate {
status: storage_enums::IntentStatus,
merchant_decision: Option<String>,
updated_by: String,
},
Expand Down Expand Up @@ -382,9 +383,11 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
..Default::default()
},
PaymentIntentUpdate::ApproveUpdate {
status,
merchant_decision,
updated_by,
} => Self {
status: Some(status),
merchant_decision,
updated_by,
..Default::default()
Expand Down
7 changes: 7 additions & 0 deletions crates/diesel_models/src/fraud_check.rs
@@ -1,3 +1,4 @@
use common_enums as storage_enums;
use diesel::{AsChangeset, Identifiable, Insertable, Queryable};
use masking::{Deserialize, Serialize};
use time::PrimitiveDateTime;
Expand Down Expand Up @@ -25,6 +26,7 @@ pub struct FraudCheck {
pub metadata: Option<serde_json::Value>,
pub modified_at: PrimitiveDateTime,
pub last_step: FraudCheckLastStep,
pub payment_capture_method: Option<storage_enums::CaptureMethod>, // In postFrm, we are updating capture method from automatic to manual. To store the merchant actual capture method, we are storing the actual capture method in payment_capture_method. It will be useful while approving the FRM decision.
}

#[derive(router_derive::Setter, Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
Expand All @@ -46,6 +48,7 @@ pub struct FraudCheckNew {
pub metadata: Option<serde_json::Value>,
pub modified_at: PrimitiveDateTime,
pub last_step: FraudCheckLastStep,
pub payment_capture_method: Option<storage_enums::CaptureMethod>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -59,6 +62,7 @@ pub enum FraudCheckUpdate {
metadata: Option<serde_json::Value>,
modified_at: PrimitiveDateTime,
last_step: FraudCheckLastStep,
payment_capture_method: Option<storage_enums::CaptureMethod>,
},
ErrorUpdate {
status: FraudCheckStatus,
Expand All @@ -76,6 +80,7 @@ pub struct FraudCheckUpdateInternal {
frm_error: Option<Option<String>>,
metadata: Option<serde_json::Value>,
last_step: FraudCheckLastStep,
payment_capture_method: Option<storage_enums::CaptureMethod>,
}

impl From<FraudCheckUpdate> for FraudCheckUpdateInternal {
Expand All @@ -89,13 +94,15 @@ impl From<FraudCheckUpdate> for FraudCheckUpdateInternal {
metadata,
modified_at: _,
last_step,
payment_capture_method,
} => Self {
frm_status: Some(frm_status),
frm_transaction_id,
frm_reason,
frm_score,
metadata,
last_step,
payment_capture_method,
..Default::default()
},
FraudCheckUpdate::ErrorUpdate {
Expand Down
3 changes: 3 additions & 0 deletions crates/diesel_models/src/payment_attempt.rs
Expand Up @@ -209,6 +209,7 @@ pub enum PaymentAttemptUpdate {
currency: storage_enums::Currency,
status: storage_enums::AttemptStatus,
authentication_type: Option<storage_enums::AuthenticationType>,
capture_method: Option<storage_enums::CaptureMethod>,
payment_method: Option<storage_enums::PaymentMethod>,
browser_info: Option<serde_json::Value>,
connector: Option<String>,
Expand Down Expand Up @@ -555,6 +556,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
amount,
currency,
authentication_type,
capture_method,
status,
payment_method,
browser_info,
Expand Down Expand Up @@ -606,6 +608,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
payment_method_billing_address_id,
fingerprint_id,
payment_method_id,
capture_method,
..Default::default()
},
PaymentAttemptUpdate::VoidUpdate {
Expand Down
3 changes: 3 additions & 0 deletions crates/diesel_models/src/payment_intent.rs
Expand Up @@ -180,6 +180,7 @@ pub enum PaymentIntentUpdate {
updated_by: String,
},
ApproveUpdate {
status: storage_enums::IntentStatus,
merchant_decision: Option<String>,
updated_by: String,
},
Expand Down Expand Up @@ -456,9 +457,11 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
..Default::default()
},
PaymentIntentUpdate::ApproveUpdate {
status,
merchant_decision,
updated_by,
} => Self {
status: Some(status),
merchant_decision,
updated_by,
..Default::default()
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/schema.rs
Expand Up @@ -449,6 +449,7 @@ diesel::table! {
modified_at -> Timestamp,
#[max_length = 64]
last_step -> Varchar,
payment_capture_method -> Nullable<CaptureMethod>,
}
}

Expand Down
Expand Up @@ -413,7 +413,8 @@ impl From<api_enums::IntentStatus> for StripePaymentStatus {
api_enums::IntentStatus::Failed => Self::Canceled,
api_enums::IntentStatus::Processing => Self::Processing,
api_enums::IntentStatus::RequiresCustomerAction
| api_enums::IntentStatus::RequiresMerchantAction => Self::RequiresAction,
| api_enums::IntentStatus::RequiresMerchantAction
| api_enums::IntentStatus::FrmRequiresMerchantAction => Self::RequiresAction,
api_enums::IntentStatus::RequiresPaymentMethod => Self::RequiresPaymentMethod,
api_enums::IntentStatus::RequiresConfirmation => Self::RequiresConfirmation,
api_enums::IntentStatus::RequiresCapture
Expand Down
Expand Up @@ -325,7 +325,8 @@ impl From<api_enums::IntentStatus> for StripeSetupStatus {
api_enums::IntentStatus::RequiresPaymentMethod => Self::RequiresPaymentMethod,
api_enums::IntentStatus::RequiresConfirmation => Self::RequiresConfirmation,
api_enums::IntentStatus::RequiresCapture
| api_enums::IntentStatus::PartiallyCapturedAndCapturable => {
| api_enums::IntentStatus::PartiallyCapturedAndCapturable
| api_enums::IntentStatus::FrmRequiresMerchantAction => {
logger::error!("Invalid status change");
Self::Canceled
}
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/paypal/transformers.rs
Expand Up @@ -1560,6 +1560,7 @@ impl TryFrom<types::PaymentsCaptureResponseRouterData<PaypalCaptureResponse>>
| storage_enums::AttemptStatus::VoidFailed
| storage_enums::AttemptStatus::AutoRefunded
| storage_enums::AttemptStatus::Unresolved
| storage_enums::AttemptStatus::FrmUnresolved
| storage_enums::AttemptStatus::PaymentMethodAwaited
| storage_enums::AttemptStatus::ConfirmationAwaited
| storage_enums::AttemptStatus::DeviceDataCollectionPending
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/connector/utils.rs
Expand Up @@ -1950,6 +1950,7 @@ impl FrmTransactionRouterDataRequest for fraud_check::FrmTransactionRouterData {
| storage_enums::AttemptStatus::VoidFailed
| storage_enums::AttemptStatus::PartialCharged
| storage_enums::AttemptStatus::Unresolved
| storage_enums::AttemptStatus::FrmUnresolved
| storage_enums::AttemptStatus::Pending
| storage_enums::AttemptStatus::PaymentMethodAwaited
| storage_enums::AttemptStatus::ConfirmationAwaited
Expand Down Expand Up @@ -1980,6 +1981,7 @@ pub fn is_payment_failure(status: enums::AttemptStatus) -> bool {
| common_enums::AttemptStatus::PartialCharged
| common_enums::AttemptStatus::PartialChargedAndChargeable
| common_enums::AttemptStatus::Unresolved
| common_enums::AttemptStatus::FrmUnresolved
| common_enums::AttemptStatus::Pending
| common_enums::AttemptStatus::PaymentMethodAwaited
| common_enums::AttemptStatus::ConfirmationAwaited
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/volt/transformers.rs
Expand Up @@ -639,6 +639,7 @@ fn is_payment_failure(status: enums::AttemptStatus) -> bool {
| common_enums::AttemptStatus::PartialCharged
| common_enums::AttemptStatus::PartialChargedAndChargeable
| common_enums::AttemptStatus::Unresolved
| common_enums::AttemptStatus::FrmUnresolved
| common_enums::AttemptStatus::Pending
| common_enums::AttemptStatus::PaymentMethodAwaited
| common_enums::AttemptStatus::ConfirmationAwaited
Expand Down