feat(analytics): implement currency conversion to power multi-currency aggregation#6418
Merged
Gnanasundari24 merged 12 commits intomainfrom Nov 6, 2024
Merged
feat(analytics): implement currency conversion to power multi-currency aggregation#6418Gnanasundari24 merged 12 commits intomainfrom
Gnanasundari24 merged 12 commits intomainfrom
Conversation
- create get_conversion_rates() function - change get_metrics() to accept ExchangeRates hashmap
…lyticsMetadata and PaymentAnalyticsBucketValue
…ep and rust_decimal as 3rd party dep
…ts and payment_intents amount metrics
…tors for both payments and payment_intents
…or payments and payments_intents
tsdk02
previously approved these changes
Oct 25, 2024
- fallback api doesnt return a USD factor of 1 inside the rates field like the primary api's response, which was causing different response when using fall_back api for fetching exchange rates.
SanchithHegde
approved these changes
Nov 3, 2024
tsdk02
approved these changes
Nov 4, 2024
Chethan-rao
approved these changes
Nov 4, 2024
14 tasks
bsayak03
pushed a commit
that referenced
this pull request
Nov 26, 2024
…y aggregation (#6418) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Description
INR) toUSDand store it in a separate field variant I created<fieldname>_in_usdFixes #6416
Additional Changes
Motivation and Context
The total amount calculated for all payment analytics buckets related to amounts is incorrect because currency conversion is not being applied before summing the values. As a result, amounts in different currencies are being added together, leading to an inaccurate total.
Dependency
This functionality depends on
currency_conversioncrate directly to fetch exchange rates.How did you test it?
API request for metrics
API response
{ "queryData": [ { "payment_success_rate": null, "payment_count": null, "payment_success_count": null, "payment_processed_amount": 150000, "payment_processed_amount_usd": 1782, "payment_processed_count": null, "payment_processed_amount_without_smart_retries": 0, "payment_processed_amount_without_smart_retries_usd": 0, "payment_processed_count_without_smart_retries": null, "avg_ticket_size": null, "payment_error_message": null, "retries_count": null, "retries_amount_processed": 0, "connector_success_rate": null, "payments_success_rate_distribution": null, "payments_success_rate_distribution_without_smart_retries": null, "payments_failure_rate_distribution": null, "payments_failure_rate_distribution_without_smart_retries": null, "failure_reason_count": 0, "failure_reason_count_without_smart_retries": 0, "currency": "INR", "status": null, "connector": null, "authentication_type": null, "payment_method": null, "payment_method_type": null, "client_source": null, "client_version": null, "profile_id": null, "card_network": null, "merchant_id": null, "card_last_4": null, "card_issuer": null, "error_reason": null, "time_range": { "start_time": "2024-10-10T18:30:00.000Z", "end_time": "2024-10-18T08:24:00.000Z" }, "time_bucket": "2024-10-10 18:30:00" }, { "payment_success_rate": null, "payment_count": null, "payment_success_count": null, "payment_processed_amount": 1794006540, "payment_processed_amount_usd": 1794006540, "payment_processed_count": null, "payment_processed_amount_without_smart_retries": 0, "payment_processed_amount_without_smart_retries_usd": 0, "payment_processed_count_without_smart_retries": null, "avg_ticket_size": null, "payment_error_message": null, "retries_count": null, "retries_amount_processed": 0, "connector_success_rate": null, "payments_success_rate_distribution": null, "payments_success_rate_distribution_without_smart_retries": null, "payments_failure_rate_distribution": null, "payments_failure_rate_distribution_without_smart_retries": null, "failure_reason_count": 0, "failure_reason_count_without_smart_retries": 0, "currency": "USD", "status": null, "connector": null, "authentication_type": null, "payment_method": null, "payment_method_type": null, "client_source": null, "client_version": null, "profile_id": null, "card_network": null, "merchant_id": null, "card_last_4": null, "card_issuer": null, "error_reason": null, "time_range": { "start_time": "2024-10-10T18:30:00.000Z", "end_time": "2024-10-18T08:24:00.000Z" }, "time_bucket": "2024-10-10 18:30:00" }, { "payment_success_rate": null, "payment_count": null, "payment_success_count": null, "payment_processed_amount": 6540, "payment_processed_amount_usd": 7118, "payment_processed_count": null, "payment_processed_amount_without_smart_retries": 0, "payment_processed_amount_without_smart_retries_usd": 0, "payment_processed_count_without_smart_retries": null, "avg_ticket_size": null, "payment_error_message": null, "retries_count": null, "retries_amount_processed": 0, "connector_success_rate": null, "payments_success_rate_distribution": null, "payments_success_rate_distribution_without_smart_retries": null, "payments_failure_rate_distribution": null, "payments_failure_rate_distribution_without_smart_retries": null, "failure_reason_count": 0, "failure_reason_count_without_smart_retries": 0, "currency": "EUR", "status": null, "connector": null, "authentication_type": null, "payment_method": null, "payment_method_type": null, "client_source": null, "client_version": null, "profile_id": null, "card_network": null, "merchant_id": null, "card_last_4": null, "card_issuer": null, "error_reason": null, "time_range": { "start_time": "2024-10-10T18:30:00.000Z", "end_time": "2024-10-18T08:24:00.000Z" }, "time_bucket": "2024-10-10 18:30:00" } ], "metaData": [ { "total_payment_processed_amount": 1794163080, "total_payment_processed_amount_usd": 1794015440, "total_payment_processed_amount_without_smart_retries": 0, "total_payment_processed_amount_without_smart_retries_usd": 0, "total_payment_processed_count": 0, "total_payment_processed_count_without_smart_retries": 0, "total_failure_reasons_count": 0, "total_failure_reasons_count_without_smart_retries": 0 } ] }Testing for various other scenarios
by tweaking
development.tomlwe can create these scenariosby setting
call_delayto 30s we can check for the fetch cycle and redis updates.API response : 200
API response : 500
Checklist
cargo +nightly fmt --allcargo clippy