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 /relay endpoint #6870

Merged
merged 14 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api-reference/api-reference/relay/relay-retrieve.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: openapi_spec get /relay/{relay_id}
ShankarSinghC marked this conversation as resolved.
Show resolved Hide resolved
---
3 changes: 3 additions & 0 deletions api-reference/api-reference/relay/relay.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: openapi_spec post /relay
---
239 changes: 239 additions & 0 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,104 @@
]
}
},
"/relay": {
"post": {
"tags": [
"Relay"
],
"summary": "Relay - Create",
"description": "Creates a relay request.",
"operationId": "Relay Request",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RelayRequest"
},
"examples": {
"Create a relay request": {
"value": {
"connector_id": "cu_123456",
"connector_resource_id": "7256228702616471803954",
"data": {
"amount": 6540,
"currency": "USD"
},
"profile_id": "pro_123456",
"type": "refund"
}
}
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Relay request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CustomerResponse"
}
}
}
},
"400": {
"description": "Invalid data"
}
},
"security": [
{
"api_key": []
}
]
}
},
"/relay/{relay_id}": {
"get": {
"tags": [
"Relay"
],
"summary": "Relay - Retrieve",
"description": "Retrieves a relay details.",
"operationId": "Retrieve a Relay details",
"parameters": [
{
"name": "id",
"in": "path",
"description": "The unique identifier for the Relay",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Relay Retrieved",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RelayResponse"
}
}
}
},
"404": {
"description": "Relay details was not found"
}
},
"security": [
{
"api_key": []
},
{
"ephemeral_key": []
}
]
}
},
"/refunds": {
"post": {
"tags": [
Expand Down Expand Up @@ -22896,6 +22994,147 @@
},
"additionalProperties": false
},
"RelayData": {
"oneOf": [
{
"$ref": "#/components/schemas/RelayRefundRequest"
}
]
},
"RelayError": {
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "string",
"description": "The error code"
},
"message": {
"type": "string",
"description": "The error message"
}
}
},
"RelayRefundRequest": {
"type": "object",
"required": [
"amount",
"currency"
],
"properties": {
"amount": {
"type": "integer",
"format": "int64",
"description": "The amount that is being refunded"
},
"currency": {
"$ref": "#/components/schemas/Currency"
},
"reason": {
"type": "string",
"description": "The reason for the refund",
"nullable": true
}
}
},
"RelayRequest": {
"type": "object",
"required": [
"connector_resource_id",
"connector_id",
"profile_id",
"type"
],
"properties": {
"connector_resource_id": {
"type": "string",
"description": "The identifier that is associated to a resource at the connector reference to which the relay request is being made"
},
"connector_id": {
"type": "string",
"description": "Identifier of the connector ( merchant connector account ) which was chosen to make the payment"
},
"profile_id": {
"type": "string",
"description": "The business profile that is associated with this payment request"
},
"type": {
"$ref": "#/components/schemas/RelayType"
},
"data": {
"allOf": [
{
"$ref": "#/components/schemas/RelayData"
}
],
"nullable": true
}
}
},
"RelayResponse": {
"type": "object",
"required": [
"id",
"status",
"error",
"connector_resource_id",
"connector_id",
"profile_id",
"type"
],
"properties": {
"id": {
"type": "string",
"description": "The unique identifier for the Relay"
},
"status": {
"$ref": "#/components/schemas/RelayStatus"
},
"error": {
"$ref": "#/components/schemas/RelayError"
},
"connector_resource_id": {
"type": "string",
"description": "The identifier that is associated to a resource at the connector reference to which the relay request is being made"
},
"connector_id": {
"type": "string",
"description": "Identifier of the connector ( merchant connector account ) which was chosen to make the payment"
},
"profile_id": {
"type": "string",
"description": "The business profile that is associated with this relay request."
},
"type": {
"$ref": "#/components/schemas/RelayType"
},
"data": {
"allOf": [
{
"$ref": "#/components/schemas/RelayData"
}
],
"nullable": true
}
}
},
"RelayStatus": {
"type": "string",
"enum": [
"Success",
"Processing",
"Failure"
]
},
"RelayType": {
"type": "string",
"enum": [
"refund"
]
},
"RequestPaymentMethodTypes": {
"type": "object",
"required": [
Expand Down
1 change: 1 addition & 0 deletions crates/api_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod poll;
#[cfg(feature = "recon")]
pub mod recon;
pub mod refunds;
pub mod relay;
pub mod routing;
pub mod surcharge_decision_configs;
pub mod user;
Expand Down
97 changes: 97 additions & 0 deletions crates/api_models/src/relay.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

use crate::enums;

#[derive(Debug, ToSchema, Clone, Deserialize, Serialize)]
pub struct RelayRequest {
/// The identifier that is associated to a resource at the connector reference to which the relay request is being made
pub connector_resource_id: String,
/// Identifier of the connector ( merchant connector account ) which was chosen to make the payment
ShankarSinghC marked this conversation as resolved.
Show resolved Hide resolved
#[schema(value_type = String)]
pub connector_id: common_utils::id_type::MerchantConnectorAccountId,
/// The business profile that is associated with this payment request
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// The business profile that is associated with this payment request
/// The business profile that is associated with this relay request

#[schema(value_type = String)]
pub profile_id: common_utils::id_type::ProfileId,
Copy link
Member

Choose a reason for hiding this comment

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

move this to headers

/// The type of relay request
#[serde(rename = "type")]
pub relay_type: RelayType,
/// The data that is associated with the relay request
pub data: Option<RelayData>,
}

#[derive(Debug, ToSchema, Clone, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum RelayType {
/// The relay request is for a refund
Refund,
}

#[derive(Debug, ToSchema, Clone, Deserialize, Serialize)]
#[serde(rename_all = "snake_case", untagged)]
Copy link
Member

Choose a reason for hiding this comment

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

do not use untagged for deserialization. You can rely on the relay_type to infer this. Can be changed in the subsequent PRs as well

pub enum RelayData {
/// The data that is associated with a refund relay request
Refund(RelayRefundRequest),
}

#[derive(Debug, ToSchema, Clone, Deserialize, Serialize)]
pub struct RelayRefundRequest {
/// The amount that is being refunded
pub amount: i64,
/// The currency in which the amount is being refunded
#[schema(value_type = Currency)]
pub currency: enums::Currency,
/// The reason for the refund
pub reason: Option<String>,
}

#[derive(Debug, ToSchema, Clone, Deserialize, Serialize)]
pub struct RelayResponse {
/// The unique identifier for the Relay
#[schema(value_type = String)]
pub id: common_utils::id_type::RelayId,
/// The status of the relay request
pub status: RelayStatus,
/// The error details if the relay request failed
pub error: RelayError,
/// The identifier that is associated to a resource at the connector reference to which the relay request is being made
pub connector_resource_id: String,
/// Identifier of the connector ( merchant connector account ) which was chosen to make the payment
#[schema(value_type = String)]
pub connector_id: common_utils::id_type::MerchantConnectorAccountId,
/// The business profile that is associated with this relay request.
#[schema(value_type = String)]
pub profile_id: common_utils::id_type::ProfileId,
/// The type of relay request
#[serde(rename = "type")]
pub relay_type: RelayType,
/// The data that is associated with the relay request
pub data: Option<RelayData>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add connector_reference_id in the response

}

#[derive(Debug, ToSchema, Clone, Deserialize, Serialize)]
pub enum RelayStatus {
/// The relay request is successful
Success,
/// The relay request is being processed
Processing,
/// The relay request has failed
Failure,
}

#[derive(Debug, ToSchema, Clone, Deserialize, Serialize)]
pub struct RelayError {
/// The error code
pub code: String,
/// The error message
pub message: String,
}

#[derive(Debug, ToSchema, Clone, Deserialize, Serialize)]
pub struct RelayRetrieveRequest {
/// The unique identifier for the Relay
#[serde(default)]
pub force_sync: bool,
/// The unique identifier for the Relay
pub id: String,
}
2 changes: 2 additions & 0 deletions crates/common_utils/src/id_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod organization;
mod payment;
mod profile;
mod refunds;
mod relay;
mod routing;
mod tenant;

Expand Down Expand Up @@ -43,6 +44,7 @@ pub use self::{
payment::{PaymentId, PaymentReferenceId},
profile::ProfileId,
refunds::RefundReferenceId,
relay::RelayId,
routing::RoutingId,
tenant::TenantId,
};
Expand Down
7 changes: 7 additions & 0 deletions crates/common_utils/src/id_type/relay.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
crate::id_type!(
RelayId,
"A type for relay_id that can be used for relay ids"
);
crate::impl_id_type_methods!(RelayId, "relay_id");

crate::impl_debug_id_type!(RelayId);
Loading
Loading