Skip to content

feat(analytics): Add refund sessionized metrics for Analytics V2 dashboard#6616

Merged
likhinbopanna merged 21 commits intomainfrom
add-refund-v2-metrics
Dec 5, 2024
Merged

feat(analytics): Add refund sessionized metrics for Analytics V2 dashboard#6616
likhinbopanna merged 21 commits intomainfrom
add-refund-v2-metrics

Conversation

@tsdk02
Copy link
Contributor

@tsdk02 tsdk02 commented Nov 19, 2024

Type of Change

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

Description

Adding metrics, and support for Refund Page in Analytics V2 Dashboard through sessionizer.

The metrics added are as follows:

  • Static Metrics in overview section:
    • Refund Success Rate
    • Total Refunds Processed (Amount)
    • Successful Refunds
    • Failed Refunds
    • Pending Refunds
  • Series Graphs:
    • Refunds Processed (Amount and Count) (With granularity)
    • Refunds Success Rate (With granularity)
  • Distributions:
    • Successful Refunds by connector
    • Failed Refunds by connector
  • Tables
    • Refund Reasons
    • Failed Refund Error Message
    • Failed Refund Error Reasons

This PR also adds support for refunds distribution, similar to payments distribution, which may be needed in the future for more advanced analytics.
The following distributions are added:

  • Refund Reasons
  • Refund Error Message

Additional Changes

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

Motivation and Context

Provide more insights into Refunds data for the merchants to make important business decisions

How did you test it?

Refunds Success Rate:

curl --location 'http://localhost:8080/analytics/v1/org/metrics/refunds' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
--header 'api-key: dev_LZcIA7XeMpnK5satp4CDvjcnHCaeKTBcosyuBBJaknZu1odhFo96cwS0nSdfzuJF' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTQ5ZTNkMmItMTY5Yi00NzUzLWJmNTQtZDcxMTM2YjRiN2JkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzI2MDQ2MzI4Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTczMjc5Mjk0OCwib3JnX2lkIjoib3JnX1ZwU0hPanNZZkR2YWJWWUpnQ0FKIiwicHJvZmlsZV9pZCI6InByb192NXNGb0hlODBPZWlVbElvbm9jTSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.Q5ruAj8DwAp5XDj1ktFhma4aZXAHSZBmRSw_EnPk4HE' \
--header 'sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-11-01T09:00:00Z",
            "endTime": "2024-11-29T09:30:39Z"
        },
        "source": "BATCH",
        "metrics": [
            "sessionized_refund_success_rate"
        ],
        "delta": true
    }
]'

Response:

{
    "queryData": [
        {
            "successful_refunds": 6,
            "total_refunds": 10,
            "refund_success_rate": 60.0,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": null,
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        }
    ],
    "metaData": [
        {
            "total_refund_success_rate": 60.0,
            "total_refund_processed_amount": 0,
            "total_refund_processed_amount_in_usd": 0,
            "total_refund_processed_count": 0,
            "total_refund_reason_count": 0,
            "total_refund_error_message_count": 0
        }
    ]
}

Fields to be tested:

  • queryData:
"successful_refunds": 6,
"total_refunds": 10,
"refund_success_rate": 60.0,
  • metaData:
"total_refund_success_rate": 60.0,

Total Refunds Processed (Amount)

curl --location 'http://localhost:8080/analytics/v1/org/metrics/refunds' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
--header 'api-key: dev_LZcIA7XeMpnK5satp4CDvjcnHCaeKTBcosyuBBJaknZu1odhFo96cwS0nSdfzuJF' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTQ5ZTNkMmItMTY5Yi00NzUzLWJmNTQtZDcxMTM2YjRiN2JkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzI2MDQ2MzI4Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTczMjc5Mjk0OCwib3JnX2lkIjoib3JnX1ZwU0hPanNZZkR2YWJWWUpnQ0FKIiwicHJvZmlsZV9pZCI6InByb192NXNGb0hlODBPZWlVbElvbm9jTSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.Q5ruAj8DwAp5XDj1ktFhma4aZXAHSZBmRSw_EnPk4HE' \
--header 'sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-11-01T09:00:00Z",
            "endTime": "2024-11-29T09:30:39Z"
        },
        "source": "BATCH",
        "metrics": [
            "sessionized_refund_processed_amount"
        ],
        "delta": true
    }
]'

Response:

{
    "queryData": [
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 1800,
            "refund_processed_amount_in_usd": 21,
            "refund_processed_count": 3,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": "INR",
            "refund_status": null,
            "connector": null,
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 1800,
            "refund_processed_amount_in_usd": 1800,
            "refund_processed_count": 3,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": "USD",
            "refund_status": null,
            "connector": null,
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        }
    ],
    "metaData": [
        {
            "total_refund_success_rate": null,
            "total_refund_processed_amount": 3600,
            "total_refund_processed_amount_in_usd": 1821,
            "total_refund_processed_count": 6,
            "total_refund_reason_count": 0,
            "total_refund_error_message_count": 0
        }
    ]
}

Fields to be tested:

  • queryData:
"refund_processed_amount": 1800,
"refund_processed_amount_in_usd": 21,
"refund_processed_count": 3,
  • metaData:
"total_refund_processed_amount": 3600,
"total_refund_processed_amount_in_usd": 1821,
"total_refund_processed_count": 6,

Successful Refunds:

curl --location 'http://localhost:8080/analytics/v1/org/metrics/refunds' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
--header 'api-key: dev_LZcIA7XeMpnK5satp4CDvjcnHCaeKTBcosyuBBJaknZu1odhFo96cwS0nSdfzuJF' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTQ5ZTNkMmItMTY5Yi00NzUzLWJmNTQtZDcxMTM2YjRiN2JkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzI2MDQ2MzI4Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTczMjc5Mjk0OCwib3JnX2lkIjoib3JnX1ZwU0hPanNZZkR2YWJWWUpnQ0FKIiwicHJvZmlsZV9pZCI6InByb192NXNGb0hlODBPZWlVbElvbm9jTSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.Q5ruAj8DwAp5XDj1ktFhma4aZXAHSZBmRSw_EnPk4HE' \
--header 'sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-11-01T09:00:00Z",
            "endTime": "2024-11-29T09:30:39Z"
        },
        "filters": {
            "refund_status": [
                "success"
            ]
        },
        "source": "BATCH",
        "metrics": [
            "sessionized_refund_count"
        ],
        "delta": true
    }
]'

Response:

{
    "queryData": [
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": 6,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": null,
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        }
    ],
    "metaData": [
        {
            "total_refund_success_rate": null,
            "total_refund_processed_amount": 0,
            "total_refund_processed_amount_in_usd": 0,
            "total_refund_processed_count": 0,
            "total_refund_reason_count": 0,
            "total_refund_error_message_count": 0
        }
    ]
}

Fields to be tested:

  • queryData:
"refund_count": 6,

Failed Refunds

curl --location 'http://localhost:8080/analytics/v1/org/metrics/refunds' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
--header 'api-key: dev_LZcIA7XeMpnK5satp4CDvjcnHCaeKTBcosyuBBJaknZu1odhFo96cwS0nSdfzuJF' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTQ5ZTNkMmItMTY5Yi00NzUzLWJmNTQtZDcxMTM2YjRiN2JkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzI2MDQ2MzI4Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTczMjc5Mjk0OCwib3JnX2lkIjoib3JnX1ZwU0hPanNZZkR2YWJWWUpnQ0FKIiwicHJvZmlsZV9pZCI6InByb192NXNGb0hlODBPZWlVbElvbm9jTSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.Q5ruAj8DwAp5XDj1ktFhma4aZXAHSZBmRSw_EnPk4HE' \
--header 'sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-11-01T09:00:00Z",
            "endTime": "2024-11-29T09:30:39Z"
        },
        "filters": {
            "refund_status": [
                "failure"
            ]
        },
        "source": "BATCH",
        "metrics": [
            "sessionized_refund_count"
        ],
        "delta": true
    }
]'

Response:

{
    "queryData": [
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": 4,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": null,
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        }
    ],
    "metaData": [
        {
            "total_refund_success_rate": null,
            "total_refund_processed_amount": 0,
            "total_refund_processed_amount_in_usd": 0,
            "total_refund_processed_count": 0,
            "total_refund_reason_count": 0,
            "total_refund_error_message_count": 0
        }
    ]
}

Fields to be tested:

  • queryData:
"refund_count": 4,

Pending Refunds

curl --location 'http://localhost:8080/analytics/v1/org/metrics/refunds' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
--header 'api-key: dev_LZcIA7XeMpnK5satp4CDvjcnHCaeKTBcosyuBBJaknZu1odhFo96cwS0nSdfzuJF' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTQ5ZTNkMmItMTY5Yi00NzUzLWJmNTQtZDcxMTM2YjRiN2JkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzI2MDQ2MzI4Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTczMjc5Mjk0OCwib3JnX2lkIjoib3JnX1ZwU0hPanNZZkR2YWJWWUpnQ0FKIiwicHJvZmlsZV9pZCI6InByb192NXNGb0hlODBPZWlVbElvbm9jTSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.Q5ruAj8DwAp5XDj1ktFhma4aZXAHSZBmRSw_EnPk4HE' \
--header 'sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-11-01T09:00:00Z",
            "endTime": "2024-11-29T09:30:39Z"
        },
        "filters": {
            "refund_status": [
                "pending"
            ]
        },
        "source": "BATCH",
        "metrics": [
            "sessionized_refund_count"
        ],
        "delta": true
    }
]'

Response:

{
    "queryData": [
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": 0,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": null,
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        }
    ],
    "metaData": [
        {
            "total_refund_success_rate": null,
            "total_refund_processed_amount": 0,
            "total_refund_processed_amount_in_usd": 0,
            "total_refund_processed_count": 0,
            "total_refund_reason_count": 0,
            "total_refund_error_message_count": 0
        }
    ]
}

Fields to be tested:

  • queryData:
"refund_count": 0,

Refund Success Rate series graph is similar to Refund Success Rate above, granularity will be added.

Refund Processed Amount and Count series graph is similar to the one above, granularity will be added.

Successful Refunds Distribution by connector:

curl --location 'http://localhost:8080/analytics/v1/org/metrics/refunds' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
--header 'api-key: dev_LZcIA7XeMpnK5satp4CDvjcnHCaeKTBcosyuBBJaknZu1odhFo96cwS0nSdfzuJF' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTQ5ZTNkMmItMTY5Yi00NzUzLWJmNTQtZDcxMTM2YjRiN2JkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzI2MDQ2MzI4Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTczMjk3MjQxOSwib3JnX2lkIjoib3JnX1ZwU0hPanNZZkR2YWJWWUpnQ0FKIiwicHJvZmlsZV9pZCI6InByb192NXNGb0hlODBPZWlVbElvbm9jTSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.eWEvxPl_3-C8tv5_uDfyqV8B8DDUeTK4yn-IHnIQvwY' \
--header 'sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-11-01T09:00:00Z",
            "endTime": "2024-11-29T09:30:39Z"
        },
        "groupByNames": [
            "connector"
        ],
        "source": "BATCH",
        "metrics": [
            "sessionized_refund_count",
            "sessionized_refund_success_count"
        ],
        "delta": true
    }
]'

Response:

{
    "queryData": [
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": 7,
            "refund_success_count": 6,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "stripe_test",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": 3,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "adyen",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        }
    ],
    "metaData": [
        {
            "total_refund_success_rate": null,
            "total_refund_processed_amount": 0,
            "total_refund_processed_amount_in_usd": 0,
            "total_refund_processed_count": 0,
            "total_refund_reason_count": 0,
            "total_refund_error_message_count": 0
        }
    ]
}

Fields to be tested and taken into account:

  • queryData:
"refund_count": 7,
"refund_success_count": 6,
"connector": "stripe_test",

Failed Refunds Distribution by connector:

  • This will have multiple API calls from FE, and data would be calculated at FE only.
  • First Request:
curl --location 'http://localhost:8080/analytics/v1/org/metrics/refunds' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
--header 'api-key: dev_LZcIA7XeMpnK5satp4CDvjcnHCaeKTBcosyuBBJaknZu1odhFo96cwS0nSdfzuJF' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTQ5ZTNkMmItMTY5Yi00NzUzLWJmNTQtZDcxMTM2YjRiN2JkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzI2MDQ2MzI4Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTczMjk3MjQxOSwib3JnX2lkIjoib3JnX1ZwU0hPanNZZkR2YWJWWUpnQ0FKIiwicHJvZmlsZV9pZCI6InByb192NXNGb0hlODBPZWlVbElvbm9jTSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.eWEvxPl_3-C8tv5_uDfyqV8B8DDUeTK4yn-IHnIQvwY' \
--header 'sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-11-01T09:00:00Z",
            "endTime": "2024-11-29T09:30:39Z"
        },
        "groupByNames": [
            "connector"
        ],
        "source": "BATCH",
        "metrics": [
            "sessionized_refund_count"
        ],
        "delta": true
    }
]'

Response:

{
    "queryData": [
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": 7,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "stripe_test",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": 3,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "adyen",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        }
    ],
    "metaData": [
        {
            "total_refund_success_rate": null,
            "total_refund_processed_amount": 0,
            "total_refund_processed_amount_in_usd": 0,
            "total_refund_processed_count": 0,
            "total_refund_reason_count": 0,
            "total_refund_error_message_count": 0
        }
    ]
}

Fields to be tested and taken into account:

  • queryData:
"refund_count": 7,
"connector": "stripe_test",
  • Second Request:
curl --location 'http://localhost:8080/analytics/v1/org/metrics/refunds' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
--header 'api-key: dev_LZcIA7XeMpnK5satp4CDvjcnHCaeKTBcosyuBBJaknZu1odhFo96cwS0nSdfzuJF' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTQ5ZTNkMmItMTY5Yi00NzUzLWJmNTQtZDcxMTM2YjRiN2JkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzI2MDQ2MzI4Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTczMjk3MjQxOSwib3JnX2lkIjoib3JnX1ZwU0hPanNZZkR2YWJWWUpnQ0FKIiwicHJvZmlsZV9pZCI6InByb192NXNGb0hlODBPZWlVbElvbm9jTSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.eWEvxPl_3-C8tv5_uDfyqV8B8DDUeTK4yn-IHnIQvwY' \
--header 'sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-11-01T09:00:00Z",
            "endTime": "2024-11-29T09:30:39Z"
        },
        "filters": {
            "refund_status": [
                "failure"
            ]
        },
        "groupByNames": [
            "connector"
        ],
        "source": "BATCH",
        "metrics": [
            "sessionized_refund_count"
        ],
        "delta": true
    }
]'

Response:

{
    "queryData": [
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": 3,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "adyen",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": 1,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "stripe_test",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        }
    ],
    "metaData": [
        {
            "total_refund_success_rate": null,
            "total_refund_processed_amount": 0,
            "total_refund_processed_amount_in_usd": 0,
            "total_refund_processed_count": 0,
            "total_refund_reason_count": 0,
            "total_refund_error_message_count": 0
        }
    ]
}

Fields to be tested and taken into account:

  • queryData:
"refund_count": 1,
"connector": "stripe_test",

From the two API calls, failed refunds and total refunds can be calculated for every connector, and the failed refunds distribution can be plotted and displayed.

Refund Reasons:

curl --location 'http://localhost:8080/analytics/v1/org/metrics/refunds' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
--header 'api-key: dev_LZcIA7XeMpnK5satp4CDvjcnHCaeKTBcosyuBBJaknZu1odhFo96cwS0nSdfzuJF' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTQ5ZTNkMmItMTY5Yi00NzUzLWJmNTQtZDcxMTM2YjRiN2JkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzI2MDQ2MzI4Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTczMjk3MjQxOSwib3JnX2lkIjoib3JnX1ZwU0hPanNZZkR2YWJWWUpnQ0FKIiwicHJvZmlsZV9pZCI6InByb192NXNGb0hlODBPZWlVbElvbm9jTSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.eWEvxPl_3-C8tv5_uDfyqV8B8DDUeTK4yn-IHnIQvwY' \
--header 'sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-11-01T09:00:00Z",
            "endTime": "2024-11-29T09:30:39Z"
        },
        "groupByNames": [
            "connector", "refund_reason"
        ],
        "source": "BATCH",
        "metrics": [
            "sessionized_refund_reason"
        ],
        "delta": true
    }
]'

Response:

{
    "queryData": [
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 1,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "stripe_test",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": "Test REFUND - 1",
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 6,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "stripe_test",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": "Customer returned product",
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 1,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "adyen",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": "Test Refund - 3",
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 2,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "adyen",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": "Test Refund - 2",
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        }
    ],
    "metaData": [
        {
            "total_refund_success_rate": null,
            "total_refund_processed_amount": 0,
            "total_refund_processed_amount_in_usd": 0,
            "total_refund_processed_count": 0,
            "total_refund_reason_count": 10,
            "total_refund_error_message_count": 0
        }
    ]
}

Fields to be tested:

  • queryData:
"refund_reason_count": 1,
"refund_reason": "Test Refund - 3",
"connector": "stripe_test",
  • metaData:
"total_refund_reason_count": 10,

Failed Refund Reasons:

curl --location 'http://localhost:8080/analytics/v1/org/metrics/refunds' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
--header 'api-key: dev_LZcIA7XeMpnK5satp4CDvjcnHCaeKTBcosyuBBJaknZu1odhFo96cwS0nSdfzuJF' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTQ5ZTNkMmItMTY5Yi00NzUzLWJmNTQtZDcxMTM2YjRiN2JkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzI2MDQ2MzI4Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTczMjk3MjQxOSwib3JnX2lkIjoib3JnX1ZwU0hPanNZZkR2YWJWWUpnQ0FKIiwicHJvZmlsZV9pZCI6InByb192NXNGb0hlODBPZWlVbElvbm9jTSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.eWEvxPl_3-C8tv5_uDfyqV8B8DDUeTK4yn-IHnIQvwY' \
--header 'sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-11-01T09:00:00Z",
            "endTime": "2024-11-29T09:30:39Z"
        },
        "groupByNames": [
            "connector", "refund_reason"
        ],
        "filters": {
            "refund_status": ["failure"]
        },
        "source": "BATCH",
        "metrics": [
            "sessionized_refund_reason"
        ],
        "delta": true
    }
]'

Response:

{
    "queryData": [
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 2,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "adyen",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": "Test Refund - 2",
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 1,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "stripe_test",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": "Customer returned product",
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 1,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "adyen",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": "Test Refund - 3",
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        }
    ],
    "metaData": [
        {
            "total_refund_success_rate": null,
            "total_refund_processed_amount": 0,
            "total_refund_processed_amount_in_usd": 0,
            "total_refund_processed_count": 0,
            "total_refund_reason_count": 4,
            "total_refund_error_message_count": 0
        }
    ]
}

Fields to be tested:

  • queryData:
"refund_reason_count": 1,
"refund_reason": "Test Refund - 3",
"connector": "adyen",
  • metaData:
"total_refund_reason_count": 4,

Failed Refund Error Message:

curl --location 'http://localhost:8080/analytics/v1/org/metrics/refunds' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
--header 'api-key: dev_LZcIA7XeMpnK5satp4CDvjcnHCaeKTBcosyuBBJaknZu1odhFo96cwS0nSdfzuJF' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTQ5ZTNkMmItMTY5Yi00NzUzLWJmNTQtZDcxMTM2YjRiN2JkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzI2MDQ2MzI4Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTczMjk3MjQxOSwib3JnX2lkIjoib3JnX1ZwU0hPanNZZkR2YWJWWUpnQ0FKIiwicHJvZmlsZV9pZCI6InByb192NXNGb0hlODBPZWlVbElvbm9jTSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.eWEvxPl_3-C8tv5_uDfyqV8B8DDUeTK4yn-IHnIQvwY' \
--header 'sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-11-01T09:00:00Z",
            "endTime": "2024-11-29T09:30:39Z"
        },
        "groupByNames": [
            "connector", "refund_error_message"
        ],
        "source": "BATCH",
        "metrics": [
            "sessionized_refund_error_message"
        ],
        "delta": true
    }
]'

Response:

{
    "queryData": [
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 1,
            "currency": null,
            "refund_status": null,
            "connector": "adyen",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": "The refund failed due to test-failure 3.",
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 1,
            "currency": null,
            "refund_status": null,
            "connector": "adyen",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": "The refund failed due to test-failure.",
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        }
    ],
    "metaData": [
        {
            "total_refund_success_rate": null,
            "total_refund_processed_amount": 0,
            "total_refund_processed_amount_in_usd": 0,
            "total_refund_processed_count": 0,
            "total_refund_reason_count": 0,
            "total_refund_error_message_count": 2
        }
    ]
}

Fields to be tested:

  • queryData:
"refund_error_message_count": 1,
"refund_error_message": "The refund failed due to test-failure.",
"connector": "adyen",
  • metaData:
"total_refund_error_message_count": 2

Refund Reasons Distribution:

curl --location 'http://localhost:8080/analytics/v1/org/metrics/refunds' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
--header 'api-key: dev_LZcIA7XeMpnK5satp4CDvjcnHCaeKTBcosyuBBJaknZu1odhFo96cwS0nSdfzuJF' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTQ5ZTNkMmItMTY5Yi00NzUzLWJmNTQtZDcxMTM2YjRiN2JkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzI2MDQ2MzI4Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTczMjk3MjQxOSwib3JnX2lkIjoib3JnX1ZwU0hPanNZZkR2YWJWWUpnQ0FKIiwicHJvZmlsZV9pZCI6InByb192NXNGb0hlODBPZWlVbElvbm9jTSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.eWEvxPl_3-C8tv5_uDfyqV8B8DDUeTK4yn-IHnIQvwY' \
--header 'sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-11-01T09:00:00Z",
            "endTime": "2024-11-29T09:30:39Z"
        },
        "groupByNames": [
            "connector"
        ],
        "distribution": {
            "distributionFor": "sessionized_refund_reason",
            "distributionCardinality": "TOP_5"
        },
        "metrics": [
        ],
        "source": "BATCH",
        "delta": true
    }
]'

Response:

{
    "queryData": [
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": [
                {
                    "reason": "Test REFUND - 1",
                    "count": 1,
                    "percentage": 14.29
                }
            ],
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "stripe_test",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": "Test REFUND - 1",
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": [
                {
                    "reason": "Test Refund - 2",
                    "count": 2,
                    "percentage": 66.67
                }
            ],
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "adyen",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": "Test Refund - 2",
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": [
                {
                    "reason": "Test Refund - 3",
                    "count": 1,
                    "percentage": 33.33
                }
            ],
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "adyen",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": "Test Refund - 3",
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": [
                {
                    "reason": "Customer returned product",
                    "count": 6,
                    "percentage": 85.71
                }
            ],
            "refund_error_message_distribution": null,
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "stripe_test",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": "Customer returned product",
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        }
    ],
    "metaData": [
        {
            "total_refund_success_rate": null,
            "total_refund_processed_amount": 0,
            "total_refund_processed_amount_in_usd": 0,
            "total_refund_processed_count": 0,
            "total_refund_reason_count": 0,
            "total_refund_error_message_count": 0
        }
    ]
}

Fields to be tested:

  • queryData:
"refund_reason_distribution": [
       {
            "reason": "Test REFUND - 1",
            "count": 1,
            "percentage": 14.29
        }
],
"connector": "stripe_test",

Refund Error Message Distribution:

curl --location 'http://localhost:8080/analytics/v1/org/metrics/refunds' \
--header 'Accept: */*' \
--header 'Accept-Language: en-US,en;q=0.9' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'Origin: http://localhost:9000' \
--header 'Referer: http://localhost:9000/' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Site: same-site' \
--header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' \
--header 'api-key: dev_LZcIA7XeMpnK5satp4CDvjcnHCaeKTBcosyuBBJaknZu1odhFo96cwS0nSdfzuJF' \
--header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTQ5ZTNkMmItMTY5Yi00NzUzLWJmNTQtZDcxMTM2YjRiN2JkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzI2MDQ2MzI4Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTczMjk3MjQxOSwib3JnX2lkIjoib3JnX1ZwU0hPanNZZkR2YWJWWUpnQ0FKIiwicHJvZmlsZV9pZCI6InByb192NXNGb0hlODBPZWlVbElvbm9jTSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.eWEvxPl_3-C8tv5_uDfyqV8B8DDUeTK4yn-IHnIQvwY' \
--header 'sec-ch-ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--data '[
    {
        "timeRange": {
            "startTime": "2024-11-01T09:00:00Z",
            "endTime": "2024-11-29T09:30:39Z"
        },
        "groupByNames": [
            "connector"
        ],
        "distribution": {
            "distributionFor": "sessionized_refund_error_message",
            "distributionCardinality": "TOP_5"
        },
        "metrics": [
        ],
        "source": "BATCH",
        "delta": true
    }
]'

Response:

{
    "queryData": [
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": [
                {
                    "error_message": "The refund failed due to test-failure 3.",
                    "count": 1,
                    "percentage": 33.33
                }
            ],
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "adyen",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": "The refund failed due to test-failure 3.",
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": [
                {
                    "error_message": "",
                    "count": 1,
                    "percentage": 33.33
                }
            ],
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "adyen",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": [
                {
                    "error_message": "The refund failed due to test-failure.",
                    "count": 1,
                    "percentage": 33.33
                }
            ],
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "adyen",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": "The refund failed due to test-failure.",
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        },
        {
            "successful_refunds": null,
            "total_refunds": null,
            "refund_success_rate": null,
            "refund_count": null,
            "refund_success_count": null,
            "refund_processed_amount": 0,
            "refund_processed_amount_in_usd": null,
            "refund_processed_count": null,
            "refund_reason_distribution": null,
            "refund_error_message_distribution": [
                {
                    "error_message": "",
                    "count": 1,
                    "percentage": 100.0
                }
            ],
            "refund_reason_count": 0,
            "refund_error_message_count": 0,
            "currency": null,
            "refund_status": null,
            "connector": "stripe_test",
            "refund_type": null,
            "profile_id": null,
            "refund_reason": null,
            "refund_error_message": null,
            "time_range": {
                "start_time": "2024-11-01T09:00:00.000Z",
                "end_time": "2024-11-29T09:30:39.000Z"
            },
            "time_bucket": "2024-11-01 09:00:00"
        }
    ],
    "metaData": [
        {
            "total_refund_success_rate": null,
            "total_refund_processed_amount": 0,
            "total_refund_processed_amount_in_usd": 0,
            "total_refund_processed_count": 0,
            "total_refund_reason_count": 0,
            "total_refund_error_message_count": 0
        }
    ]
}

Fields to be tested:

  • queryData:
"refund_error_message_distribution": [
    {
        "error_message": "The refund failed due to test-failure 3.",
        "count": 1,
        "percentage": 33.33
    }
],
"connector": "adyen",

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 Nov 19, 2024
@tsdk02 tsdk02 self-assigned this Nov 19, 2024
@tsdk02 tsdk02 requested a review from a team as a code owner November 19, 2024 17:04
@semanticdiff-com
Copy link

semanticdiff-com bot commented Nov 19, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/analytics/src/refunds/core.rs  37% smaller
  crates/analytics/src/clickhouse.rs  28% smaller
  crates/analytics/src/refunds/accumulator.rs  11% smaller
  crates/analytics/src/payments/distribution/payment_error_message.rs  5% smaller
  crates/analytics/src/query.rs  2% smaller
  crates/analytics/src/lib.rs  1% smaller
  crates/analytics/src/payments/distribution.rs  0% smaller
  crates/analytics/src/refunds.rs  0% smaller
  crates/analytics/src/refunds/distribution.rs  0% smaller
  crates/analytics/src/refunds/distribution/sessionized_distribution.rs  0% smaller
  crates/analytics/src/refunds/distribution/sessionized_distribution/refund_error_message.rs  0% smaller
  crates/analytics/src/refunds/distribution/sessionized_distribution/refund_reason.rs  0% smaller
  crates/analytics/src/refunds/filters.rs  0% smaller
  crates/analytics/src/refunds/metrics.rs  0% smaller
  crates/analytics/src/refunds/metrics/refund_count.rs  0% smaller
  crates/analytics/src/refunds/metrics/refund_processed_amount.rs  0% smaller
  crates/analytics/src/refunds/metrics/refund_success_count.rs  0% smaller
  crates/analytics/src/refunds/metrics/refund_success_rate.rs  0% smaller
  crates/analytics/src/refunds/metrics/sessionized_metrics.rs  0% smaller
  crates/analytics/src/refunds/metrics/sessionized_metrics/refund_count.rs  0% smaller
  crates/analytics/src/refunds/metrics/sessionized_metrics/refund_error_message.rs  0% smaller
  crates/analytics/src/refunds/metrics/sessionized_metrics/refund_processed_amount.rs  0% smaller
  crates/analytics/src/refunds/metrics/sessionized_metrics/refund_reason.rs  0% smaller
  crates/analytics/src/refunds/metrics/sessionized_metrics/refund_success_count.rs  0% smaller
  crates/analytics/src/refunds/metrics/sessionized_metrics/refund_success_rate.rs  0% smaller
  crates/analytics/src/refunds/types.rs  0% smaller
  crates/analytics/src/sqlx.rs  0% smaller
  crates/api_models/src/analytics.rs  0% smaller
  crates/api_models/src/analytics/refunds.rs  0% smaller

res.push(ReasonsResult {
reason: val.refund_reason,
count: val.count,
percentage: (perc * 100.0).round() / 100.0,
Copy link
Member

Choose a reason for hiding this comment

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

Why the multiplication and division by 100?

If it's to only have 2 decimal places, be aware of the concerns with how floats are represented in computers, so the resulting number may be slightly off.

If you just need a string representation of this, you can use format!() (this even does the rounding):

format!("{perc:.02}");

Or if you need to perform further calculation, you can use a crate that handles decimals, such as the rust_decimal crate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The string representation is not required, need it to be an f64 itself.
Multiplication by 100, allows us to round it to the nearest integer, and again dividing by 100 will give us 2 decimal places, which is the desired behaviour.

Copy link
Member

Choose a reason for hiding this comment

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

The reason why we'd have to be careful of doing floating point arithmetic like this is due to the gotchas involved: https://floating-point-gui.de/ (including a link in case you weren't aware already).

If we are completely sure that such arithmetic is safe, then we can proceed with it, no worries. Otherwise, we may have to consider handling it better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood, and I believe the arithmetic is safe. Thanks for the additional documentation link regarding this issue.

res.push(ReasonsResult {
reason: val.refund_reason,
count: val.count,
percentage: (perc * 100.0).round() / 100.0,
Copy link
Member

Choose a reason for hiding this comment

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

The reason why we'd have to be careful of doing floating point arithmetic like this is due to the gotchas involved: https://floating-point-gui.de/ (including a link in case you weren't aware already).

If we are completely sure that such arithmetic is safe, then we can proceed with it, no worries. Otherwise, we may have to consider handling it better.

@likhinbopanna likhinbopanna added this pull request to the merge queue Dec 5, 2024
Merged via the queue into main with commit 774a53e Dec 5, 2024
@likhinbopanna likhinbopanna deleted the add-refund-v2-metrics branch December 5, 2024 12:09
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(analytics): Add refund sessionized metrics for Analytics V2 dashboard

4 participants