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 #6924

Merged
merged 5 commits into from
Dec 23, 2024

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

Keeping the pr title of pr to get the hotfix pr checked pass.

#6918
/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_aN57oRXcLr1mHaA0rgEm' \
--header 'api-key: dev_xaZ8h3fUz4jtHv2PvY3rUG4TT6gqwt4e3WlbbBiXoTNd8Qa9Xj9mikmLU7LNXoBt' \
--data '{
  "connector_id": "mca_OJpAfYFQGmrFJFNHZlXJ",
  "connector_resource_id": "pi_3QZCtfEOqOywnAIx0U9MQsTk",
  "data": {
      "refund": {
    "amount": 50,
    "currency": "USD"
  }},
  "type": "refund"
}'
{
    "id": "relay_oEX76VqhTuCiAiXqdALZ",
    "status": "success",
    "connector_resource_id": "pi_3QZCtfEOqOywnAIx0U9MQsTk",
    "error": null,
    "connector_reference_id": "re_3QZCtfEOqOywnAIx0BVy5n4o",
    "connector_id": "mca_OJpAfYFQGmrFJFNHZlXJ",
    "profile_id": "pro_aN57oRXcLr1mHaA0rgEm",
    "type": "refund",
    "data": {
        "refund": {
            "amount": 50,
            "currency": "USD",
            "reason": null
        }
    }
}

-> retrieve

curl --location 'http://localhost:8080/relay/relay_oEX76VqhTuCiAiXqdALZ?force_sync=true' \
--header 'Content-Type: application/json' \
--header 'X-Idempotency-Key: <x-idempotency-key>' \
--header 'X-Profile-Id: pro_aN57oRXcLr1mHaA0rgEm' \
--header 'api-key: dev_xaZ8h3fUz4jtHv2PvY3rUG4TT6gqwt4e3WlbbBiXoTNd8Qa9Xj9mikmLU7LNXoBt' \
--data ''
{
    "id": "relay_oEX76VqhTuCiAiXqdALZ",
    "status": "success",
    "connector_resource_id": "pi_3QZCtfEOqOywnAIx0U9MQsTk",
    "error": null,
    "connector_reference_id": "re_3QZCtfEOqOywnAIx0BVy5n4o",
    "connector_id": "mca_OJpAfYFQGmrFJFNHZlXJ",
    "profile_id": "pro_aN57oRXcLr1mHaA0rgEm",
    "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 and others added 3 commits December 23, 2024 17:48
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
@ShankarSinghC ShankarSinghC requested review from a team as code owners December 23, 2024 13:36
Copy link

semanticdiff-com bot commented Dec 23, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/lib.rs  75% smaller
  crates/diesel_models/src/enums.rs  57% smaller
  crates/hyperswitch_domain_models/src/merchant_connector_account.rs  12% smaller
  crates/router/src/db.rs  12% smaller
  crates/router/src/routes.rs  2% smaller
  crates/openapi/src/routes.rs  1% smaller
  crates/router/src/routes/app.rs  1% smaller
  api-reference/api-reference/relay/relay--retrieve.mdx Unsupported file format
  api-reference/api-reference/relay/relay.mdx Unsupported file format
  api-reference/mint.json  0% smaller
  api-reference/openapi_spec.json  0% smaller
  crates/api_models/src/lib.rs  0% smaller
  crates/api_models/src/relay.rs  0% smaller
  crates/common_enums/src/enums.rs  0% smaller
  crates/common_utils/src/id_type.rs  0% smaller
  crates/common_utils/src/id_type/relay.rs  0% smaller
  crates/diesel_models/src/lib.rs  0% smaller
  crates/diesel_models/src/query.rs  0% smaller
  crates/diesel_models/src/query/relay.rs  0% smaller
  crates/diesel_models/src/relay.rs  0% smaller
  crates/diesel_models/src/schema.rs  0% smaller
  crates/diesel_models/src/schema_v2.rs  0% smaller
  crates/hyperswitch_domain_models/src/lib.rs  0% smaller
  crates/hyperswitch_domain_models/src/relay.rs  0% smaller
  crates/openapi/src/openapi.rs  0% smaller
  crates/openapi/src/routes/relay.rs  0% smaller
  crates/router/src/core.rs  0% smaller
  crates/router/src/core/relay.rs  0% smaller
  crates/router/src/core/relay/utils.rs  0% smaller
  crates/router/src/db/relay.rs  0% smaller
  crates/router/src/routes/lock_utils.rs  0% smaller
  crates/router/src/routes/relay.rs  0% smaller
  crates/router/src/services/authentication.rs  0% smaller
  crates/router_env/src/logger/types.rs  0% smaller
  migrations/2024-12-17-141811_add_relay_table/down.sql Unsupported file format
  migrations/2024-12-17-141811_add_relay_table/up.sql Unsupported file format

@hyperswitch-bot hyperswitch-bot bot added M-database-changes Metadata: This PR involves database schema changes M-api-contract-changes Metadata: This PR involves API contract changes labels Dec 23, 2024
@ShankarSinghC ShankarSinghC changed the base branch from main to hotfix-2024.12.18.0 December 23, 2024 13:36
@ShankarSinghC ShankarSinghC removed request for a team December 23, 2024 13:40
@ShankarSinghC ShankarSinghC self-assigned this Dec 23, 2024
@ShankarSinghC ShankarSinghC added A-core Area: Core flows A-payment-methods Area: Payment Methods labels Dec 23, 2024
@ShankarSinghC ShankarSinghC changed the title Relay/hotfix feat(router): add /retrieve api for relay Dec 23, 2024
@ShankarSinghC ShankarSinghC linked an issue Dec 23, 2024 that may be closed by this pull request
@Gnanasundari24 Gnanasundari24 merged commit 1be28d3 into hotfix-2024.12.18.0 Dec 23, 2024
18 of 20 checks passed
@Gnanasundari24 Gnanasundari24 deleted the relay/hotfix branch December 23, 2024 17:04
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 M-api-contract-changes Metadata: This PR involves API contract changes M-database-changes Metadata: This PR involves database schema changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add retrieve api support for relay
6 participants