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(router): add /retrieve api for relay #6918

Merged
merged 4 commits into from
Dec 23, 2024
Merged

Conversation

ShankarSinghC
Copy link
Contributor

@ShankarSinghC ShankarSinghC commented Dec 23, 2024

Type of Change

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

Description

/relay is a api that will be used to just forward the request sent by merchant without performing any application logic on it. This is particular to support the refunds for the payments that was directly performed with the connector (example stripe) with out hyperswitch involved during the payment flow.

This PR introduces changes to add a retrieve API for relay refunds.

The retrieve API will:

  1. Return the relay status from our database when a retrieve call is made.
  2. If force_sync = true is passed and the relay status is not in a terminal state in our system, the API will call the connector to fetch the latest status.

Flow

  1. Merchant performs payment directly with processor and stores the payment reference id associated with it.
  2. Merchant tiggers the refund through hyperswitch using the processor reference id for the payment.
  3. Merchant makes retrieve call for the relay status

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?

-> Create a merchant connector account
-> Make a refund request with invalid connector_resource_id

curl --location 'http://localhost:8080/relay' \
--header 'Content-Type: application/json' \
--header 'X-Profile-Id: pro_rIikb0gPrzd0vEY8hIiP' \
--header 'api-key: dev_qqMQAuMWCclJSk4uMBeNNSpqAPlsKlBA3blQOwOoq5ogTSFVON3taShABqtqYNA4' \
--data '{
  "connector_id": "mca_8W0CQfwE89J1BJBbpcnt",
  "connector_resource_id": "7349526182906968904951",
  "data": {
      "refund": {
    "amount": 50,
    "currency": "USD"
  }},
  "type": "refund"
}'
{
    "id": "relay_4lgXCQW0EnqKddZ9CC3b",
    "status": "pending",
    "connector_resource_id": "7349526182906968904951",
    "error": null,
    "connector_reference_id": "7349526431306986204951",
    "connector_id": "mca_8W0CQfwE89J1BJBbpcnt",
    "profile_id": "pro_rIikb0gPrzd0vEY8hIiP",
    "type": "refund",
    "data": {
        "refund": {
            "amount": 50,
            "currency": "USD",
            "reason": null
        }
    }
}

-> Relay retrieve

curl --location 'http://localhost:8080/relay/relay_4lgXCQW0EnqKddZ9CC3b' \
--header 'Content-Type: application/json' \
--header 'X-Idempotency-Key: <x-idempotency-key>' \
--header 'X-Profile-Id: pro_rIikb0gPrzd0vEY8hIiP' \
--header 'api-key: dev_qqMQAuMWCclJSk4uMBeNNSpqAPlsKlBA3blQOwOoq5ogTSFVON3taShABqtqYNA4' \
--data ''
{
    "id": "relay_4lgXCQW0EnqKddZ9CC3b",
    "status": "pending",
    "connector_resource_id": "7349526182906968904951",
    "error": null,
    "connector_reference_id": "7349526431306986204951",
    "connector_id": "mca_8W0CQfwE89J1BJBbpcnt",
    "profile_id": "pro_rIikb0gPrzd0vEY8hIiP",
    "type": "refund",
    "data": {
        "refund": {
            "amount": 50,
            "currency": "USD",
            "reason": null
        }
    }
}

-> Relay retrieve force_sync = true

curl --location 'http://localhost:8080/relay/relay_4lgXCQW0EnqKddZ9CC3b?force_sync=true' \
--header 'Content-Type: application/json' \
--header 'X-Idempotency-Key: <x-idempotency-key>' \
--header 'X-Profile-Id: pro_rIikb0gPrzd0vEY8hIiP' \
--header 'api-key: dev_qqMQAuMWCclJSk4uMBeNNSpqAPlsKlBA3blQOwOoq5ogTSFVON3taShABqtqYNA4' \
--data ''
{
    "id": "relay_4lgXCQW0EnqKddZ9CC3b",
    "status": "success",
    "connector_resource_id": "7349526182906968904951",
    "error": null,
    "connector_reference_id": "7349526431306986204951",
    "connector_id": "mca_8W0CQfwE89J1BJBbpcnt",
    "profile_id": "pro_rIikb0gPrzd0vEY8hIiP",
    "type": "refund",
    "data": {
        "refund": {
            "amount": 50,
            "currency": "USD",
            "reason": 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

@ShankarSinghC ShankarSinghC self-assigned this Dec 23, 2024
@ShankarSinghC ShankarSinghC requested review from a team as code owners December 23, 2024 09:40
Copy link

semanticdiff-com bot commented Dec 23, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/api_models/src/relay.rs  10% smaller
  crates/router/src/routes/lock_utils.rs  5% smaller
  crates/router/src/core/relay.rs  4% smaller
  crates/diesel_models/src/query/relay.rs  0% smaller
  crates/diesel_models/src/relay.rs  0% smaller
  crates/router/src/db/relay.rs  0% smaller
  crates/router/src/routes/app.rs  0% smaller
  crates/router/src/routes/relay.rs  0% smaller
  crates/router_env/src/logger/types.rs  0% smaller

@ShankarSinghC ShankarSinghC added A-core Area: Core flows A-payment-methods Area: Payment Methods labels Dec 23, 2024
crates/router/src/core/relay.rs Outdated Show resolved Hide resolved
crates/diesel_models/src/query/relay.rs Outdated Show resolved Hide resolved
crates/router/src/core/relay.rs Outdated Show resolved Hide resolved
crates/router/src/routes/relay.rs Outdated Show resolved Hide resolved
@ShankarSinghC ShankarSinghC linked an issue Dec 23, 2024 that may be closed by this pull request
jarnura
jarnura previously approved these changes Dec 23, 2024
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Dec 23, 2024
Merged via the queue into main with commit 0478731 Dec 23, 2024
17 of 19 checks passed
@Gnanasundari24 Gnanasundari24 deleted the relay/add-retrieve-api branch December 23, 2024 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows A-payment-methods Area: Payment Methods
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add retrieve api support for relay
4 participants