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

refactor(relay): add trait based implementation for relay #7264

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ShankarSinghC
Copy link
Contributor

@ShankarSinghC ShankarSinghC commented Feb 13, 2025

Type of Change

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

Description

This pr refactors the relay flow to add trait based implementation for it.

Changes made:-

  1. relay_flow_decider decides the relay flow based on the relay types
  2. Introduced RelayInterface trait that consists the methods required for different relay types
    a. validate_relay_request validates the relay requests for different type of relay types. It also provides default
    implementation, if a new relay type does not have specific type.
    b. get_domain_models to convert the relay request form api models to domain models
    c. process_relay that consists the core functionality for every relay type
    d. generate_response relay type specific response
  3. Validate trait provides the generic validation. This trait can be implemented for any type, that requires validation.

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?

-> Make a relay payment

curl --location 'http://localhost:8080/relay' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_Zv50p4TBhOIRJFnynXL7' \
--header 'api-key: <api-key>' \
--data '{
    "connector_id": "mca_5dVmrsd0IwgQAsu3uiUo",
    "connector_resource_id": "pi_3Qs0CqEOqOywnAIx0QJ1vo67",
    "data": {
        "refund": {
            "amount": 1,
            "currency": "USD"
        }
    },
    "type": "refund"
}'
{
    "id": "relay_5nS1Mr5DHgWCkadiEVwY",
    "status": "success",
    "connector_resource_id": "pi_3Qs0CqEOqOywnAIx0QJ1vo67",
    "error": null,
    "connector_reference_id": "re_3Qs0CqEOqOywnAIx07ZIvgZ1",
    "connector_id": "mca_5dVmrsd0IwgQAsu3uiUo",
    "profile_id": "pro_Zv50p4TBhOIRJFnynXL7",
    "type": "refund",
    "data": {
        "refund": {
            "amount": 1,
            "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 added the C-refactor Category: Refactor label Feb 13, 2025
@ShankarSinghC ShankarSinghC self-assigned this Feb 13, 2025
@ShankarSinghC ShankarSinghC requested review from a team as code owners February 13, 2025 11:05
Copy link

semanticdiff-com bot commented Feb 13, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/relay.rs  45% smaller
  api-reference/openapi_spec.json  0% smaller
  crates/api_models/src/relay.rs  0% smaller
  crates/hyperswitch_domain_models/src/merchant_connector_account.rs  0% smaller
  crates/hyperswitch_domain_models/src/relay.rs  0% smaller
  crates/openapi/src/openapi.rs  0% smaller
  crates/router/src/routes/relay.rs  0% smaller

@ShankarSinghC ShankarSinghC linked an issue Feb 13, 2025 that may be closed by this pull request
@@ -17,13 +21,222 @@ use crate::{

pub mod utils;

pub async fn relay(
pub trait Validate {
type Error;
Copy link
Member

Choose a reason for hiding this comment

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

We should add Context here itself.

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Feb 13, 2025
jarnura
jarnura previously approved these changes Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-refactor Category: Refactor M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add trait based implementation for relay
3 participants