Skip to content

Commit

Permalink
refactor(core): resolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
sahkal committed Dec 5, 2024
2 parents 7c6a74b + e5dde6a commit 87cda52
Show file tree
Hide file tree
Showing 137 changed files with 2,605 additions and 516 deletions.
21 changes: 18 additions & 3 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5433,7 +5433,8 @@
"automatic",
"manual",
"manual_multiple",
"scheduled"
"scheduled",
"sequential_automatic"
]
},
"CaptureResponse": {
Expand Down Expand Up @@ -17241,7 +17242,8 @@
"ProfileCreate": {
"type": "object",
"required": [
"profile_name"
"profile_name",
"is_click_to_pay_enabled"
],
"properties": {
"profile_name": {
Expand Down Expand Up @@ -17399,6 +17401,12 @@
"is_network_tokenization_enabled": {
"type": "boolean",
"description": "Indicates if network tokenization is enabled or not."
},
"is_click_to_pay_enabled": {
"type": "boolean",
"description": "Indicates if click to pay is enabled or not.",
"default": false,
"example": false
}
},
"additionalProperties": false
Expand Down Expand Up @@ -17431,7 +17439,8 @@
"redirect_to_merchant_with_http_post",
"is_tax_connector_enabled",
"is_network_tokenization_enabled",
"should_collect_cvv_during_payment"
"should_collect_cvv_during_payment",
"is_click_to_pay_enabled"
],
"properties": {
"merchant_id": {
Expand Down Expand Up @@ -17611,6 +17620,12 @@
"should_collect_cvv_during_payment": {
"type": "boolean",
"description": "Indicates if CVV should be collected during payment or not."
},
"is_click_to_pay_enabled": {
"type": "boolean",
"description": "Indicates if click to pay is enabled or not.",
"default": false,
"example": false
}
}
},
Expand Down
38 changes: 10 additions & 28 deletions api-reference/logo/dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 10 additions & 28 deletions api-reference/logo/light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -8012,7 +8012,8 @@
"automatic",
"manual",
"manual_multiple",
"scheduled"
"scheduled",
"sequential_automatic"
]
},
"CaptureResponse": {
Expand Down Expand Up @@ -21668,6 +21669,10 @@
"description": "Maximum number of auto retries allowed for a payment",
"nullable": true,
"minimum": 0
},
"is_click_to_pay_enabled": {
"type": "boolean",
"description": "Indicates if click to pay is enabled or not."
}
},
"additionalProperties": false
Expand Down Expand Up @@ -21700,7 +21705,8 @@
"redirect_to_merchant_with_http_post",
"is_tax_connector_enabled",
"is_network_tokenization_enabled",
"is_auto_retries_enabled"
"is_auto_retries_enabled",
"is_click_to_pay_enabled"
],
"properties": {
"merchant_id": {
Expand Down Expand Up @@ -21897,6 +21903,12 @@
"format": "int32",
"description": "Maximum number of auto retries allowed for a payment",
"nullable": true
},
"is_click_to_pay_enabled": {
"type": "boolean",
"description": "Indicates if click to pay is enabled or not.",
"default": false,
"example": false
}
}
},
Expand Down
15 changes: 14 additions & 1 deletion crates/analytics/src/clickhouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use super::{
distribution::PaymentDistributionRow, filters::PaymentFilterRow, metrics::PaymentMetricRow,
},
query::{Aggregate, ToSql, Window},
refunds::{filters::RefundFilterRow, metrics::RefundMetricRow},
refunds::{
distribution::RefundDistributionRow, filters::RefundFilterRow, metrics::RefundMetricRow,
},
sdk_events::{filters::SdkEventFilter, metrics::SdkEventMetricRow},
types::{AnalyticsCollection, AnalyticsDataSource, LoadRow, QueryExecutionError},
};
Expand Down Expand Up @@ -170,6 +172,7 @@ impl super::payment_intents::filters::PaymentIntentFilterAnalytics for Clickhous
impl super::payment_intents::metrics::PaymentIntentMetricAnalytics for ClickhouseClient {}
impl super::refunds::metrics::RefundMetricAnalytics for ClickhouseClient {}
impl super::refunds::filters::RefundFilterAnalytics for ClickhouseClient {}
impl super::refunds::distribution::RefundDistributionAnalytics for ClickhouseClient {}
impl super::frm::metrics::FrmMetricAnalytics for ClickhouseClient {}
impl super::frm::filters::FrmFilterAnalytics for ClickhouseClient {}
impl super::sdk_events::filters::SdkEventFilterAnalytics for ClickhouseClient {}
Expand Down Expand Up @@ -300,6 +303,16 @@ impl TryInto<RefundFilterRow> for serde_json::Value {
}
}

impl TryInto<RefundDistributionRow> for serde_json::Value {
type Error = Report<ParsingError>;

fn try_into(self) -> Result<RefundDistributionRow, Self::Error> {
serde_json::from_value(self).change_context(ParsingError::StructParseFailure(
"Failed to parse RefundDistributionRow in clickhouse results",
))
}
}

impl TryInto<FrmMetricRow> for serde_json::Value {
type Error = Report<ParsingError>;

Expand Down
115 changes: 113 additions & 2 deletions crates/analytics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use hyperswitch_interfaces::secrets_interface::{
secret_state::{RawSecret, SecretStateContainer, SecuredSecret},
SecretManagementInterface, SecretsManagementError,
};
use refunds::distribution::{RefundDistribution, RefundDistributionRow};
pub use types::AnalyticsDomain;
pub mod lambda_utils;
pub mod utils;
Expand All @@ -52,7 +53,7 @@ use api_models::analytics::{
sdk_events::{
SdkEventDimensions, SdkEventFilters, SdkEventMetrics, SdkEventMetricsBucketIdentifier,
},
Distribution, Granularity, TimeRange,
Granularity, PaymentDistributionBody, RefundDistributionBody, TimeRange,
};
use clickhouse::ClickhouseClient;
pub use clickhouse::ClickhouseConfig;
Expand Down Expand Up @@ -215,7 +216,7 @@ impl AnalyticsProvider {

pub async fn get_payment_distribution(
&self,
distribution: &Distribution,
distribution: &PaymentDistributionBody,
dimensions: &[PaymentDimensions],
auth: &AuthInfo,
filters: &PaymentFilters,
Expand Down Expand Up @@ -528,6 +529,116 @@ impl AnalyticsProvider {
.await
}

pub async fn get_refund_distribution(
&self,
distribution: &RefundDistributionBody,
dimensions: &[RefundDimensions],
auth: &AuthInfo,
filters: &RefundFilters,
granularity: &Option<Granularity>,
time_range: &TimeRange,
) -> types::MetricsResult<Vec<(RefundMetricsBucketIdentifier, RefundDistributionRow)>> {
// Metrics to get the fetch time for each payment metric
metrics::request::record_operation_time(
async {
match self {
Self::Sqlx(pool) => {
distribution.distribution_for
.load_distribution(
distribution,
dimensions,
auth,
filters,
granularity,
time_range,
pool,
)
.await
}
Self::Clickhouse(pool) => {
distribution.distribution_for
.load_distribution(
distribution,
dimensions,
auth,
filters,
granularity,
time_range,
pool,
)
.await
}
Self::CombinedCkh(sqlx_pool, ckh_pool) => {
let (ckh_result, sqlx_result) = tokio::join!(distribution.distribution_for
.load_distribution(
distribution,
dimensions,
auth,
filters,
granularity,
time_range,
ckh_pool,
),
distribution.distribution_for
.load_distribution(
distribution,
dimensions,
auth,
filters,
granularity,
time_range,
sqlx_pool,
));
match (&sqlx_result, &ckh_result) {
(Ok(ref sqlx_res), Ok(ref ckh_res)) if sqlx_res != ckh_res => {
router_env::logger::error!(clickhouse_result=?ckh_res, postgres_result=?sqlx_res, "Mismatch between clickhouse & postgres payments analytics distribution")
},
_ => {}

};

ckh_result
}
Self::CombinedSqlx(sqlx_pool, ckh_pool) => {
let (ckh_result, sqlx_result) = tokio::join!(distribution.distribution_for
.load_distribution(
distribution,
dimensions,
auth,
filters,
granularity,
time_range,
ckh_pool,
),
distribution.distribution_for
.load_distribution(
distribution,
dimensions,
auth,
filters,
granularity,
time_range,
sqlx_pool,
));
match (&sqlx_result, &ckh_result) {
(Ok(ref sqlx_res), Ok(ref ckh_res)) if sqlx_res != ckh_res => {
router_env::logger::error!(clickhouse_result=?ckh_res, postgres_result=?sqlx_res, "Mismatch between clickhouse & postgres payments analytics distribution")
},
_ => {}

};

sqlx_result
}
}
},
&metrics::METRIC_FETCH_TIME,
&distribution.distribution_for,
self,
)
.await
}

pub async fn get_frm_metrics(
&self,
metric: &FrmMetrics,
Expand Down
6 changes: 3 additions & 3 deletions crates/analytics/src/payments/distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use api_models::analytics::{
payments::{
PaymentDimensions, PaymentDistributions, PaymentFilters, PaymentMetricsBucketIdentifier,
},
Distribution, Granularity, TimeRange,
Granularity, PaymentDistributionBody, TimeRange,
};
use diesel_models::enums as storage_enums;
use time::PrimitiveDateTime;
Expand Down Expand Up @@ -53,7 +53,7 @@ where
#[allow(clippy::too_many_arguments)]
async fn load_distribution(
&self,
distribution: &Distribution,
distribution: &PaymentDistributionBody,
dimensions: &[PaymentDimensions],
auth: &AuthInfo,
filters: &PaymentFilters,
Expand All @@ -75,7 +75,7 @@ where
{
async fn load_distribution(
&self,
distribution: &Distribution,
distribution: &PaymentDistributionBody,
dimensions: &[PaymentDimensions],
auth: &AuthInfo,
filters: &PaymentFilters,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use api_models::analytics::{
payments::{PaymentDimensions, PaymentFilters, PaymentMetricsBucketIdentifier},
Distribution, Granularity, TimeRange,
Granularity, PaymentDistributionBody, TimeRange,
};
use common_utils::errors::ReportSwitchExt;
use diesel_models::enums as storage_enums;
Expand Down Expand Up @@ -31,7 +31,7 @@ where
{
async fn load_distribution(
&self,
distribution: &Distribution,
distribution: &PaymentDistributionBody,
dimensions: &[PaymentDimensions],
auth: &AuthInfo,
filters: &PaymentFilters,
Expand Down
3 changes: 2 additions & 1 deletion crates/analytics/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use api_models::{
frm::{FrmDimensions, FrmTransactionType},
payment_intents::PaymentIntentDimensions,
payments::{PaymentDimensions, PaymentDistributions},
refunds::{RefundDimensions, RefundType},
refunds::{RefundDimensions, RefundDistributions, RefundType},
sdk_events::{SdkEventDimensions, SdkEventNames},
Granularity,
},
Expand Down Expand Up @@ -488,6 +488,7 @@ impl_to_sql_for_to_string!(
PaymentIntentDimensions,
&PaymentDistributions,
RefundDimensions,
&RefundDistributions,
FrmDimensions,
PaymentMethod,
PaymentMethodType,
Expand Down
1 change: 1 addition & 0 deletions crates/analytics/src/refunds.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod accumulator;
mod core;

pub mod distribution;
pub mod filters;
pub mod metrics;
pub mod types;
Expand Down
Loading

0 comments on commit 87cda52

Please sign in to comment.