Skip to content

feat(refunds_v2): Add refunds list flow in v2 apis#7966

Merged
Gnanasundari24 merged 10 commits intomainfrom
refunds-v2-list-flow
May 12, 2025
Merged

feat(refunds_v2): Add refunds list flow in v2 apis#7966
Gnanasundari24 merged 10 commits intomainfrom
refunds-v2-list-flow

Conversation

@AmeyWale
Copy link
Contributor

@AmeyWale AmeyWale commented May 6, 2025

Type of Change

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

Description

This PR introduces support for listing refunds in v2 apis.

Available filters for listing are as follows

  • payment_id: Filter by a specific payment identifier.
  • refund_id: Filter by a specific refund identifier.
  • limit: Maximum number of refund records to return.
  • offset: Starting index for pagination.
  • time_range: Filter refunds by a range of creation timestamps (start_time, end_time).
  • amount_filter: Filter by refund amount (start_amount, end_amount).
  • connector: Filter by a list of connector names.
  • connector_id_list: Filter by specific merchant connector account IDs.
  • currency: Filter by a list of currency codes.
  • refund_status: Filter by a list of refund statuses.

Additional Changes

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

Motivation and Context

Merchants will be able to list refunds upon merging this PR.

How did you test it?

Create some payments and refunds before hand.

  • List all refunds API call
curl --location --request GET 'http://localhost:8080/v2/refunds/list' \
--header 'x-profile-id: pro_PiIU0MSYNuU5kS96H0kV' \
--header 'Content-Type: application/json' \
--header 'Authorization: api-key=dev_nG2oG32R2dnadMOvkwfRyl0j1YB8uNf3t1FcDqhFgFxO7TtVS1kPQ8m4F3DEngVb' \
--data '{
    
}'
  • Response from the above call
{
    "count": 4,
    "total_count": 4,
    "data": [
        {
            "id": "12345_ref_0196a4badf2f7ed2b16c4ecaf1c814db",
            "payment_id": "12345_pay_0196a4baa48772909f72eac2cd863d7b",
            "merchant_reference_id": "1746520432",
            "amount": 70,
            "currency": "EUR",
            "status": "succeeded",
            "reason": "Paid by mistake",
            "metadata": {
                "foo": "bar"
            },
            "error_details": {
                "code": "",
                "message": ""
            },
            "created_at": "2025-05-06T08:33:52.433Z",
            "updated_at": "2025-05-06T08:33:53.474Z",
            "connector": "stripe",
            "profile_id": "pro_PiIU0MSYNuU5kS96H0kV",
            "merchant_connector_id": "mca_jQBjGAAN1BgqzXa0Gpoy",
            "connector_refund_reference_id": null
        },
        {
            "id": "12345_ref_0196a4ba41147d138621293a283b9d3e",
            "payment_id": "12345_pay_0196a4ba295477d0a4156e65135d8fb2",
            "merchant_reference_id": "1746520392",
            "amount": 1000,
            "currency": "BBD",
            "status": "succeeded",
            "reason": "Paid by mistake",
            "metadata": {
                "foo": "bar"
            },
            "error_details": {
                "code": "",
                "message": ""
            },
            "created_at": "2025-05-06T08:33:11.959Z",
            "updated_at": "2025-05-06T08:33:13.047Z",
            "connector": "stripe",
            "profile_id": "pro_PiIU0MSYNuU5kS96H0kV",
            "merchant_connector_id": "mca_jQBjGAAN1BgqzXa0Gpoy",
            "connector_refund_reference_id": null
        },
        {
            "id": "12345_ref_0196a4b978637810b17d2f855afb0305",
            "payment_id": "12345_pay_0196a4b9609179429e3e0decc9892a55",
            "merchant_reference_id": "1746520341",
            "amount": 100,
            "currency": "USD",
            "status": "succeeded",
            "reason": "Paid by mistake",
            "metadata": {
                "foo": "bar"
            },
            "error_details": {
                "code": "",
                "message": ""
            },
            "created_at": "2025-05-06T08:32:20.588Z",
            "updated_at": "2025-05-06T08:32:21.669Z",
            "connector": "stripe",
            "profile_id": "pro_PiIU0MSYNuU5kS96H0kV",
            "merchant_connector_id": "mca_jQBjGAAN1BgqzXa0Gpoy",
            "connector_refund_reference_id": null
        },
        {
            "id": "12345_ref_01969f96f27e7213b4257eb238ec3a46",
            "payment_id": "12345_pay_01969f96e02a7dd3a183592c24c6693e",
            "merchant_reference_id": "1746434192",
            "amount": 100,
            "currency": "USD",
            "status": "succeeded",
            "reason": "Paid by mistake",
            "metadata": {
                "foo": "bar"
            },
            "error_details": {
                "code": "",
                "message": ""
            },
            "created_at": "2025-05-05T08:36:32.015Z",
            "updated_at": "2025-05-05T08:36:46.580Z",
            "connector": "stripe",
            "profile_id": "pro_PiIU0MSYNuU5kS96H0kV",
            "merchant_connector_id": "mca_jQBjGAAN1BgqzXa0Gpoy",
            "connector_refund_reference_id": null
        }
    ]
}
  • List refund by payment id API Call
curl --location --request GET 'http://localhost:8080/v2/refunds/list' \
--header 'x-profile-id: pro_PiIU0MSYNuU5kS96H0kV' \
--header 'Content-Type: application/json' \
--header 'Authorization: api-key=dev_nG2oG32R2dnadMOvkwfRyl0j1YB8uNf3t1FcDqhFgFxO7TtVS1kPQ8m4F3DEngVb' \
--data '{
    "payment_id":"12345_pay_0196a4baa48772909f72eac2cd863d7b"
}'
  • Response from the above call
{
    "count": 1,
    "total_count": 1,
    "data": [
        {
            "id": "12345_ref_0196a4badf2f7ed2b16c4ecaf1c814db",
            "payment_id": "12345_pay_0196a4baa48772909f72eac2cd863d7b",
            "merchant_reference_id": "1746520432",
            "amount": 70,
            "currency": "EUR",
            "status": "succeeded",
            "reason": "Paid by mistake",
            "metadata": {
                "foo": "bar"
            },
            "error_details": {
                "code": "",
                "message": ""
            },
            "created_at": "2025-05-06T08:33:52.433Z",
            "updated_at": "2025-05-06T08:33:53.474Z",
            "connector": "stripe",
            "profile_id": "pro_PiIU0MSYNuU5kS96H0kV",
            "merchant_connector_id": "mca_jQBjGAAN1BgqzXa0Gpoy",
            "connector_refund_reference_id": null
        }
    ]
}
  • List refund by refund id API Call
curl --location --request GET 'http://localhost:8080/v2/refunds/list' \
--header 'x-profile-id: pro_PiIU0MSYNuU5kS96H0kV' \
--header 'Content-Type: application/json' \
--header 'Authorization: api-key=dev_nG2oG32R2dnadMOvkwfRyl0j1YB8uNf3t1FcDqhFgFxO7TtVS1kPQ8m4F3DEngVb' \
--data '{
    "refund_id":"12345_ref_0196a4ba41147d138621293a283b9d3e"
}'
  • Response from the above call
{
    "count": 1,
    "total_count": 1,
    "data": [
        {
            "id": "12345_ref_0196a4ba41147d138621293a283b9d3e",
            "payment_id": "12345_pay_0196a4ba295477d0a4156e65135d8fb2",
            "merchant_reference_id": "1746520392",
            "amount": 1000,
            "currency": "BBD",
            "status": "succeeded",
            "reason": "Paid by mistake",
            "metadata": {
                "foo": "bar"
            },
            "error_details": {
                "code": "",
                "message": ""
            },
            "created_at": "2025-05-06T08:33:11.959Z",
            "updated_at": "2025-05-06T08:33:13.047Z",
            "connector": "stripe",
            "profile_id": "pro_PiIU0MSYNuU5kS96H0kV",
            "merchant_connector_id": "mca_jQBjGAAN1BgqzXa0Gpoy",
            "connector_refund_reference_id": null
        }
    ]
}
  • List refund by currencies API Call
curl --location --request GET 'http://localhost:8080/v2/refunds/list' \
--header 'x-profile-id: pro_PiIU0MSYNuU5kS96H0kV' \
--header 'Content-Type: application/json' \
--header 'Authorization: api-key=dev_nG2oG32R2dnadMOvkwfRyl0j1YB8uNf3t1FcDqhFgFxO7TtVS1kPQ8m4F3DEngVb' \
--data '{
    "currency":["EUR","USD"]
}'
  • Response from the above call
{
    "count": 3,
    "total_count": 3,
    "data": [
        {
            "id": "12345_ref_0196a4badf2f7ed2b16c4ecaf1c814db",
            "payment_id": "12345_pay_0196a4baa48772909f72eac2cd863d7b",
            "merchant_reference_id": "1746520432",
            "amount": 70,
            "currency": "EUR",
            "status": "succeeded",
            "reason": "Paid by mistake",
            "metadata": {
                "foo": "bar"
            },
            "error_details": {
                "code": "",
                "message": ""
            },
            "created_at": "2025-05-06T08:33:52.433Z",
            "updated_at": "2025-05-06T08:33:53.474Z",
            "connector": "stripe",
            "profile_id": "pro_PiIU0MSYNuU5kS96H0kV",
            "merchant_connector_id": "mca_jQBjGAAN1BgqzXa0Gpoy",
            "connector_refund_reference_id": null
        },
        {
            "id": "12345_ref_0196a4b978637810b17d2f855afb0305",
            "payment_id": "12345_pay_0196a4b9609179429e3e0decc9892a55",
            "merchant_reference_id": "1746520341",
            "amount": 100,
            "currency": "USD",
            "status": "succeeded",
            "reason": "Paid by mistake",
            "metadata": {
                "foo": "bar"
            },
            "error_details": {
                "code": "",
                "message": ""
            },
            "created_at": "2025-05-06T08:32:20.588Z",
            "updated_at": "2025-05-06T08:32:21.669Z",
            "connector": "stripe",
            "profile_id": "pro_PiIU0MSYNuU5kS96H0kV",
            "merchant_connector_id": "mca_jQBjGAAN1BgqzXa0Gpoy",
            "connector_refund_reference_id": null
        },
        {
            "id": "12345_ref_01969f96f27e7213b4257eb238ec3a46",
            "payment_id": "12345_pay_01969f96e02a7dd3a183592c24c6693e",
            "merchant_reference_id": "1746434192",
            "amount": 100,
            "currency": "USD",
            "status": "succeeded",
            "reason": "Paid by mistake",
            "metadata": {
                "foo": "bar"
            },
            "error_details": {
                "code": "",
                "message": ""
            },
            "created_at": "2025-05-05T08:36:32.015Z",
            "updated_at": "2025-05-05T08:36:46.580Z",
            "connector": "stripe",
            "profile_id": "pro_PiIU0MSYNuU5kS96H0kV",
            "merchant_connector_id": "mca_jQBjGAAN1BgqzXa0Gpoy",
            "connector_refund_reference_id": null
        }
    ]
}

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

@AmeyWale AmeyWale added the api-v2 label May 6, 2025
@AmeyWale AmeyWale self-assigned this May 6, 2025
@AmeyWale AmeyWale requested review from a team as code owners May 6, 2025 09:49
@semanticdiff-com
Copy link

semanticdiff-com bot commented May 6, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/types/api/refunds.rs  71% smaller
  crates/router/src/routes/app.rs  58% smaller
  api-reference-v2/openapi_spec.json  3% smaller
  crates/api_models/src/refunds.rs  0% smaller
  crates/hyperswitch_domain_models/Cargo.toml Unsupported file format
  crates/hyperswitch_domain_models/src/refunds.rs  0% smaller
  crates/openapi/src/openapi_v2.rs  0% smaller
  crates/openapi/src/routes/refunds.rs  0% smaller
  crates/router/Cargo.toml Unsupported file format
  crates/router/src/core/refunds_v2.rs Unsupported file format
  crates/router/src/db/kafka_store.rs  0% smaller
  crates/router/src/db/refund.rs  0% smaller
  crates/router/src/routes/refunds.rs  0% smaller
  crates/router/src/types/storage/refund.rs  0% smaller

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label May 6, 2025
@AmeyWale AmeyWale changed the title feat(refunds_v2): [Refunds List] Add refunds list flow in v2 apis feat(refunds_v2): Add refunds list flow in v2 apis May 6, 2025
@AmeyWale AmeyWale linked an issue May 6, 2025 that may be closed by this pull request
jarnura
jarnura previously approved these changes May 7, 2025
jarnura
jarnura previously approved these changes May 7, 2025
hrithikesh026
hrithikesh026 previously approved these changes May 8, 2025
@AmeyWale AmeyWale dismissed stale reviews from hrithikesh026 and jarnura via f8e5d7e May 8, 2025 11:08
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue May 12, 2025
Merged via the queue into main with commit 839eb2e May 12, 2025
15 of 20 checks passed
@Gnanasundari24 Gnanasundari24 deleted the refunds-v2-list-flow branch May 12, 2025 15:29
pixincreate added a commit that referenced this pull request May 12, 2025
…adyen-ideal

* 'main' of github.com:juspay/hyperswitch: (62 commits)
  fix(core): language consumption from locale in payment and payout links (#7993)
  feat(refunds_v2): Add refunds list flow in v2 apis (#7966)
  refactor(connector): [Noon] auth header (#7977)
  fix(connector): [Novalnet] send decoded token for apple pay payment (#7973)
  feat(business_profile): add business_profile config to enable external vault (#7876)
  feat(vsaas): integrate onboarding flow for vertical saas (#7884)
  feat(connector): Introduce connector template code for WorldpayXML  (#7968)
  feat(connector): [ADYEN, CHECKOUT] Added In Feature Matrix API (#7914)
  feat(core): add psync support for recovery external payments (#7855)
  refactor(open_router): call elimination routing of open router if enabled instead of dynamo (#7961)
  feat(payment_methods): add v2 api for fetching token data (#7629)
  ci(cypress): Fix Bank Redirects for stripe test (#8004)
  chore(version): 2025.05.12.0
  refactor(authentication): moved cavv storing from table to temp locker (#7978)
  chore(version): 2025.05.09.0
  feat(connector): [paypal, trustpay] add in feature matrix (#7911)
  fix(update_metadata): Update Metadata for any connectors other than stripe gives 500 error (#7984)
  fix(router): Fixed stack over flow for session call in authentication connectors (#7983)
  chore(version): 2025.05.08.0
  fix(payment): disable payment update via client config (#7970)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 M-api-contract-changes Metadata: This PR involves API contract changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Add refunds list feature in v2 apis

4 participants