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(router): blocklist #3056

Merged
merged 55 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
779b1b0
chore: updated main
prajjwalkumar17 Dec 5, 2023
896c755
Merge branch 'main' into feat/block_paymentmethod
prajjwalkumar17 Dec 5, 2023
248f39d
feat(router): block card block route init
prajjwalkumar17 Dec 5, 2023
b3665d7
Merge branch 'feat/block_paymentmethod' of https://github.com/juspay/…
prajjwalkumar17 Dec 5, 2023
d434bf2
chore: run formatter
hyperswitch-bot[bot] Dec 5, 2023
0348d18
chore: pull schema.rs from main
prajjwalkumar17 Dec 5, 2023
ee32675
Merge branch 'feat/block_paymentmethod' of https://github.com/juspay/…
prajjwalkumar17 Dec 5, 2023
bdbb6b5
chore: added the card fingerprint generation in payment confirm's upd…
prajjwalkumar17 Dec 11, 2023
bc0a0d2
Merge branch 'main' into feat/block_paymentmethod
prajjwalkumar17 Dec 11, 2023
797a538
chore: run formatter
hyperswitch-bot[bot] Dec 11, 2023
ac19744
chore: add new tables pm_blocklist and pm_fingerprints and a new colo…
prajjwalkumar17 Dec 12, 2023
8715fbf
chore: run formatter
hyperswitch-bot[bot] Dec 12, 2023
ddcdc74
chore: block, unblock & blocklist api working with 2 tables up namely…
prajjwalkumar17 Dec 18, 2023
7dee9c9
Merge branch 'feat/block_paymentmethod' of https://github.com/juspay/…
prajjwalkumar17 Dec 18, 2023
4558f4d
Merge branch 'main' into feat/block_paymentmethod
prajjwalkumar17 Dec 18, 2023
3133fc8
chore: run formatter
hyperswitch-bot[bot] Dec 18, 2023
e6bd5c6
chore: complete interfacing of blocklist_lookup table
prajjwalkumar17 Dec 18, 2023
84014ef
chore: run formatter
hyperswitch-bot[bot] Dec 18, 2023
ee8386d
chore: complete flow working without kms encryptions
prajjwalkumar17 Dec 26, 2023
3b6af11
chore: merge main
prajjwalkumar17 Dec 26, 2023
560a8eb
chore: run formatter
hyperswitch-bot[bot] Dec 26, 2023
0c76254
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Dec 26, 2023
077f88f
chore: refactored the response
prajjwalkumar17 Dec 28, 2023
ec5368a
chore: merge main
prajjwalkumar17 Dec 28, 2023
d177c09
chore: run formatter
hyperswitch-bot[bot] Dec 28, 2023
1c7a629
chore: refactored the route to payment_methods prefixed routes
prajjwalkumar17 Jan 2, 2024
488255d
chore: refactored the route to payment_methods prefixed routes
prajjwalkumar17 Jan 2, 2024
058054f
chore: run formatter
hyperswitch-bot[bot] Jan 2, 2024
a4543a0
chore: complete implementation without kms
prajjwalkumar17 Jan 4, 2024
531d1a7
chore: complete implementation without kms
prajjwalkumar17 Jan 4, 2024
68599d4
Merge branch 'main' into feat/block_paymentmethod
prajjwalkumar17 Jan 4, 2024
87a2875
chore: run formatter
hyperswitch-bot[bot] Jan 4, 2024
e0ec646
chore: complete implementation without kms flag
prajjwalkumar17 Jan 4, 2024
aa87be3
chore: run formatter
hyperswitch-bot[bot] Jan 4, 2024
cea6894
chore: complete implementation with kms flags
prajjwalkumar17 Jan 4, 2024
84f941b
Merge branch 'feat/block_paymentmethod' of https://github.com/juspay/…
prajjwalkumar17 Jan 4, 2024
0e19c8c
chore: run formatter
hyperswitch-bot[bot] Jan 4, 2024
0953a06
chore: addressed comments
prajjwalkumar17 Jan 5, 2024
e038a71
Merge branch 'feat/block_paymentmethod' of https://github.com/juspay/…
prajjwalkumar17 Jan 5, 2024
f39aebd
Merge branch 'main' into feat/block_paymentmethod
prajjwalkumar17 Jan 5, 2024
4c2fe79
Merge branch 'main' into feat/block_paymentmethod
prajjwalkumar17 Jan 5, 2024
673762d
chore: added the kms as well as non kms flow
prajjwalkumar17 Jan 9, 2024
97f86a4
chore: resolved conflicts
prajjwalkumar17 Jan 9, 2024
5536a09
chore: run formatter
hyperswitch-bot[bot] Jan 9, 2024
d9d3760
chore: resolved conflicts
prajjwalkumar17 Jan 9, 2024
b32f1f2
Merge branch 'feat/block_paymentmethod' of https://github.com/juspay/…
prajjwalkumar17 Jan 9, 2024
1e42151
Merge branch 'main' into feat/block_paymentmethod
prajjwalkumar17 Jan 9, 2024
a901e76
chore: addressed comments
prajjwalkumar17 Jan 10, 2024
da421cd
chore: run formatter
hyperswitch-bot[bot] Jan 10, 2024
ed791f6
refactor(router): refactor the blocklist feature with quality of life…
vspecky Jan 10, 2024
767cce6
fix(router): remove redundant feature flag
vspecky Jan 10, 2024
91a5711
refactor(router): remove redundant code for blocklist
vspecky Jan 11, 2024
947d197
refactor(router): update flow name and permissions for blocklist APIs
vspecky Jan 11, 2024
18e5d31
Merge branch 'main' into feat/block_paymentmethod
prajjwalkumar17 Jan 11, 2024
5864ae1
refactor(router): changed the read permissions
prajjwalkumar17 Jan 11, 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
41 changes: 41 additions & 0 deletions crates/api_models/src/blocklist.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use common_enums::enums;
use common_utils::events::ApiEventMetric;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case", tag = "type", content = "data")]
pub enum BlocklistRequest {
CardBin(String),
Fingerprint(String),
ExtendedCardBin(String),
}

pub type AddToBlocklistRequest = BlocklistRequest;
pub type DeleteFromBlocklistRequest = BlocklistRequest;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct BlocklistResponse {
pub fingerprint_id: String,
pub data_kind: enums::BlocklistDataKind,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub created_at: time::PrimitiveDateTime,
}

pub type AddToBlocklistResponse = BlocklistResponse;
pub type DeleteFromBlocklistResponse = BlocklistResponse;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ListBlocklistQuery {
pub data_kind: enums::BlocklistDataKind,
#[serde(default = "default_list_limit")]
pub limit: u16,
#[serde(default)]
pub offset: u16,
}

fn default_list_limit() -> u16 {
10
}

impl ApiEventMetric for BlocklistRequest {}
impl ApiEventMetric for BlocklistResponse {}
impl ApiEventMetric for ListBlocklistQuery {}
1 change: 1 addition & 0 deletions crates/api_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod admin;
pub mod analytics;
pub mod api_keys;
pub mod bank_accounts;
pub mod blocklist;
pub mod cards_info;
pub mod conditional_configs;
pub mod connector_onboarding;
Expand Down
3 changes: 3 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,9 @@ pub struct PaymentsResponse {

/// List of incremental authorizations happened to the payment
pub incremental_authorizations: Option<Vec<IncrementalAuthorizationResponse>>,

/// Payment Fingerprint
pub fingerprint: Option<String>,
}

#[derive(Clone, Debug, serde::Deserialize, ToSchema, serde::Serialize)]
Expand Down
7 changes: 7 additions & 0 deletions crates/cards/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ impl CardNumber {
pub fn get_card_isin(self) -> String {
self.0.peek().chars().take(6).collect::<String>()
}

pub fn get_extended_card_bin(self) -> String {
self.0.peek().chars().take(8).collect::<String>()
}
pub fn get_card_no(self) -> String {
prajjwalkumar17 marked this conversation as resolved.
Show resolved Hide resolved
self.0.peek().chars().collect::<String>()
}
pub fn get_last4(self) -> String {
self.0
.peek()
Expand Down
34 changes: 28 additions & 6 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use utoipa::ToSchema;
pub mod diesel_exports {
pub use super::{
DbAttemptStatus as AttemptStatus, DbAuthenticationType as AuthenticationType,
DbCaptureMethod as CaptureMethod, DbCaptureStatus as CaptureStatus,
DbConnectorType as ConnectorType, DbCountryAlpha2 as CountryAlpha2, DbCurrency as Currency,
DbDisputeStage as DisputeStage, DbDisputeStatus as DisputeStatus, DbEventType as EventType,
DbFutureUsage as FutureUsage, DbIntentStatus as IntentStatus,
DbMandateStatus as MandateStatus, DbPaymentMethodIssuerCode as PaymentMethodIssuerCode,
DbPaymentType as PaymentType, DbRefundStatus as RefundStatus,
DbBlocklistDataKind as BlocklistDataKind, DbCaptureMethod as CaptureMethod,
DbCaptureStatus as CaptureStatus, DbConnectorType as ConnectorType,
DbCountryAlpha2 as CountryAlpha2, DbCurrency as Currency, DbDisputeStage as DisputeStage,
DbDisputeStatus as DisputeStatus, DbEventType as EventType, DbFutureUsage as FutureUsage,
DbIntentStatus as IntentStatus, DbMandateStatus as MandateStatus,
DbPaymentMethodIssuerCode as PaymentMethodIssuerCode, DbPaymentType as PaymentType,
DbRefundStatus as RefundStatus,
DbRequestIncrementalAuthorization as RequestIncrementalAuthorization,
};
}
Expand Down Expand Up @@ -275,6 +276,27 @@ pub enum AuthorizationStatus {
Unresolved,
}

#[derive(
Clone,
Debug,
PartialEq,
Eq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
Hash,
)]
#[router_derive::diesel_enum(storage_type = "db_enum")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum BlocklistDataKind {
PaymentMethod,
CardBin,
ExtendedCardBin,
}

#[derive(
Clone,
Copy,
Expand Down
2 changes: 2 additions & 0 deletions crates/data_models/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub enum StorageError {
SerializationFailed,
#[error("MockDb error")]
MockDbError,
#[error("Kafka error")]
KafkaError,
#[error("Customer with this id is Redacted")]
CustomerRedacted,
#[error("Deserialization failure")]
Expand Down
1 change: 1 addition & 0 deletions crates/data_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ pub struct PaymentIntent {
pub request_incremental_authorization: Option<storage_enums::RequestIncrementalAuthorization>,
pub incremental_authorization_allowed: Option<bool>,
pub authorization_count: Option<i32>,
pub fingerprint_id: Option<String>,
prajjwalkumar17 marked this conversation as resolved.
Show resolved Hide resolved
pub session_expiry: Option<PrimitiveDateTime>,
}
5 changes: 5 additions & 0 deletions crates/data_models/src/payments/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub struct PaymentIntentNew {
pub request_incremental_authorization: Option<storage_enums::RequestIncrementalAuthorization>,
pub incremental_authorization_allowed: Option<bool>,
pub authorization_count: Option<i32>,
pub fingerprint_id: Option<String>,
pub session_expiry: Option<PrimitiveDateTime>,
}

Expand Down Expand Up @@ -163,6 +164,7 @@ pub enum PaymentIntentUpdate {
metadata: Option<pii::SecretSerdeValue>,
payment_confirm_source: Option<storage_enums::PaymentSource>,
updated_by: String,
fingerprint_id: Option<String>,
session_expiry: Option<PrimitiveDateTime>,
},
PaymentAttemptAndAttemptCountUpdate {
Expand Down Expand Up @@ -228,6 +230,7 @@ pub struct PaymentIntentUpdateInternal {
pub surcharge_applicable: Option<bool>,
pub incremental_authorization_allowed: Option<bool>,
pub authorization_count: Option<i32>,
pub fingerprint_id: Option<String>,
pub session_expiry: Option<PrimitiveDateTime>,
}

Expand All @@ -252,6 +255,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
metadata,
payment_confirm_source,
updated_by,
fingerprint_id,
session_expiry,
} => Self {
amount: Some(amount),
Expand All @@ -272,6 +276,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
metadata,
payment_confirm_source,
updated_by,
fingerprint_id,
session_expiry,
..Default::default()
},
Expand Down
26 changes: 26 additions & 0 deletions crates/diesel_models/src/blocklist.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use diesel::{Identifiable, Insertable, Queryable};
use serde::{Deserialize, Serialize};

use crate::schema::blocklist;

#[derive(Clone, Debug, Eq, Insertable, PartialEq, Serialize, Deserialize)]
#[diesel(table_name = blocklist)]
pub struct BlocklistNew {
pub merchant_id: String,
pub fingerprint_id: String,
pub data_kind: common_enums::BlocklistDataKind,
pub metadata: Option<serde_json::Value>,
pub created_at: time::PrimitiveDateTime,
}

#[derive(Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Deserialize, Serialize)]
#[diesel(table_name = blocklist)]
pub struct Blocklist {
#[serde(skip)]
pub id: i32,
pub merchant_id: String,
pub fingerprint_id: String,
pub data_kind: common_enums::BlocklistDataKind,
pub metadata: Option<serde_json::Value>,
pub created_at: time::PrimitiveDateTime,
}
26 changes: 26 additions & 0 deletions crates/diesel_models/src/blocklist_fingerprint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use diesel::{Identifiable, Insertable, Queryable};
use serde::{Deserialize, Serialize};

use crate::schema::blocklist_fingerprint;

#[derive(Clone, Debug, Eq, Insertable, PartialEq, Serialize, Deserialize)]
#[diesel(table_name = blocklist_fingerprint)]
pub struct BlocklistFingerprintNew {
pub merchant_id: String,
pub fingerprint_id: String,
pub data_kind: common_enums::BlocklistDataKind,
pub encrypted_fingerprint: String,
pub created_at: time::PrimitiveDateTime,
}

#[derive(Clone, Debug, Eq, PartialEq, Queryable, Identifiable, Deserialize, Serialize)]
#[diesel(table_name = blocklist_fingerprint)]
pub struct BlocklistFingerprint {
#[serde(skip_serializing)]
pub id: i32,
pub merchant_id: String,
pub fingerprint_id: String,
pub data_kind: common_enums::BlocklistDataKind,
pub encrypted_fingerprint: String,
pub created_at: time::PrimitiveDateTime,
}
20 changes: 20 additions & 0 deletions crates/diesel_models/src/blocklist_lookup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use diesel::{Identifiable, Insertable, Queryable};
use serde::{Deserialize, Serialize};

use crate::schema::blocklist_lookup;

#[derive(Default, Clone, Debug, Eq, Insertable, PartialEq, Serialize, Deserialize)]
#[diesel(table_name = blocklist_lookup)]
pub struct BlocklistLookupNew {
pub merchant_id: String,
pub fingerprint: String,
}

#[derive(Default, Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Deserialize, Serialize)]
#[diesel(table_name = blocklist_lookup)]
pub struct BlocklistLookup {
#[serde(skip)]
pub id: i32,
pub merchant_id: String,
pub fingerprint: String,
}
6 changes: 3 additions & 3 deletions crates/diesel_models/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pub mod diesel_exports {
pub use super::{
DbAttemptStatus as AttemptStatus, DbAuthenticationType as AuthenticationType,
DbCaptureMethod as CaptureMethod, DbCaptureStatus as CaptureStatus,
DbConnectorStatus as ConnectorStatus, DbConnectorType as ConnectorType,
DbCountryAlpha2 as CountryAlpha2, DbCurrency as Currency,
DbBlocklistDataKind as BlocklistDataKind, DbCaptureMethod as CaptureMethod,
DbCaptureStatus as CaptureStatus, DbConnectorStatus as ConnectorStatus,
DbConnectorType as ConnectorType, DbCountryAlpha2 as CountryAlpha2, DbCurrency as Currency,
DbDashboardMetadata as DashboardMetadata, DbDisputeStage as DisputeStage,
DbDisputeStatus as DisputeStatus, DbEventClass as EventClass,
DbEventObjectType as EventObjectType, DbEventType as EventType,
Expand Down
3 changes: 3 additions & 0 deletions crates/diesel_models/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
pub mod address;
pub mod api_keys;
pub mod blocklist_lookup;
pub mod business_profile;
pub mod capture;
pub mod cards_info;
pub mod configs;

pub mod authorization;
pub mod blocklist;
pub mod blocklist_fingerprint;
pub mod customers;
pub mod dispute;
pub mod encryption;
Expand Down
9 changes: 9 additions & 0 deletions crates/diesel_models/src/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct PaymentIntent {
pub incremental_authorization_allowed: Option<bool>,
pub authorization_count: Option<i32>,
pub session_expiry: Option<PrimitiveDateTime>,
pub fingerprint_id: Option<String>,
}

#[derive(
Expand Down Expand Up @@ -107,6 +108,7 @@ pub struct PaymentIntentNew {
pub authorization_count: Option<i32>,
#[serde(with = "common_utils::custom_serde::iso8601::option")]
pub session_expiry: Option<PrimitiveDateTime>,
pub fingerprint_id: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -160,6 +162,7 @@ pub enum PaymentIntentUpdate {
payment_confirm_source: Option<storage_enums::PaymentSource>,
updated_by: String,
session_expiry: Option<PrimitiveDateTime>,
fingerprint_id: Option<String>,
},
PaymentAttemptAndAttemptCountUpdate {
active_attempt_id: String,
Expand Down Expand Up @@ -226,6 +229,7 @@ pub struct PaymentIntentUpdateInternal {
pub incremental_authorization_allowed: Option<bool>,
pub authorization_count: Option<i32>,
pub session_expiry: Option<PrimitiveDateTime>,
pub fingerprint_id: Option<String>,
}

impl PaymentIntentUpdate {
Expand Down Expand Up @@ -259,6 +263,7 @@ impl PaymentIntentUpdate {
incremental_authorization_allowed,
authorization_count,
session_expiry,
fingerprint_id,
} = self.into();
PaymentIntent {
amount: amount.unwrap_or(source.amount),
Expand Down Expand Up @@ -288,10 +293,12 @@ impl PaymentIntentUpdate {
payment_confirm_source: payment_confirm_source.or(source.payment_confirm_source),
updated_by,
surcharge_applicable: surcharge_applicable.or(source.surcharge_applicable),

incremental_authorization_allowed: incremental_authorization_allowed
.or(source.incremental_authorization_allowed),
authorization_count: authorization_count.or(source.authorization_count),
session_expiry,
fingerprint_id: fingerprint_id.or(source.fingerprint_id),
..source
}
}
Expand Down Expand Up @@ -319,6 +326,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
payment_confirm_source,
updated_by,
session_expiry,
fingerprint_id,
} => Self {
amount: Some(amount),
currency: Some(currency),
Expand All @@ -339,6 +347,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
payment_confirm_source,
updated_by,
session_expiry,
fingerprint_id,
..Default::default()
},
PaymentIntentUpdate::MetadataUpdate {
Expand Down
3 changes: 3 additions & 0 deletions crates/diesel_models/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
pub mod address;
pub mod api_keys;
pub mod blocklist_lookup;
pub mod business_profile;
mod capture;
pub mod cards_info;
pub mod configs;

pub mod authorization;
pub mod blocklist;
pub mod blocklist_fingerprint;
pub mod customers;
pub mod dashboard_metadata;
pub mod dispute;
Expand Down
Loading
Loading