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

refactor(blocklist): separate utility function & kill switch for validating data in blocklist #3360

Merged
merged 35 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
243a76d
refactor(blocklist): separate utility function for validating data in…
prajjwalkumar17 Jan 16, 2024
63cdc18
Merge branch 'main' into refactor_blocklist
prajjwalkumar17 Jan 16, 2024
f0438d6
refactor(blocklist): separate error generic-error for blocked payments
prajjwalkumar17 Jan 18, 2024
cfe2803
chore: merge main
prajjwalkumar17 Jan 18, 2024
0c124f4
Merge branch 'main' into refactor_blocklist
prajjwalkumar17 Jan 18, 2024
5da238d
chore: formatting
prajjwalkumar17 Jan 18, 2024
3e7acf4
chore: formatting
prajjwalkumar17 Jan 18, 2024
471482a
chore: changed the error message
prajjwalkumar17 Jan 18, 2024
cb1f18f
chore: clippy fix
prajjwalkumar17 Jan 18, 2024
c4ec9b4
refactor: created separate domain function for blocklist check
prajjwalkumar17 Jan 24, 2024
c9255a7
chore: resolve conflicts
prajjwalkumar17 Jan 24, 2024
a14e085
chore: updated connector and mca_id to be null once the payment is bl…
prajjwalkumar17 Jan 29, 2024
6267d86
chore: updated the flow where the blocklist_guard was getting called
prajjwalkumar17 Jan 29, 2024
6563fa1
Merge branch 'main' into refactor_blocklist
prajjwalkumar17 Jan 29, 2024
7636817
chore: refactored for clippy checks to pass
prajjwalkumar17 Jan 29, 2024
29e3db5
feat(core): add killswitch for the blocklist guard feature
prajjwalkumar17 Jan 30, 2024
381d101
Merge branch 'main' into refactor_blocklist
prajjwalkumar17 Jan 30, 2024
9dc1243
chore: addressed comments
prajjwalkumar17 Jan 30, 2024
85bd463
Merge branch 'refactor_blocklist' of https://github.com/juspay/hypers…
prajjwalkumar17 Jan 30, 2024
fa9e5ea
chore: addressed comments
prajjwalkumar17 Jan 30, 2024
4928c91
chore: addressed comments, renamed error type
prajjwalkumar17 Jan 30, 2024
f3375ee
chore: resolved conflicts
prajjwalkumar17 Jan 30, 2024
b0ba6a5
chore: run formatter
hyperswitch-bot[bot] Jan 30, 2024
bd151df
chore: addressed comments
prajjwalkumar17 Jan 31, 2024
6483529
Merge branch 'refactor_blocklist' of https://github.com/juspay/hypers…
prajjwalkumar17 Jan 31, 2024
4e6cb28
Merge branch 'main' into refactor_blocklist
prajjwalkumar17 Jan 31, 2024
453f04d
Merge remote-tracking branch 'origin' into refactor_blocklist
prajjwalkumar17 Jan 31, 2024
35c806d
chore: refactored the deisel model conversions for Option<Option<stri…
prajjwalkumar17 Feb 1, 2024
41da206
Merge branch 'main' into refactor_blocklist
prajjwalkumar17 Feb 1, 2024
cf1cee8
chore: refactored the deisel model conversions for Option<Option<stri…
prajjwalkumar17 Feb 1, 2024
54fa133
Merge branch 'refactor_blocklist' of https://github.com/juspay/hypers…
prajjwalkumar17 Feb 1, 2024
6a0704b
Merge branch 'main' into refactor_blocklist
prajjwalkumar17 Feb 1, 2024
0282067
Merge branch 'main' into refactor_blocklist
prajjwalkumar17 Feb 5, 2024
48c8d93
chore: resolved conflicts
prajjwalkumar17 Feb 5, 2024
a339be0
chore: resolved conflicts
prajjwalkumar17 Feb 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/api_models/src/errors/actix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ impl actix_web::ResponseError for ApiErrorResponse {
Self::MethodNotAllowed(_) => StatusCode::METHOD_NOT_ALLOWED,
Self::NotFound(_) => StatusCode::NOT_FOUND,
Self::BadRequest(_) => StatusCode::BAD_REQUEST,
Self::DomainError(_) => StatusCode::OK,
}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/api_models/src/errors/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub enum ApiErrorResponse {
NotFound(ApiError),
MethodNotAllowed(ApiError),
BadRequest(ApiError),
DomainError(ApiError),
}

impl ::core::fmt::Display for ApiErrorResponse {
Expand Down Expand Up @@ -122,6 +123,7 @@ impl ApiErrorResponse {
| Self::NotFound(i)
| Self::MethodNotAllowed(i)
| Self::BadRequest(i)
| Self::DomainError(i)
| Self::ConnectorError(i, _) => i,
}
}
Expand All @@ -139,6 +141,7 @@ impl ApiErrorResponse {
| Self::NotFound(i)
| Self::MethodNotAllowed(i)
| Self::BadRequest(i)
| Self::DomainError(i)
| Self::ConnectorError(i, _) => i,
}
}
Expand All @@ -156,6 +159,7 @@ impl ApiErrorResponse {
| Self::NotFound(_)
| Self::BadRequest(_) => "invalid_request",
Self::InternalServerError(_) => "api",
Self::DomainError(_) => "blocked",
Self::ConnectorError(_, _) => "connector",
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/data_models/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ pub enum PaymentAttemptUpdate {
error_message: Option<Option<String>>,
updated_by: String,
},
BlocklistUpdate {
status: storage_enums::AttemptStatus,
error_code: Option<Option<String>>,
error_message: Option<Option<String>>,
updated_by: String,
},
VoidUpdate {
status: storage_enums::AttemptStatus,
cancellation_reason: Option<String>,
Expand Down
44 changes: 32 additions & 12 deletions crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ pub enum PaymentAttemptUpdate {
cancellation_reason: Option<String>,
updated_by: String,
},
BlocklistUpdate {
status: storage_enums::AttemptStatus,
error_code: Option<Option<String>>,
error_message: Option<Option<String>>,
updated_by: String,
},
RejectUpdate {
status: storage_enums::AttemptStatus,
error_code: Option<Option<String>>,
Expand Down Expand Up @@ -312,7 +318,7 @@ pub struct PaymentAttemptUpdateInternal {
status: Option<storage_enums::AttemptStatus>,
connector_transaction_id: Option<String>,
amount_to_capture: Option<i64>,
connector: Option<String>,
connector: Option<Option<String>>,
authentication_type: Option<storage_enums::AuthenticationType>,
payment_method: Option<storage_enums::PaymentMethod>,
error_message: Option<Option<String>>,
Expand All @@ -338,7 +344,7 @@ pub struct PaymentAttemptUpdateInternal {
tax_amount: Option<i64>,
amount_capturable: Option<i64>,
updated_by: String,
merchant_connector_id: Option<String>,
merchant_connector_id: Option<Option<String>>,
authentication_data: Option<serde_json::Value>,
encoded_data: Option<String>,
unified_code: Option<Option<String>>,
Expand Down Expand Up @@ -411,7 +417,7 @@ impl PaymentAttemptUpdate {
status: status.unwrap_or(source.status),
connector_transaction_id: connector_transaction_id.or(source.connector_transaction_id),
amount_to_capture: amount_to_capture.or(source.amount_to_capture),
connector: connector.or(source.connector),
connector: connector.unwrap_or(source.connector),
authentication_type: authentication_type.or(source.authentication_type),
payment_method: payment_method.or(source.payment_method),
error_message: error_message.unwrap_or(source.error_message),
Expand Down Expand Up @@ -439,7 +445,7 @@ impl PaymentAttemptUpdate {
tax_amount: tax_amount.or(source.tax_amount),
amount_capturable: amount_capturable.unwrap_or(source.amount_capturable),
updated_by,
merchant_connector_id: merchant_connector_id.or(source.merchant_connector_id),
merchant_connector_id: merchant_connector_id.unwrap_or(source.merchant_connector_id),
authentication_data: authentication_data.or(source.authentication_data),
encoded_data: encoded_data.or(source.encoded_data),
unified_code: unified_code.unwrap_or(source.unified_code),
Expand Down Expand Up @@ -527,7 +533,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
payment_method,
modified_at: Some(common_utils::date_time::now()),
browser_info,
connector,
connector: connector.map(Some),
payment_token,
payment_method_data,
payment_method_type,
Expand All @@ -538,7 +544,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
error_message,
amount_capturable,
updated_by,
merchant_connector_id,
merchant_connector_id: merchant_connector_id.map(Some),
surcharge_amount,
tax_amount,
..Default::default()
Expand All @@ -565,6 +571,20 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
updated_by,
..Default::default()
},
PaymentAttemptUpdate::BlocklistUpdate {
status,
error_code,
error_message,
updated_by,
} => Self {
status: Some(status),
error_code,
connector: Some(None),
error_message,
updated_by,
merchant_connector_id: Some(None),
..Default::default()
},
PaymentAttemptUpdate::ResponseUpdate {
status,
connector,
Expand All @@ -586,7 +606,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
unified_message,
} => Self {
status: Some(status),
connector,
connector: connector.map(Some),
connector_transaction_id,
authentication_type,
payment_method_id,
Expand Down Expand Up @@ -618,7 +638,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
unified_message,
connector_transaction_id,
} => Self {
connector,
connector: connector.map(Some),
status: Some(status),
error_message,
error_code,
Expand Down Expand Up @@ -647,13 +667,13 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
merchant_connector_id,
} => Self {
payment_token,
connector,
connector: connector.map(Some),
straight_through_algorithm,
amount_capturable,
surcharge_amount,
tax_amount,
updated_by,
merchant_connector_id,
merchant_connector_id: merchant_connector_id.map(Some),
..Default::default()
},
PaymentAttemptUpdate::UnresolvedResponseUpdate {
Expand All @@ -668,7 +688,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
updated_by,
} => Self {
status: Some(status),
connector,
connector: connector.map(Some),
connector_transaction_id,
payment_method_id,
modified_at: Some(common_utils::date_time::now()),
Expand Down Expand Up @@ -728,7 +748,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
authentication_data,
encoded_data,
connector_transaction_id,
connector,
connector: connector.map(Some),
updated_by,
..Default::default()
},
Expand Down
23 changes: 22 additions & 1 deletion crates/router/src/compatibility/stripe/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ pub enum StripeErrorCode {
status_code: u16,
},

#[error(error_type = StripeErrorType::CardError, code = "", message = "{code}: {message}")]
PaymentBlockedError {
code: u16,
message: String,
status: String,
reason: String,
},

#[error(error_type = StripeErrorType::HyperswitchError, code = "", message = "The connector provided in the request is incorrect or not available")]
IncorrectConnectorNameGiven,
#[error(error_type = StripeErrorType::HyperswitchError, code = "", message = "No such {object}: '{id}'")]
Expand Down Expand Up @@ -521,7 +529,17 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
connector_name,
},
errors::ApiErrorResponse::DuplicatePaymentMethod => Self::DuplicatePaymentMethod,
errors::ApiErrorResponse::PaymentBlocked => Self::PaymentFailed,
errors::ApiErrorResponse::PaymentBlockedError {
code,
message,
status,
reason,
} => Self::PaymentBlockedError {
code,
message,
status,
reason,
},
errors::ApiErrorResponse::ClientSecretInvalid => Self::PaymentIntentInvalidParameter {
param: "client_secret".to_owned(),
},
Expand Down Expand Up @@ -680,6 +698,9 @@ impl actix_web::ResponseError for StripeErrorCode {
Self::ExternalConnectorError { status_code, .. } => {
StatusCode::from_u16(*status_code).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR)
}
Self::PaymentBlockedError { code, .. } => {
StatusCode::from_u16(*code).unwrap_or(StatusCode::OK)
}
Self::LockTimeout => StatusCode::LOCKED,
}
}
Expand Down
Loading
Loading