Skip to content
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

feat(analytics): adding metric api for dispute analytics #3810

Merged
merged 13 commits into from
Feb 28, 2024

Conversation

harsh-sharma-juspay
Copy link
Contributor

@harsh-sharma-juspay harsh-sharma-juspay commented Feb 25, 2024

Type of Change

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

Description

adding metric api for dispute analytics
Http Method: POST
URL Path /analytics/v1/metric/dispute

Additional Changes

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

Motivation and Context

How did you test it?

Hit the URL given below and should get sample response mentioned in the comment

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
  • I added a CHANGELOG entry if applicable

@harsh-sharma-juspay
Copy link
Contributor Author

harsh-sharma-juspay commented Feb 26, 2024

Curl:

curl --location 'http://localhost:8080/analytics/v1/metrics/disputes' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:121.0) Gecko/20100101 Firefox/121.0' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.5' \
--header 'Accept-Encoding: gzip, deflate, br' \
--header 'Referer: https://app.hyperswitch.io/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiM2NhODdjNTUtYTI1YS00YjRmLWE3MWUtMjM4NzU1MTA5NDBlIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzA4MDc1MjcyIiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTcwOTI3OTEzNiwib3JnX2lkIjoib3JnX0s2TkNFa0R1dHNqNUFuazJOVjl6In0.q1cSGvuJYnOrrVhkwtlKyrQL7alo706d4UYwokatvPY' \
--header 'api-key: hyperswitch' \
--header 'Connection: keep-alive' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-02-17T18:30:00Z",
            "endTime": "2024-02-29T17:34:00Z"
        },
        "groupByNames": [
            "connector"
        ],
        "source": "BATCH",
        "metrics": [
            "dispute_status_metric",
            "total_amount_disputed",
            "total_dispute_lost_amount"
            
        ],
        "delta": true
    }
]'

@harsh-sharma-juspay
Copy link
Contributor Author

harsh-sharma-juspay commented Feb 26, 2024

{
    "queryData": [
        {
            "disputes_challenged": 0,
            "disputes_won": 1,
            "disputes_lost": 0,
            "total_amount_disputed": 1040,
            "total_dispute_lost_amount": null,
            "total_dispute": 1,
            "dispute_stage": null,
            "connector": "checkout",
            "time_range": {
                "start_time": "2024-02-17T18:30:00.000Z",
                "end_time": "2024-02-29T17:34:00.000Z"
            },
            "time_bucket": "2024-02-17 18:30:00"
        }
    ],
    "metaData": [
        {
            "current_time_range": {
                "start_time": "2024-02-17T18:30:00.000Z",
                "end_time": "2024-02-29T17:34:00.000Z"
            }
        }
    ]
}

@harsh-sharma-juspay
Copy link
Contributor Author

Screenshot 2024-02-26 at 11 42 50 AM

ivor11
ivor11 previously approved these changes Feb 27, 2024
Comment on lines +73 to +83
fn collect(self) -> Self::MetricOutput {
if self.total <= 0 {
Some((None, None, None, None))
} else {
Some((
u64::try_from(self.challenged_count).ok(),
u64::try_from(self.won_count).ok(),
u64::try_from(self.lost_count).ok(),
u64::try_from(self.total).ok(),
))
}
Copy link
Member

Choose a reason for hiding this comment

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

is this rate or count?
should it be challenged_count/total instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it have total count as well so if rate have to be display FE can convert count to rate percentage

crates/api_models/src/analytics/disputes.rs Outdated Show resolved Hide resolved
ivor11
ivor11 previously approved these changes Feb 28, 2024
lsampras
lsampras previously approved these changes Feb 28, 2024
Copy link
Member

@lsampras lsampras left a comment

Choose a reason for hiding this comment

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

rest looks good

Co-authored-by: Sampras Lopes <lsampras@pm.me>
@harsh-sharma-juspay harsh-sharma-juspay dismissed stale reviews from lsampras and ivor11 via 5b46e20 February 28, 2024 10:46
Co-authored-by: Sampras Lopes <lsampras@pm.me>
@likhinbopanna likhinbopanna added this pull request to the merge queue Feb 28, 2024
Merged via the queue into main with commit de6b16b Feb 28, 2024
10 of 12 checks passed
@likhinbopanna likhinbopanna deleted the adding_dispute_metrics_api branch February 28, 2024 13:11
pixincreate added a commit that referenced this pull request Feb 29, 2024
…stman-runner

* 'main' of github.com:juspay/hyperswitch:
  chore(version): 2024.02.29.0
  chore(postman): update Postman collection files
  feat(analytics): add force retrieve call for force retrieve calls (#3565)
  refactor(connector): [Mollie] Mask PII data  (#3856)
  refactor(connector): [Gocardless] Mask PII data (#3844)
  feat(analytics): adding metric api for dispute analytics (#3810)
  feat(payment_methods): Add default payment method column in customers table and last used column in payment_methods table (#3790)
  fix(tests/postman/adyen): enable sepa payment method type for payout flows (#3861)
  feat(payouts): Implement Smart Retries for Payout (#3580)
  refactor(payment_link): add Miscellaneous charges in cart (#3645)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Analytics]/[Dispute] Create API's endpoints for disputes analytics
4 participants