Skip to content

feat(analytics): refactor and introduce analytics APIs to accommodate OrgLevel, MerchantLevel and ProfileLevel authentication#5729

Merged
likhinbopanna merged 68 commits intomainfrom
add-profile-id-org-id-analytics-apis
Sep 3, 2024
Merged

feat(analytics): refactor and introduce analytics APIs to accommodate OrgLevel, MerchantLevel and ProfileLevel authentication#5729
likhinbopanna merged 68 commits intomainfrom
add-profile-id-org-id-analytics-apis

Conversation

@tsdk02
Copy link
Contributor

@tsdk02 tsdk02 commented Aug 28, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Introducing OrgLevel, MerchantLevel and ProfileLevel authentication for analytics, the following changes are done:

  • refactored the existing MerchantLevel APIs
  • introduced new OrgLevel APIs
  • introduced new ProfileLevel APIs

The levels are described as:

    OrgLevel {
        org_id: id_type::OrganizationId,
    },
    MerchantLevel {
        org_id: id_type::OrganizationId,
        merchant_ids: Vec<id_type::MerchantId>,
    },
    ProfileLevel {
        org_id: id_type::OrganizationId,
        merchant_id: id_type::MerchantId,
        profile_ids: Vec<id_type::ProfileId>,
    }
  • Introduced ProfileId as a dimension and filter for analytics:

    • Payments v1
    • Payments v2
    • Refunds
  • Changed the clickhouse query to search in UTC timezone by converting the timestamp into epoch
    The API's added are as follows:

  • Merchant Level

Merchant Level  
Payment Metrics V1 /analytics/v1/merchant/metrics/payments
Payment Filters V1 /analytics/v1/merchant/filters/payments
Refund Metrics /analytics/v1/merchant/metrics/refunds
Refund Filters /analytics/v1/merchant/filters/refunds
Payment Report /analytics/v1/merchant/report/payments
Refund Report /analytics/v1/merchant/report/refunds
Dispute Report /analytics/v1/merchant/report/dispute
API Event Metrics /analytics/v1/merchant/metrics/api_events
API Event Filters /analytics/v1/merchant/filters/api_events
Dispute Metrics /analytics/v1/merchant/metrics/disputes
Dispute Filters /analytics/v1/merchant/filters/disputes
Info /analytics/v1/merchant/{domain}/info
Payment Metrics V2 /analytics/v2/merchant/metrics/payments
  • Org Level
Org Level  
Payment Metrics V1 /analytics/v1/org/metrics/payments
Payment Filters V1 /analytics/v1/org/filters/payments
Refund Metrics /analytics/v1/org/metrics/refunds
Refund Filters /analytics/v1/org/filters/refunds
Payment Report /analytics/v1/org/report/payments
Refund Report /analytics/v1/org/report/refunds
Dispute Report /analytics/v1/org/report/dispute
Dispute Metrics /analytics/v1/org/metrics/disputes
Dispute Filters /analytics/v1/org/filters/disputes
Info /analytics/v1/org/{domain}/info
Payment Metrics V2 /analytics/v2/org/metrics/payments
  • Profile Level
Profile Level  
Payment Metrics V1 /analytics/v1/profile/metrics/payments
Payment Filters V1 /analytics/v1/profile/filters/payments
Refund Metrics /analytics/v1/profile/metrics/refunds
Refund Filters /analytics/v1/profile/filters/refunds
Payment Report /analytics/v1/profile/report/payments
Refund Report /analytics/v1/profile/report/refunds
Dispute Report /analytics/v1/profile/report/dispute
Dispute Metrics /analytics/v1/profile/metrics/disputes
Dispute Filters /analytics/v1/profile/filters/disputes
Info /analytics/v1/profile/{domain}/info
Connector Logs /analytics/v1/profile/connector_event_logs
Outgoing Webhook Event Logs /analytics/v1/profile/outgoing_webhook_event_logs
API Event Logs /analytics/v1/profile/api_event_logs
SDK Event Logs /analytics/v1/profile/sdk_event_logs
Payment Metrics V2 /analytics/v2/profile/metrics/payments

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

OrgLevel, MerchantLevel and ProfileLevel provide for enhanced analytics insights on metrics, filters etc of Payments, Refunds, Disputes etc.

How did you test it?

  • Can be tested once Frontend support is added and the respective OrgLevel, MerchantLevel and ProfileLevel APIs are hit
  • ProfileId is added as a filter for Payments and Refunds
Screenshot 2024-09-03 at 11 08 18 AM Screenshot 2024-09-03 at 11 08 28 AM Screenshot 2024-09-03 at 11 08 35 AM

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@tsdk02 tsdk02 added C-feature Category: Feature request or enhancement A-Analytics labels Aug 28, 2024
@tsdk02 tsdk02 self-assigned this Aug 28, 2024
@tsdk02 tsdk02 requested a review from a team as a code owner August 28, 2024 05:19
@semanticdiff-com
Copy link

semanticdiff-com bot commented Aug 28, 2024

Review changes with SemanticDiff.

Analyzed 59 of 63 files.

Overall, the semantic diff is 17% smaller than the GitHub diff.

1 files do not contain logic changes.

File Information
Filename Status
Cargo.lock Unsupported file format
✔️ crates/router/src/analytics.rs 4.37% smaller
✔️ crates/router/src/types/domain/user.rs Analyzed
✔️ crates/router/src/core/verification/utils.rs 16.84% smaller
✔️ crates/hyperswitch_domain_models/src/merchant_account.rs Analyzed
✔️ crates/common_utils/src/types.rs Analyzed
crates/common_utils/src/types/authentication.rs Unsupported file format
✔️ crates/api_models/src/analytics.rs 56.02% smaller
✔️ crates/api_models/src/analytics/connector_events.rs Analyzed
✔️ crates/api_models/src/analytics/payment_intents.rs Analyzed
✔️ crates/api_models/src/analytics/payments.rs Analyzed
✔️ crates/api_models/src/analytics/refunds.rs Analyzed
✔️ crates/analytics/src/clickhouse.rs Analyzed
crates/analytics/src/enums.rs Unsupported file format
✔️ crates/analytics/src/errors.rs Analyzed
✔️ crates/analytics/src/lib.rs 33.63% smaller
✔️ crates/analytics/src/query.rs 7.47% smaller
✔️ crates/analytics/src/sqlx.rs 12.47% smaller
✔️ crates/analytics/src/refunds/core.rs 4.82% smaller
✔️ crates/analytics/src/refunds/filters.rs 29.63% smaller
✔️ crates/analytics/src/refunds/metrics.rs 84.54% smaller
✔️ crates/analytics/src/refunds/types.rs Analyzed
✔️ crates/analytics/src/refunds/metrics/refund_count.rs 28.0% smaller
✔️ crates/analytics/src/refunds/metrics/refund_processed_amount.rs 28.0% smaller
✔️ crates/analytics/src/refunds/metrics/refund_success_count.rs 28.0% smaller
✔️ crates/analytics/src/refunds/metrics/refund_success_rate.rs 28.0% smaller
✔️ crates/analytics/src/payments/core.rs Analyzed
✔️ crates/analytics/src/payments/distribution.rs Analyzed
✔️ crates/analytics/src/payments/filters.rs 5.51% smaller
✔️ crates/analytics/src/payments/metrics.rs 89.14% smaller
✔️ crates/analytics/src/payments/types.rs Analyzed
✔️ crates/analytics/src/payments/metrics/avg_ticket_size.rs 28.0% smaller
✔️ crates/analytics/src/payments/metrics/connector_success_rate.rs 28.0% smaller
✔️ crates/analytics/src/payments/metrics/payment_count.rs 28.0% smaller
✔️ crates/analytics/src/payments/metrics/payment_processed_amount.rs 28.0% smaller
✔️ crates/analytics/src/payments/metrics/payment_success_count.rs 28.0% smaller
✔️ crates/analytics/src/payments/metrics/retries_count.rs 28.0% smaller
✔️ crates/analytics/src/payments/metrics/success_rate.rs 28.0% smaller
✔️ crates/analytics/src/payments/distribution/payment_error_message.rs 28.0% smaller
✔️ crates/analytics/src/payment_intents/core.rs 2.29% smaller
✔️ crates/analytics/src/payment_intents/filters.rs Analyzed
✔️ crates/analytics/src/payment_intents/metrics.rs 84.54% smaller
✔️ crates/analytics/src/payment_intents/types.rs Analyzed
✔️ crates/analytics/src/payment_intents/metrics/payment_intent_count.rs 28.0% smaller
✔️ crates/analytics/src/payment_intents/metrics/smart_retried_amount.rs 28.0% smaller
✔️ crates/analytics/src/payment_intents/metrics/successful_smart_retries.rs 28.0% smaller
✔️ crates/analytics/src/payment_intents/metrics/total_smart_retries.rs 28.0% smaller
✔️ crates/analytics/src/outgoing_webhook_event/events.rs No logic changes found
✔️ crates/analytics/src/disputes/core.rs 5.41% smaller
✔️ crates/analytics/src/disputes/filters.rs 34.34% smaller
✔️ crates/analytics/src/disputes/metrics.rs 83.91% smaller
✔️ crates/analytics/src/disputes/metrics/dispute_status_metric.rs 32.33% smaller
✔️ crates/analytics/src/disputes/metrics/total_amount_disputed.rs 32.33% smaller
✔️ crates/analytics/src/disputes/metrics/total_dispute_lost_amount.rs 32.33% smaller
✔️ crates/analytics/src/api_event/core.rs 35.38% smaller
✔️ crates/analytics/src/api_event/filters.rs 33.86% smaller
✔️ crates/analytics/src/api_event/metrics.rs 83.91% smaller
✔️ crates/analytics/src/api_event/metrics/api_count.rs 32.33% smaller
✔️ crates/analytics/src/api_event/metrics/latency.rs 32.33% smaller
✔️ crates/analytics/src/api_event/metrics/status_code_count.rs 32.33% smaller
config/dashboard.toml Unsupported file format
✔️ api-reference-v2/openapi_spec.json 0.82% smaller
✔️ api-reference/openapi_spec.json 0.37% smaller

@tsdk02 tsdk02 changed the title feat(analytics): refactor and introduce analytics APIs to accomodate OrgLevel, MerchantLevel and ProfileLevel authentication feat(analytics): refactor and introduce analytics APIs to accommodate OrgLevel, MerchantLevel and ProfileLevel authentication Aug 28, 2024
@tsdk02 tsdk02 requested a review from a team as a code owner August 28, 2024 05:25
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Sep 2, 2024
@lsampras lsampras requested a review from a team as a code owner September 2, 2024 20:22
@tsdk02 tsdk02 requested a review from ThisIsMani September 3, 2024 05:27
@tsdk02 tsdk02 requested a review from racnan September 3, 2024 06:49
Copy link
Contributor

@ThisIsMani ThisIsMani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check Cargo.lock changes.
And inform control-center FE about dashboard.toml.

@likhinbopanna likhinbopanna added this pull request to the merge queue Sep 3, 2024
Merged via the queue into main with commit 8ed942c Sep 3, 2024
@likhinbopanna likhinbopanna deleted the add-profile-id-org-id-analytics-apis branch September 3, 2024 11:12
lsampras added a commit that referenced this pull request Sep 3, 2024
… OrgLevel, MerchantLevel and ProfileLevel authentication (#5729)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sampras Lopes <sampras.lopes@juspay.in>
pixincreate added a commit that referenced this pull request Sep 5, 2024
* 'main' of github.com:juspay/hyperswitch:
  feat(customer_v2): Add customer V2 delete api (#5518)
  chore(version): 2024.09.05.0
  feat(user_roles): get user role details (#5777)
  feat(users): Add profile level invites (#5793)
  refactor(router): profile based routes for payouts (#5794)
  Feat(connector): [Fiuu] Add Card Flows (#5786)
  fix(cypress): fix fiservemea configs for cypress (#5772)
  fix(cypress): `api_key` check in cypress (#5787)
  feat(payment_methods_v2): Implemented Diesel and Domain models for v2 (#5700)
  fix(payout): query for getting a list of active payout IDs (#5771)
  refactor(router): remove admin v2 intermediate features (#5780)
  feat(revert): populate payment method details in payments response (#5785)
  chore(version): 2024.09.04.0
  fix(connector): skip 3DS in `network_transaction_id` flow for cybersource (#5781)
  refactor(euclid): check the authenticity of profile_id being used (#5647)
  feat(analytics): refactor and introduce analytics APIs to accommodate OrgLevel, MerchantLevel and ProfileLevel authentication (#5729)
  fix(router): make customer details None in the `Psync` flow if the customer is deleted (#5732)
  feat(connector): [DEUTSCHE] Add template code (#5774)
  chore(version): 2024.09.03.1
  fix(router): send post message to window.parent instead of window.top in external 3ds flow (#5778)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Analytics C-feature Category: Feature request or enhancement M-api-contract-changes Metadata: This PR involves API contract changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(analytics): refactor and introduce analytics APIs to accomodate OrgLevel, MerchantLevel and ProfileLevel authentication

5 participants