feat(router): add db interface for /relay (#6879)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Shankar Singh C
2024-12-22 22:41:28 +05:30
committed by GitHub
parent 977cb704e7
commit 0f8b0b3bc8
29 changed files with 1152 additions and 58 deletions

View File

@ -1,33 +1,27 @@
pub use common_utils::types::MinorUnit;
use common_utils::types::MinorUnit;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use crate::enums;
use crate::enums as api_enums;
#[derive(Debug, ToSchema, Clone, Deserialize, Serialize)]
pub struct RelayRequest {
/// The identifier that is associated to a resource at the connector to which the relay request is being made
/// The identifier that is associated to a resource at the connector reference to which the relay request is being made
#[schema(example = "7256228702616471803954")]
pub connector_resource_id: String,
/// Identifier of the connector ( merchant connector account ) to which relay request is being made
/// Identifier of the connector ( merchant connector account ) which was chosen to make the payment
#[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)]
pub connector_id: common_utils::id_type::MerchantConnectorAccountId,
/// The type of relay request
#[serde(rename = "type")]
pub relay_type: RelayType,
#[schema(value_type = RelayType)]
pub relay_type: api_enums::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)]
pub enum RelayData {
/// The data that is associated with a refund relay request
Refund(RelayRefundRequest),
@ -40,7 +34,7 @@ pub struct RelayRefundRequest {
pub amount: MinorUnit,
/// The currency in which the amount is being refunded
#[schema(value_type = Currency)]
pub currency: enums::Currency,
pub currency: api_enums::Currency,
/// The reason for the refund
#[schema(max_length = 255, example = "Customer returned the product")]
pub reason: Option<String>,
@ -52,39 +46,30 @@ pub struct RelayResponse {
#[schema(example = "relay_mbabizu24mvu3mela5njyhpit4", value_type = String)]
pub id: common_utils::id_type::RelayId,
/// The status of the relay request
pub status: RelayStatus,
/// The reference identifier provided by the connector for the relay request
#[schema(value_type = RelayStatus)]
pub status: api_enums::RelayStatus,
/// The identifier that is associated to a resource at the connector reference to which the relay request is being made
#[schema(example = "pi_3MKEivSFNglxLpam0ZaL98q9")]
pub connector_reference_id: Option<String>,
pub connector_resource_id: String,
/// The error details if the relay request failed
pub error: Option<RelayError>,
/// The identifier that is associated to a resource at the connector to which the relay request is being made
#[schema(example = "7256228702616471803954")]
pub connector_resource_id: String,
/// Identifier of the connector ( merchant connector account ) to which relay request is being made
#[schema(example = "re_3QY4TnEOqOywnAIx1Mm1p7GQ")]
pub connector_reference_id: Option<String>,
/// Identifier of the connector ( merchant connector account ) which was chosen to make the payment
#[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)]
pub connector_id: common_utils::id_type::MerchantConnectorAccountId,
/// The business profile that is associated with this relay request
/// The business profile that is associated with this relay request.
#[schema(example = "pro_abcdefghijklmnopqrstuvwxyz", value_type = String)]
pub profile_id: common_utils::id_type::ProfileId,
/// The type of relay request
#[serde(rename = "type")]
pub relay_type: RelayType,
#[schema(value_type = RelayType)]
pub relay_type: api_enums::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 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
@ -101,3 +86,7 @@ pub struct RelayRetrieveRequest {
/// The unique identifier for the Relay
pub id: String,
}
impl common_utils::events::ApiEventMetric for RelayRequest {}
impl common_utils::events::ApiEventMetric for RelayResponse {}