Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into frm_oss
Browse files Browse the repository at this point in the history
  • Loading branch information
Kashif committed Nov 30, 2023
2 parents 319a0cc + 6a2e4ab commit 22d4e72
Show file tree
Hide file tree
Showing 31 changed files with 1,473 additions and 30 deletions.
15 changes: 13 additions & 2 deletions crates/api_models/src/events/user.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use common_utils::events::{ApiEventMetric, ApiEventsType};

use crate::user::{ChangePasswordRequest, ConnectAccountRequest, ConnectAccountResponse};
use crate::user::{
dashboard_metadata::{
GetMetaDataRequest, GetMetaDataResponse, GetMultipleMetaDataPayload, SetMetaDataRequest,
},
ChangePasswordRequest, ConnectAccountRequest, ConnectAccountResponse,
};

impl ApiEventMetric for ConnectAccountResponse {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Expand All @@ -13,4 +18,10 @@ impl ApiEventMetric for ConnectAccountResponse {

impl ApiEventMetric for ConnectAccountRequest {}

common_utils::impl_misc_api_event_type!(ChangePasswordRequest);
common_utils::impl_misc_api_event_type!(
ChangePasswordRequest,
GetMultipleMetaDataPayload,
GetMetaDataResponse,
GetMetaDataRequest,
SetMetaDataRequest
);
1 change: 1 addition & 0 deletions crates/api_models/src/user.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use common_utils::pii;
use masking::Secret;
pub mod dashboard_metadata;

#[derive(serde::Deserialize, Debug, Clone, serde::Serialize)]
pub struct ConnectAccountRequest {
Expand Down
110 changes: 110 additions & 0 deletions crates/api_models/src/user/dashboard_metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
use masking::Secret;
use strum::EnumString;

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub enum SetMetaDataRequest {
ProductionAgreement(ProductionAgreementRequest),
SetupProcessor(SetupProcessor),
ConfigureEndpoint,
SetupComplete,
FirstProcessorConnected(ProcessorConnected),
SecondProcessorConnected(ProcessorConnected),
ConfiguredRouting(ConfiguredRouting),
TestPayment(TestPayment),
IntegrationMethod(IntegrationMethod),
IntegrationCompleted,
SPRoutingConfigured(ConfiguredRouting),
SPTestPayment,
DownloadWoocom,
ConfigureWoocom,
SetupWoocomWebhook,
IsMultipleConfiguration,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct ProductionAgreementRequest {
pub version: String,
#[serde(skip_deserializing)]
pub ip_address: Option<Secret<String, common_utils::pii::IpAddress>>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct SetupProcessor {
pub connector_id: String,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct ProcessorConnected {
pub processor_id: String,
pub processor_name: String,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct ConfiguredRouting {
pub routing_id: String,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct TestPayment {
pub payment_id: String,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct IntegrationMethod {
pub integration_type: String,
}

#[derive(Debug, serde::Deserialize, EnumString, serde::Serialize)]
pub enum GetMetaDataRequest {
ProductionAgreement,
SetupProcessor,
ConfigureEndpoint,
SetupComplete,
FirstProcessorConnected,
SecondProcessorConnected,
ConfiguredRouting,
TestPayment,
IntegrationMethod,
IntegrationCompleted,
StripeConnected,
PaypalConnected,
SPRoutingConfigured,
SPTestPayment,
DownloadWoocom,
ConfigureWoocom,
SetupWoocomWebhook,
IsMultipleConfiguration,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[serde(transparent)]
pub struct GetMultipleMetaDataPayload {
pub results: Vec<GetMetaDataRequest>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct GetMultipleMetaDataRequest {
pub keys: String,
}

#[derive(Debug, serde::Serialize)]
pub enum GetMetaDataResponse {
ProductionAgreement(bool),
SetupProcessor(Option<SetupProcessor>),
ConfigureEndpoint(bool),
SetupComplete(bool),
FirstProcessorConnected(Option<ProcessorConnected>),
SecondProcessorConnected(Option<ProcessorConnected>),
ConfiguredRouting(Option<ConfiguredRouting>),
TestPayment(Option<TestPayment>),
IntegrationMethod(Option<IntegrationMethod>),
IntegrationCompleted(bool),
StripeConnected(Option<ProcessorConnected>),
PaypalConnected(Option<ProcessorConnected>),
SPRoutingConfigured(Option<ConfiguredRouting>),
SPTestPayment(bool),
DownloadWoocom(bool),
ConfigureWoocom(bool),
SetupWoocomWebhook(bool),
IsMultipleConfiguration(bool),
}
36 changes: 36 additions & 0 deletions crates/diesel_models/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,39 @@ pub enum UserStatus {
#[default]
InvitationSent,
}

#[derive(
Clone,
Copy,
Debug,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
frunk::LabelledGeneric,
)]
#[router_derive::diesel_enum(storage_type = "text")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum DashboardMetadata {
ProductionAgreement,
SetupProcessor,
ConfigureEndpoint,
SetupComplete,
FirstProcessorConnected,
SecondProcessorConnected,
ConfiguredRouting,
TestPayment,
IntegrationMethod,
IntegrationCompleted,
StripeConnected,
PaypalConnected,
SpRoutingConfigured,
SpTestPayment,
DownloadWoocom,
ConfigureWoocom,
SetupWoocomWebhook,
IsMultipleConfiguration,
}
1 change: 1 addition & 0 deletions crates/diesel_models/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod cards_info;
pub mod configs;

pub mod customers;
pub mod dashboard_metadata;
pub mod dispute;
pub mod events;
pub mod file;
Expand Down
64 changes: 64 additions & 0 deletions crates/diesel_models/src/query/dashboard_metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods};
use router_env::tracing::{self, instrument};

use crate::{
enums,
query::generics,
schema::dashboard_metadata::dsl,
user::dashboard_metadata::{DashboardMetadata, DashboardMetadataNew},
PgPooledConn, StorageResult,
};

impl DashboardMetadataNew {
#[instrument(skip(conn))]
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<DashboardMetadata> {
generics::generic_insert(conn, self).await
}
}

impl DashboardMetadata {
pub async fn find_user_scoped_dashboard_metadata(
conn: &PgPooledConn,
user_id: String,
merchant_id: String,
org_id: String,
data_types: Vec<enums::DashboardMetadata>,
) -> StorageResult<Vec<Self>> {
let predicate = dsl::user_id
.eq(user_id)
.and(dsl::merchant_id.eq(merchant_id))
.and(dsl::org_id.eq(org_id))
.and(dsl::data_key.eq_any(data_types));

generics::generic_filter::<<Self as HasTable>::Table, _, _, _>(
conn,
predicate,
None,
None,
Some(dsl::last_modified_at.asc()),
)
.await
}

pub async fn find_merchant_scoped_dashboard_metadata(
conn: &PgPooledConn,
merchant_id: String,
org_id: String,
data_types: Vec<enums::DashboardMetadata>,
) -> StorageResult<Vec<Self>> {
let predicate = dsl::user_id
.is_null()
.and(dsl::merchant_id.eq(merchant_id))
.and(dsl::org_id.eq(org_id))
.and(dsl::data_key.eq_any(data_types));

generics::generic_filter::<<Self as HasTable>::Table, _, _, _>(
conn,
predicate,
None,
None,
Some(dsl::last_modified_at.asc()),
)
.await
}
}
25 changes: 25 additions & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,30 @@ diesel::table! {
}
}

diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;

dashboard_metadata (id) {
id -> Int4,
#[max_length = 64]
user_id -> Nullable<Varchar>,
#[max_length = 64]
merchant_id -> Varchar,
#[max_length = 64]
org_id -> Varchar,
#[max_length = 64]
data_key -> Varchar,
data_value -> Json,
#[max_length = 64]
created_by -> Varchar,
created_at -> Timestamp,
#[max_length = 64]
last_modified_by -> Varchar,
last_modified_at -> Timestamp,
}
}

diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;
Expand Down Expand Up @@ -965,6 +989,7 @@ diesel::allow_tables_to_appear_in_same_query!(
cards_info,
configs,
customers,
dashboard_metadata,
dispute,
events,
file_metadata,
Expand Down
2 changes: 2 additions & 0 deletions crates/diesel_models/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use time::PrimitiveDateTime;

use crate::schema::users;

pub mod dashboard_metadata;

#[derive(Clone, Debug, Identifiable, Queryable)]
#[diesel(table_name = users)]
pub struct User {
Expand Down
35 changes: 35 additions & 0 deletions crates/diesel_models/src/user/dashboard_metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use diesel::{query_builder::AsChangeset, Identifiable, Insertable, Queryable};
use time::PrimitiveDateTime;

use crate::{enums, schema::dashboard_metadata};

#[derive(Clone, Debug, Identifiable, Queryable)]
#[diesel(table_name = dashboard_metadata)]
pub struct DashboardMetadata {
pub id: i32,
pub user_id: Option<String>,
pub merchant_id: String,
pub org_id: String,
pub data_key: enums::DashboardMetadata,
pub data_value: serde_json::Value,
pub created_by: String,
pub created_at: PrimitiveDateTime,
pub last_modified_by: String,
pub last_modified_at: PrimitiveDateTime,
}

#[derive(
router_derive::Setter, Clone, Debug, Insertable, router_derive::DebugAsDisplay, AsChangeset,
)]
#[diesel(table_name = dashboard_metadata)]
pub struct DashboardMetadataNew {
pub user_id: Option<String>,
pub merchant_id: String,
pub org_id: String,
pub data_key: enums::DashboardMetadata,
pub data_value: serde_json::Value,
pub created_by: String,
pub created_at: PrimitiveDateTime,
pub last_modified_by: String,
pub last_modified_at: PrimitiveDateTime,
}
17 changes: 7 additions & 10 deletions crates/router/src/connector/cybersource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,18 +307,15 @@ impl
data: &types::SetupMandateRouterData,
res: types::Response,
) -> CustomResult<types::SetupMandateRouterData, errors::ConnectorError> {
let response: cybersource::CybersourcePaymentsResponse = res
let response: cybersource::CybersourceSetupMandatesResponse = res
.response
.parse_struct("CybersourceMandateResponse")
.parse_struct("CybersourceSetupMandatesResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
types::RouterData::try_from((
types::ResponseRouterData {
response,
data: data.clone(),
http_code: res.status_code,
},
false,
))
types::RouterData::try_from(types::ResponseRouterData {
response,
data: data.clone(),
http_code: res.status_code,
})
}

fn get_error_response(
Expand Down
Loading

0 comments on commit 22d4e72

Please sign in to comment.