mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
feat(router): add organization_id in authentication table and add it in authentication events (#7168)
This commit is contained in:
committed by
GitHub
parent
9b1b245564
commit
f2117542a7
@ -35,6 +35,7 @@ CREATE TABLE authentication_queue (
|
|||||||
`ds_trans_id` Nullable(String),
|
`ds_trans_id` Nullable(String),
|
||||||
`directory_server_id` Nullable(String),
|
`directory_server_id` Nullable(String),
|
||||||
`acquirer_country_code` Nullable(String),
|
`acquirer_country_code` Nullable(String),
|
||||||
|
`organization_id` String,
|
||||||
`sign_flag` Int8
|
`sign_flag` Int8
|
||||||
) ENGINE = Kafka SETTINGS kafka_broker_list = 'kafka0:29092',
|
) ENGINE = Kafka SETTINGS kafka_broker_list = 'kafka0:29092',
|
||||||
kafka_topic_list = 'hyperswitch-authentication-events',
|
kafka_topic_list = 'hyperswitch-authentication-events',
|
||||||
@ -80,6 +81,7 @@ CREATE TABLE authentications (
|
|||||||
`ds_trans_id` Nullable(String),
|
`ds_trans_id` Nullable(String),
|
||||||
`directory_server_id` Nullable(String),
|
`directory_server_id` Nullable(String),
|
||||||
`acquirer_country_code` Nullable(String),
|
`acquirer_country_code` Nullable(String),
|
||||||
|
`organization_id` String,
|
||||||
`sign_flag` Int8,
|
`sign_flag` Int8,
|
||||||
INDEX authenticationConnectorIndex authentication_connector TYPE bloom_filter GRANULARITY 1,
|
INDEX authenticationConnectorIndex authentication_connector TYPE bloom_filter GRANULARITY 1,
|
||||||
INDEX transStatusIndex trans_status TYPE bloom_filter GRANULARITY 1,
|
INDEX transStatusIndex trans_status TYPE bloom_filter GRANULARITY 1,
|
||||||
@ -127,6 +129,7 @@ CREATE MATERIALIZED VIEW authentication_mv TO authentications (
|
|||||||
`ds_trans_id` Nullable(String),
|
`ds_trans_id` Nullable(String),
|
||||||
`directory_server_id` Nullable(String),
|
`directory_server_id` Nullable(String),
|
||||||
`acquirer_country_code` Nullable(String),
|
`acquirer_country_code` Nullable(String),
|
||||||
|
`organization_id` String,
|
||||||
`sign_flag` Int8
|
`sign_flag` Int8
|
||||||
) AS
|
) AS
|
||||||
SELECT
|
SELECT
|
||||||
@ -167,6 +170,7 @@ SELECT
|
|||||||
ds_trans_id,
|
ds_trans_id,
|
||||||
directory_server_id,
|
directory_server_id,
|
||||||
acquirer_country_code,
|
acquirer_country_code,
|
||||||
|
organization_id,
|
||||||
sign_flag
|
sign_flag
|
||||||
FROM
|
FROM
|
||||||
authentication_queue
|
authentication_queue
|
||||||
|
|||||||
@ -48,6 +48,7 @@ pub struct Authentication {
|
|||||||
pub directory_server_id: Option<String>,
|
pub directory_server_id: Option<String>,
|
||||||
pub acquirer_country_code: Option<String>,
|
pub acquirer_country_code: Option<String>,
|
||||||
pub service_details: Option<serde_json::Value>,
|
pub service_details: Option<serde_json::Value>,
|
||||||
|
pub organization_id: common_utils::id_type::OrganizationId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Authentication {
|
impl Authentication {
|
||||||
@ -96,6 +97,7 @@ pub struct AuthenticationNew {
|
|||||||
pub directory_server_id: Option<String>,
|
pub directory_server_id: Option<String>,
|
||||||
pub acquirer_country_code: Option<String>,
|
pub acquirer_country_code: Option<String>,
|
||||||
pub service_details: Option<serde_json::Value>,
|
pub service_details: Option<serde_json::Value>,
|
||||||
|
pub organization_id: common_utils::id_type::OrganizationId,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
@ -121,6 +121,8 @@ diesel::table! {
|
|||||||
#[max_length = 64]
|
#[max_length = 64]
|
||||||
acquirer_country_code -> Nullable<Varchar>,
|
acquirer_country_code -> Nullable<Varchar>,
|
||||||
service_details -> Nullable<Jsonb>,
|
service_details -> Nullable<Jsonb>,
|
||||||
|
#[max_length = 32]
|
||||||
|
organization_id -> Varchar,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -122,6 +122,8 @@ diesel::table! {
|
|||||||
#[max_length = 64]
|
#[max_length = 64]
|
||||||
acquirer_country_code -> Nullable<Varchar>,
|
acquirer_country_code -> Nullable<Varchar>,
|
||||||
service_details -> Nullable<Jsonb>,
|
service_details -> Nullable<Jsonb>,
|
||||||
|
#[max_length = 32]
|
||||||
|
organization_id -> Varchar,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -124,6 +124,7 @@ pub async fn perform_post_authentication(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn perform_pre_authentication(
|
pub async fn perform_pre_authentication(
|
||||||
state: &SessionState,
|
state: &SessionState,
|
||||||
key_store: &domain::MerchantKeyStore,
|
key_store: &domain::MerchantKeyStore,
|
||||||
@ -132,6 +133,7 @@ pub async fn perform_pre_authentication(
|
|||||||
business_profile: &domain::Profile,
|
business_profile: &domain::Profile,
|
||||||
acquirer_details: Option<types::AcquirerDetails>,
|
acquirer_details: Option<types::AcquirerDetails>,
|
||||||
payment_id: Option<common_utils::id_type::PaymentId>,
|
payment_id: Option<common_utils::id_type::PaymentId>,
|
||||||
|
organization_id: common_utils::id_type::OrganizationId,
|
||||||
) -> CustomResult<storage::Authentication, ApiErrorResponse> {
|
) -> CustomResult<storage::Authentication, ApiErrorResponse> {
|
||||||
let (authentication_connector, three_ds_connector_account) =
|
let (authentication_connector, three_ds_connector_account) =
|
||||||
utils::get_authentication_connector_data(state, key_store, business_profile).await?;
|
utils::get_authentication_connector_data(state, key_store, business_profile).await?;
|
||||||
@ -147,6 +149,7 @@ pub async fn perform_pre_authentication(
|
|||||||
.get_mca_id()
|
.get_mca_id()
|
||||||
.ok_or(ApiErrorResponse::InternalServerError)
|
.ok_or(ApiErrorResponse::InternalServerError)
|
||||||
.attach_printable("Error while finding mca_id from merchant_connector_account")?,
|
.attach_printable("Error while finding mca_id from merchant_connector_account")?,
|
||||||
|
organization_id,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@ -174,6 +174,7 @@ impl ForeignFrom<common_enums::AuthenticationStatus> for common_enums::AttemptSt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn create_new_authentication(
|
pub async fn create_new_authentication(
|
||||||
state: &SessionState,
|
state: &SessionState,
|
||||||
merchant_id: common_utils::id_type::MerchantId,
|
merchant_id: common_utils::id_type::MerchantId,
|
||||||
@ -182,6 +183,7 @@ pub async fn create_new_authentication(
|
|||||||
profile_id: common_utils::id_type::ProfileId,
|
profile_id: common_utils::id_type::ProfileId,
|
||||||
payment_id: Option<common_utils::id_type::PaymentId>,
|
payment_id: Option<common_utils::id_type::PaymentId>,
|
||||||
merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
|
merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
|
||||||
|
organization_id: common_utils::id_type::OrganizationId,
|
||||||
) -> RouterResult<storage::Authentication> {
|
) -> RouterResult<storage::Authentication> {
|
||||||
let authentication_id =
|
let authentication_id =
|
||||||
common_utils::generate_id_with_default_len(consts::AUTHENTICATION_ID_PREFIX);
|
common_utils::generate_id_with_default_len(consts::AUTHENTICATION_ID_PREFIX);
|
||||||
@ -220,6 +222,7 @@ pub async fn create_new_authentication(
|
|||||||
directory_server_id: None,
|
directory_server_id: None,
|
||||||
acquirer_country_code: None,
|
acquirer_country_code: None,
|
||||||
service_details: None,
|
service_details: None,
|
||||||
|
organization_id,
|
||||||
};
|
};
|
||||||
state
|
state
|
||||||
.store
|
.store
|
||||||
|
|||||||
@ -983,6 +983,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
|
|||||||
business_profile,
|
business_profile,
|
||||||
Some(acquirer_details),
|
Some(acquirer_details),
|
||||||
Some(payment_data.payment_attempt.payment_id.clone()),
|
Some(payment_data.payment_attempt.payment_id.clone()),
|
||||||
|
payment_data.payment_attempt.organization_id.clone(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
if authentication.is_separate_authn_required()
|
if authentication.is_separate_authn_required()
|
||||||
@ -1175,6 +1176,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
|
|||||||
&authentication_id,
|
&authentication_id,
|
||||||
payment_data.service_details.clone(),
|
payment_data.service_details.clone(),
|
||||||
authentication_status,
|
authentication_status,
|
||||||
|
payment_data.payment_attempt.organization_id.clone(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
},
|
},
|
||||||
@ -1197,6 +1199,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
|
|||||||
.get_mca_id()
|
.get_mca_id()
|
||||||
.ok_or(errors::ApiErrorResponse::InternalServerError)
|
.ok_or(errors::ApiErrorResponse::InternalServerError)
|
||||||
.attach_printable("Error while finding mca_id from merchant_connector_account")?,
|
.attach_printable("Error while finding mca_id from merchant_connector_account")?,
|
||||||
|
payment_data.payment_attempt.organization_id.clone(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@ -410,6 +410,7 @@ pub async fn create_new_authentication(
|
|||||||
authentication_id: &str,
|
authentication_id: &str,
|
||||||
service_details: Option<payments::CtpServiceDetails>,
|
service_details: Option<payments::CtpServiceDetails>,
|
||||||
authentication_status: common_enums::AuthenticationStatus,
|
authentication_status: common_enums::AuthenticationStatus,
|
||||||
|
organization_id: common_utils::id_type::OrganizationId,
|
||||||
) -> RouterResult<Authentication> {
|
) -> RouterResult<Authentication> {
|
||||||
let service_details_value = service_details
|
let service_details_value = service_details
|
||||||
.map(serde_json::to_value)
|
.map(serde_json::to_value)
|
||||||
@ -453,6 +454,7 @@ pub async fn create_new_authentication(
|
|||||||
directory_server_id: None,
|
directory_server_id: None,
|
||||||
acquirer_country_code: None,
|
acquirer_country_code: None,
|
||||||
service_details: service_details_value,
|
service_details: service_details_value,
|
||||||
|
organization_id,
|
||||||
};
|
};
|
||||||
state
|
state
|
||||||
.store
|
.store
|
||||||
|
|||||||
@ -151,6 +151,7 @@ impl AuthenticationInterface for MockDb {
|
|||||||
directory_server_id: authentication.directory_server_id,
|
directory_server_id: authentication.directory_server_id,
|
||||||
acquirer_country_code: authentication.acquirer_country_code,
|
acquirer_country_code: authentication.acquirer_country_code,
|
||||||
service_details: authentication.service_details,
|
service_details: authentication.service_details,
|
||||||
|
organization_id: authentication.organization_id,
|
||||||
};
|
};
|
||||||
authentications.push(authentication.clone());
|
authentications.push(authentication.clone());
|
||||||
Ok(authentication)
|
Ok(authentication)
|
||||||
|
|||||||
@ -41,6 +41,7 @@ pub struct KafkaAuthentication<'a> {
|
|||||||
pub ds_trans_id: Option<&'a String>,
|
pub ds_trans_id: Option<&'a String>,
|
||||||
pub directory_server_id: Option<&'a String>,
|
pub directory_server_id: Option<&'a String>,
|
||||||
pub acquirer_country_code: Option<&'a String>,
|
pub acquirer_country_code: Option<&'a String>,
|
||||||
|
pub organization_id: &'a common_utils::id_type::OrganizationId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> KafkaAuthentication<'a> {
|
impl<'a> KafkaAuthentication<'a> {
|
||||||
@ -82,6 +83,7 @@ impl<'a> KafkaAuthentication<'a> {
|
|||||||
ds_trans_id: authentication.ds_trans_id.as_ref(),
|
ds_trans_id: authentication.ds_trans_id.as_ref(),
|
||||||
directory_server_id: authentication.directory_server_id.as_ref(),
|
directory_server_id: authentication.directory_server_id.as_ref(),
|
||||||
acquirer_country_code: authentication.acquirer_country_code.as_ref(),
|
acquirer_country_code: authentication.acquirer_country_code.as_ref(),
|
||||||
|
organization_id: &authentication.organization_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,6 +42,7 @@ pub struct KafkaAuthenticationEvent<'a> {
|
|||||||
pub ds_trans_id: Option<&'a String>,
|
pub ds_trans_id: Option<&'a String>,
|
||||||
pub directory_server_id: Option<&'a String>,
|
pub directory_server_id: Option<&'a String>,
|
||||||
pub acquirer_country_code: Option<&'a String>,
|
pub acquirer_country_code: Option<&'a String>,
|
||||||
|
pub organization_id: &'a common_utils::id_type::OrganizationId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> KafkaAuthenticationEvent<'a> {
|
impl<'a> KafkaAuthenticationEvent<'a> {
|
||||||
@ -83,6 +84,7 @@ impl<'a> KafkaAuthenticationEvent<'a> {
|
|||||||
ds_trans_id: authentication.ds_trans_id.as_ref(),
|
ds_trans_id: authentication.ds_trans_id.as_ref(),
|
||||||
directory_server_id: authentication.directory_server_id.as_ref(),
|
directory_server_id: authentication.directory_server_id.as_ref(),
|
||||||
acquirer_country_code: authentication.acquirer_country_code.as_ref(),
|
acquirer_country_code: authentication.acquirer_country_code.as_ref(),
|
||||||
|
organization_id: &authentication.organization_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
-- This file should undo anything in `up.sql`
|
||||||
|
ALTER TABLE authentication
|
||||||
|
DROP COLUMN IF EXISTS organization_id;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
-- Your SQL goes here
|
||||||
|
ALTER TABLE authentication
|
||||||
|
ADD COLUMN IF NOT EXISTS organization_id VARCHAR(32) NOT NULL DEFAULT 'default_org';
|
||||||
Reference in New Issue
Block a user