-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat(debit_routing): add debit_routing_savings
in analytics payment attempt
#8519
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
Conversation
…it-routing/analytics/add-savings
@@ -128,6 +129,7 @@ impl ForexMetric for PaymentMetrics { | |||
self, | |||
Self::PaymentProcessedAmount | |||
| Self::AvgTicketSize | |||
// add here New Metric |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can add Self::DebitRouting
here and can remove this comment
This is for the forex conversion of other currencies to USD
for debit_routing_savings
@@ -1073,6 +1074,10 @@ impl PaymentAttempt { | |||
pub fn get_total_surcharge_amount(&self) -> Option<MinorUnit> { | |||
self.net_amount.get_total_surcharge_amount() | |||
} | |||
|
|||
pub fn set_debit_routing_savings(&mut self, debit_routing_savings: Option<&MinorUnit>) { | |||
self.debit_routing_savings = debit_routing_savings.copied(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why we have used .copied()
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debit_routing_savings
is an optional reference: Option<&MinorUnit>
self.debit_routing_savings
is of type Option, not a reference
pub fn get_debit_routing_savings(&self) -> Option<&MinorUnit> { | ||
match self { | ||
Self::ResponseUpdate { | ||
debit_routing_savings, | ||
.. | ||
} => debit_routing_savings.as_ref(), | ||
Self::Update { .. } | ||
| Self::UpdateTrackers { .. } | ||
| Self::AuthenticationTypeUpdate { .. } | ||
| Self::ConfirmUpdate { .. } | ||
| Self::RejectUpdate { .. } | ||
| Self::BlocklistUpdate { .. } | ||
| Self::PaymentMethodDetailsUpdate { .. } | ||
| Self::ConnectorMandateDetailUpdate { .. } | ||
| Self::VoidUpdate { .. } | ||
| Self::UnresolvedResponseUpdate { .. } | ||
| Self::StatusUpdate { .. } | ||
| Self::ErrorUpdate { .. } | ||
| Self::CaptureUpdate { .. } | ||
| Self::AmountToCaptureUpdate { .. } | ||
| Self::PreprocessingUpdate { .. } | ||
| Self::ConnectorResponse { .. } | ||
| Self::IncrementalAuthorizationAmountUpdate { .. } | ||
| Self::AuthenticationUpdate { .. } | ||
| Self::ManualUpdate { .. } | ||
| Self::PostSessionTokensUpdate { .. } => None, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be done in any simpler way?
You might have to create another metric, say The changes can be similar to |
@@ -281,7 +281,10 @@ where | |||
&profile_id, | |||
&key_store, | |||
vec![connector_data.clone()], | |||
debit_routing_output.get_co_badged_card_networks(), | |||
open_router::CoBadgedCardNetworks( | |||
debit_routing_output.co_badged_card_networks_info.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debit_routing_output.co_badged_card_networks_info can be a domain type
@@ -451,6 +451,13 @@ where | |||
.and_then(|connector_response| connector_response.additional_payment_method_data), | |||
)?; | |||
|
|||
let debit_routing_savings = payment_data.get_payment_method_data().and_then(|data| { | |||
payments::helpers::get_debit_routing_savings_amount( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_debit_routing_savings_amount can be a impl based fn on get_payment_method_data
@@ -5209,6 +5211,85 @@ pub fn get_applepay_metadata( | |||
}) | |||
} | |||
|
|||
pub fn extract_saving_percentage( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can move this to impl based fn as well
"Calculating debit routing saving amount" | ||
); | ||
|
||
let savings_float = (net_amount * (saving_percentage / 100.0)).round(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we somehow avoid two step conversion?
…it-routing/analytics/add-savings
…com/juspay/hyperswitch into debit-routing/analytics/add-savings
@@ -128,6 +130,7 @@ impl ForexMetric for PaymentMetrics { | |||
self, | |||
Self::PaymentProcessedAmount | |||
| Self::AvgTicketSize | |||
| Self::DebitRouting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the SessionizedDebitRouting
metric here as well
(To enable the currency conversion from other currencies to USD for debit_routing_savings)
c0a1a9a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Payment method changes looks good to me!
Description
This pull request introduces a new feature to track and analyze debit routing savings and integrates it across multiple components of the analytics system. It also refactors the handling of co-badged card networks to provide additional details, such as saving percentages. Below is a breakdown of the most important changes grouped by theme:
Debit Routing Analytics Integration:
debit_routing_savings
to thepayment_attempt_queue
,payment_attempts
, andpayment_attempt_mv
tables in ClickHouse for tracking debit routing savings.PaymentMetricsAccumulator
struct to include a newDebitRoutingAccumulator
, which tracks transaction counts and savings amounts. Implemented the necessary methods for metric collection and aggregation.PaymentMetrics::DebitRouting
enum variant and its corresponding implementation to load metrics, process data, and convert savings to USD.Additional Changes
Motivation and Context
How did you test it?
-> Enable debit routing for a profile
-> Configure adyen connector with local debit networks enabled
-> Make some debit routing payments
-> Payment FIlters
-> Payment metric that gives total debit routed txn and savings
-> Payment metrics that gives savings per txn
Checklist
cargo +nightly fmt --all
cargo clippy