From 171b23b863679b0b331d2ca53134897a82d561a6 Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Wed, 18 Dec 2024 11:29:35 +0530 Subject: [PATCH 1/9] feat(router): add /relay endpoint --- .../api-reference/relay/relay-retrieve.mdx | 3 + api-reference/api-reference/relay/relay.mdx | 3 + api-reference/openapi_spec.json | 235 ++++++++++++++++++ crates/api_models/src/lib.rs | 1 + crates/api_models/src/relay.rs | 98 ++++++++ crates/common_utils/src/id_type.rs | 2 + crates/common_utils/src/id_type/relay.rs | 7 + crates/openapi/src/openapi.rs | 11 + crates/openapi/src/routes.rs | 3 +- crates/openapi/src/routes/relay.rs | 52 ++++ 10 files changed, 414 insertions(+), 1 deletion(-) create mode 100644 api-reference/api-reference/relay/relay-retrieve.mdx create mode 100644 api-reference/api-reference/relay/relay.mdx create mode 100644 crates/api_models/src/relay.rs create mode 100644 crates/common_utils/src/id_type/relay.rs create mode 100644 crates/openapi/src/routes/relay.rs diff --git a/api-reference/api-reference/relay/relay-retrieve.mdx b/api-reference/api-reference/relay/relay-retrieve.mdx new file mode 100644 index 00000000000..d65e62d31d7 --- /dev/null +++ b/api-reference/api-reference/relay/relay-retrieve.mdx @@ -0,0 +1,3 @@ +--- +openapi: openapi_spec get /relay/{relay_id} +--- \ No newline at end of file diff --git a/api-reference/api-reference/relay/relay.mdx b/api-reference/api-reference/relay/relay.mdx new file mode 100644 index 00000000000..a6b5962740a --- /dev/null +++ b/api-reference/api-reference/relay/relay.mdx @@ -0,0 +1,3 @@ +--- +openapi: openapi_spec post /relay +--- \ No newline at end of file diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index c31a8bd11ed..da55d076d9b 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -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": [ @@ -22709,6 +22807,143 @@ }, "additionalProperties": false }, + "RelayData": { + "oneOf": [ + { + "$ref": "#/components/schemas/RelayRefundRequest" + } + ] + }, + "RelayError": { + "type": "object", + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "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" + }, + "connector_id": { + "type": "string" + }, + "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": [ diff --git a/crates/api_models/src/lib.rs b/crates/api_models/src/lib.rs index a28332e7fea..19de6dcb69d 100644 --- a/crates/api_models/src/lib.rs +++ b/crates/api_models/src/lib.rs @@ -39,3 +39,4 @@ pub mod verifications; pub mod verify_connector; pub mod webhook_events; pub mod webhooks; +pub mod relay; diff --git a/crates/api_models/src/relay.rs b/crates/api_models/src/relay.rs new file mode 100644 index 00000000000..cd2c0497fa8 --- /dev/null +++ b/crates/api_models/src/relay.rs @@ -0,0 +1,98 @@ +use crate::enums; +use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; + +#[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 + #[schema(value_type = String)] + pub connector_id: common_utils::id_type::MerchantConnectorAccountId, + /// The business profile that is associated with this payment 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, +} + + + +#[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), +} + +#[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, +} + +#[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, +} + +#[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, +} diff --git a/crates/common_utils/src/id_type.rs b/crates/common_utils/src/id_type.rs index 594078bb405..743cce91c29 100644 --- a/crates/common_utils/src/id_type.rs +++ b/crates/common_utils/src/id_type.rs @@ -10,6 +10,7 @@ mod merchant_connector_account; mod organization; mod payment; mod profile; +mod relay; mod refunds; mod routing; mod tenant; @@ -42,6 +43,7 @@ pub use self::{ organization::OrganizationId, payment::{PaymentId, PaymentReferenceId}, profile::ProfileId, + relay::RelayId, refunds::RefundReferenceId, routing::RoutingId, tenant::TenantId, diff --git a/crates/common_utils/src/id_type/relay.rs b/crates/common_utils/src/id_type/relay.rs new file mode 100644 index 00000000000..4b71a6d2ca9 --- /dev/null +++ b/crates/common_utils/src/id_type/relay.rs @@ -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); \ No newline at end of file diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs index db0db93109b..a481aa6b907 100644 --- a/crates/openapi/src/openapi.rs +++ b/crates/openapi/src/openapi.rs @@ -84,6 +84,10 @@ Never share your secret api keys. Keep them guarded and secure. routes::payments::payments_complete_authorize, routes::payments::payments_post_session_tokens, + // Routes for relay + routes::relay, + routes::relay_retrieve, + // Routes for refunds routes::refunds::refunds_create, routes::refunds::refunds_retrieve, @@ -513,6 +517,13 @@ Never share your secret api keys. Keep them guarded and secure. api_models::payment_methods::PaymentMethodCollectLinkResponse, api_models::refunds::RefundListRequest, api_models::refunds::RefundListResponse, + api_models::relay::RelayRequest, + api_models::relay::RelayType, + api_models::relay::RelayData, + api_models::relay::RelayRefundRequest, + api_models::relay::RelayResponse, + api_models::relay::RelayStatus, + api_models::relay::RelayError, api_models::payments::AmountFilter, api_models::mandates::MandateRevokedResponse, api_models::mandates::MandateResponse, diff --git a/crates/openapi/src/routes.rs b/crates/openapi/src/routes.rs index 453f7f557d3..a7db6482e87 100644 --- a/crates/openapi/src/routes.rs +++ b/crates/openapi/src/routes.rs @@ -5,6 +5,7 @@ pub mod blocklist; pub mod customers; pub mod disputes; pub mod gsm; +pub mod relay; pub mod mandates; pub mod merchant_account; pub mod merchant_connector_account; @@ -21,5 +22,5 @@ pub mod webhook_events; pub use self::{ customers::*, mandates::*, merchant_account::*, merchant_connector_account::*, organization::*, - payment_method::*, payments::*, poll::*, refunds::*, routing::*, webhook_events::*, + payment_method::*, payments::*, poll::*, refunds::*, routing::*, webhook_events::*, relay::*, }; diff --git a/crates/openapi/src/routes/relay.rs b/crates/openapi/src/routes/relay.rs new file mode 100644 index 00000000000..0913750a683 --- /dev/null +++ b/crates/openapi/src/routes/relay.rs @@ -0,0 +1,52 @@ +/// Relay - Create +/// +/// Creates a relay request. +#[utoipa::path( + post, + path = "/relay", + request_body ( + content = RelayRequest, + examples (( + "Create a relay request" = ( + value = json!({ + "connector_resource_id": "7256228702616471803954", + "connector_id": "cu_123456", + "profile_id": "pro_123456", + "type": "refund", + "data": { + "amount": 6540, + "currency": "USD" + } + }) + ) + )) + ), + responses( + (status = 200, description = "Relay request", body = CustomerResponse), + (status = 400, description = "Invalid data") + + ), + tag = "Relay", + operation_id = "Relay Request", + security(("api_key" = [])) +)] + +pub async fn relay() {} + +/// Relay - Retrieve +/// +/// Retrieves a relay details. +#[utoipa::path( + get, + path = "/relay/{relay_id}", + params (("id" = String, Path, description = "The unique identifier for the Relay")), + responses( + (status = 200, description = "Relay Retrieved", body = RelayResponse), + (status = 404, description = "Relay details was not found") + ), + tag = "Relay", + operation_id = "Retrieve a Relay details", + security(("api_key" = []), ("ephemeral_key" = [])) +)] + +pub async fn relay_retrieve() {} From 53afd05afe215718754b7fc4356429658962a051 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Wed, 18 Dec 2024 06:03:32 +0000 Subject: [PATCH 2/9] docs(openapi): re-generate OpenAPI specification --- api-reference/openapi_spec.json | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index da55d076d9b..509437fc874 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -22822,10 +22822,12 @@ ], "properties": { "code": { - "type": "string" + "type": "string", + "description": "The error code" }, "message": { - "type": "string" + "type": "string", + "description": "The error message" } } }, @@ -22908,10 +22910,12 @@ "$ref": "#/components/schemas/RelayError" }, "connector_resource_id": { - "type": "string" + "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" + "type": "string", + "description": "Identifier of the connector ( merchant connector account ) which was chosen to make the payment" }, "profile_id": { "type": "string", From f2e16423c72f95212a42723a89fc2a7a910ee615 Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Wed, 18 Dec 2024 11:35:02 +0530 Subject: [PATCH 3/9] fix fmt --- crates/api_models/src/lib.rs | 2 +- crates/api_models/src/relay.rs | 5 ++--- crates/common_utils/src/id_type.rs | 4 ++-- crates/common_utils/src/id_type/relay.rs | 2 +- crates/openapi/src/routes.rs | 4 ++-- crates/openapi/src/routes/relay.rs | 4 ++-- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/crates/api_models/src/lib.rs b/crates/api_models/src/lib.rs index 19de6dcb69d..2d1e87ebf01 100644 --- a/crates/api_models/src/lib.rs +++ b/crates/api_models/src/lib.rs @@ -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; @@ -39,4 +40,3 @@ pub mod verifications; pub mod verify_connector; pub mod webhook_events; pub mod webhooks; -pub mod relay; diff --git a/crates/api_models/src/relay.rs b/crates/api_models/src/relay.rs index cd2c0497fa8..34cae38f615 100644 --- a/crates/api_models/src/relay.rs +++ b/crates/api_models/src/relay.rs @@ -1,7 +1,8 @@ -use crate::enums; 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 @@ -19,8 +20,6 @@ pub struct RelayRequest { pub data: Option, } - - #[derive(Debug, ToSchema, Clone, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] pub enum RelayType { diff --git a/crates/common_utils/src/id_type.rs b/crates/common_utils/src/id_type.rs index 743cce91c29..c7393155226 100644 --- a/crates/common_utils/src/id_type.rs +++ b/crates/common_utils/src/id_type.rs @@ -10,8 +10,8 @@ mod merchant_connector_account; mod organization; mod payment; mod profile; -mod relay; mod refunds; +mod relay; mod routing; mod tenant; @@ -43,8 +43,8 @@ pub use self::{ organization::OrganizationId, payment::{PaymentId, PaymentReferenceId}, profile::ProfileId, - relay::RelayId, refunds::RefundReferenceId, + relay::RelayId, routing::RoutingId, tenant::TenantId, }; diff --git a/crates/common_utils/src/id_type/relay.rs b/crates/common_utils/src/id_type/relay.rs index 4b71a6d2ca9..5db48c492f9 100644 --- a/crates/common_utils/src/id_type/relay.rs +++ b/crates/common_utils/src/id_type/relay.rs @@ -4,4 +4,4 @@ crate::id_type!( ); crate::impl_id_type_methods!(RelayId, "relay_id"); -crate::impl_debug_id_type!(RelayId); \ No newline at end of file +crate::impl_debug_id_type!(RelayId); diff --git a/crates/openapi/src/routes.rs b/crates/openapi/src/routes.rs index a7db6482e87..2c1c5824412 100644 --- a/crates/openapi/src/routes.rs +++ b/crates/openapi/src/routes.rs @@ -5,7 +5,6 @@ pub mod blocklist; pub mod customers; pub mod disputes; pub mod gsm; -pub mod relay; pub mod mandates; pub mod merchant_account; pub mod merchant_connector_account; @@ -17,10 +16,11 @@ pub mod payouts; pub mod poll; pub mod profile; pub mod refunds; +pub mod relay; pub mod routing; pub mod webhook_events; pub use self::{ customers::*, mandates::*, merchant_account::*, merchant_connector_account::*, organization::*, - payment_method::*, payments::*, poll::*, refunds::*, routing::*, webhook_events::*, relay::*, + payment_method::*, payments::*, poll::*, refunds::*, relay::*, routing::*, webhook_events::*, }; diff --git a/crates/openapi/src/routes/relay.rs b/crates/openapi/src/routes/relay.rs index 0913750a683..b163def2de2 100644 --- a/crates/openapi/src/routes/relay.rs +++ b/crates/openapi/src/routes/relay.rs @@ -1,5 +1,5 @@ /// Relay - Create -/// +/// /// Creates a relay request. #[utoipa::path( post, @@ -16,7 +16,7 @@ "data": { "amount": 6540, "currency": "USD" - } + } }) ) )) From 22be8b711fe4e79fcaac8f2f841123579168cedf Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Thu, 19 Dec 2024 15:59:12 +0530 Subject: [PATCH 4/9] add example in the relay response --- ...relay-retrieve.mdx => relay--retrieve.mdx} | 0 api-reference/mint.json | 7 +++ api-reference/openapi_spec.json | 48 ++++++++++++------- crates/api_models/src/relay.rs | 23 +++++---- crates/openapi/src/routes/relay.rs | 6 +-- 5 files changed, 56 insertions(+), 28 deletions(-) rename api-reference/api-reference/relay/{relay-retrieve.mdx => relay--retrieve.mdx} (100%) diff --git a/api-reference/api-reference/relay/relay-retrieve.mdx b/api-reference/api-reference/relay/relay--retrieve.mdx similarity index 100% rename from api-reference/api-reference/relay/relay-retrieve.mdx rename to api-reference/api-reference/relay/relay--retrieve.mdx diff --git a/api-reference/mint.json b/api-reference/mint.json index 04b16682e3c..5e9c9c6d36c 100644 --- a/api-reference/mint.json +++ b/api-reference/mint.json @@ -234,6 +234,13 @@ "api-reference/routing/routing--activate-config" ] }, + { + "group": "Relay", + "pages": [ + "api-reference/relay/relay", + "api-reference/relay/relay--retrieve" + ] + }, { "group": "Schemas", "pages": ["api-reference/schemas/outgoing--webhook"] diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index 509437fc874..2acf41021a7 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -967,13 +967,13 @@ "examples": { "Create a relay request": { "value": { - "connector_id": "cu_123456", + "connector_id": "mca_5apGeP94tMts6rg3U3kR", "connector_resource_id": "7256228702616471803954", "data": { "amount": 6540, "currency": "USD" }, - "profile_id": "pro_123456", + "profile_id": "pro_abcdefghijklmnopqrstuvwxyz", "type": "refund" } } @@ -988,7 +988,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CustomerResponse" + "$ref": "#/components/schemas/RelayResponse" } } } @@ -22841,7 +22841,8 @@ "amount": { "type": "integer", "format": "int64", - "description": "The amount that is being refunded" + "description": "The amount that is being refunded", + "example": 6540 }, "currency": { "$ref": "#/components/schemas/Currency" @@ -22849,7 +22850,9 @@ "reason": { "type": "string", "description": "The reason for the refund", - "nullable": true + "example": "Customer returned the product", + "nullable": true, + "maxLength": 255 } } }, @@ -22864,15 +22867,18 @@ "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" + "description": "The identifier that is associated to a resource at the connector reference to which the relay request is being made", + "example": "7256228702616471803954" }, "connector_id": { "type": "string", - "description": "Identifier of the connector ( merchant connector account ) which was chosen to make the payment" + "description": "Identifier of the connector ( merchant connector account ) to which relay request is being made", + "example": "mca_5apGeP94tMts6rg3U3kR" }, "profile_id": { "type": "string", - "description": "The business profile that is associated with this payment request" + "description": "The business profile that is associated with this payment request", + "example": "pro_abcdefghijklmnopqrstuvwxyz" }, "type": { "$ref": "#/components/schemas/RelayType" @@ -22892,7 +22898,6 @@ "required": [ "id", "status", - "error", "connector_resource_id", "connector_id", "profile_id", @@ -22901,25 +22906,34 @@ "properties": { "id": { "type": "string", - "description": "The unique identifier for the Relay" + "description": "The unique identifier for the Relay", + "example": "relay_mbabizu24mvu3mela5njyhpit4" }, "status": { "$ref": "#/components/schemas/RelayStatus" }, "error": { - "$ref": "#/components/schemas/RelayError" + "allOf": [ + { + "$ref": "#/components/schemas/RelayError" + } + ], + "nullable": true }, "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" + "description": "The identifier that is associated to a resource at the connector reference to which the relay request is being made", + "example": "7256228702616471803954" }, "connector_id": { "type": "string", - "description": "Identifier of the connector ( merchant connector account ) which was chosen to make the payment" + "description": "Identifier of the connector ( merchant connector account ) which was chosen to make the payment", + "example": "mca_5apGeP94tMts6rg3U3kR" }, "profile_id": { "type": "string", - "description": "The business profile that is associated with this relay request." + "description": "The business profile that is associated with this relay request.", + "example": "pro_abcdefghijklmnopqrstuvwxyz" }, "type": { "$ref": "#/components/schemas/RelayType" @@ -22937,9 +22951,9 @@ "RelayStatus": { "type": "string", "enum": [ - "Success", - "Processing", - "Failure" + "success", + "processing", + "failure" ] }, "RelayType": { diff --git a/crates/api_models/src/relay.rs b/crates/api_models/src/relay.rs index 34cae38f615..bde5f04fc11 100644 --- a/crates/api_models/src/relay.rs +++ b/crates/api_models/src/relay.rs @@ -3,15 +3,18 @@ use utoipa::ToSchema; use crate::enums; +pub use common_utils::types::MinorUnit; + #[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 + #[schema(example = "7256228702616471803954")] pub connector_resource_id: String, - /// Identifier of the connector ( merchant connector account ) which was chosen to make the payment - #[schema(value_type = String)] + /// Identifier of the connector ( merchant connector account ) to which relay request is being made + #[schema(example = "mca_5apGeP94tMts6rg3U3kR", value_type = String)] pub connector_id: common_utils::id_type::MerchantConnectorAccountId, /// The business profile that is associated with this payment request - #[schema(value_type = String)] + #[schema(example = "pro_abcdefghijklmnopqrstuvwxyz", value_type = String)] pub profile_id: common_utils::id_type::ProfileId, /// The type of relay request #[serde(rename = "type")] @@ -37,30 +40,33 @@ pub enum RelayData { #[derive(Debug, ToSchema, Clone, Deserialize, Serialize)] pub struct RelayRefundRequest { /// The amount that is being refunded - pub amount: i64, + #[schema(value_type = i64 , example = 6540)] + pub amount: MinorUnit, /// The currency in which the amount is being refunded #[schema(value_type = Currency)] pub currency: enums::Currency, /// The reason for the refund + #[schema(max_length = 255, example = "Customer returned the product")] pub reason: Option, } #[derive(Debug, ToSchema, Clone, Deserialize, Serialize)] pub struct RelayResponse { /// The unique identifier for the Relay - #[schema(value_type = String)] + #[schema(example = "relay_mbabizu24mvu3mela5njyhpit4", 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, + pub error: Option, /// 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 ) which was chosen to make the payment - #[schema(value_type = String)] + #[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. - #[schema(value_type = String)] + #[schema(example = "pro_abcdefghijklmnopqrstuvwxyz", value_type = String)] pub profile_id: common_utils::id_type::ProfileId, /// The type of relay request #[serde(rename = "type")] @@ -70,6 +76,7 @@ pub struct RelayResponse { } #[derive(Debug, ToSchema, Clone, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] pub enum RelayStatus { /// The relay request is successful Success, diff --git a/crates/openapi/src/routes/relay.rs b/crates/openapi/src/routes/relay.rs index b163def2de2..2963f8574ee 100644 --- a/crates/openapi/src/routes/relay.rs +++ b/crates/openapi/src/routes/relay.rs @@ -10,8 +10,8 @@ "Create a relay request" = ( value = json!({ "connector_resource_id": "7256228702616471803954", - "connector_id": "cu_123456", - "profile_id": "pro_123456", + "connector_id": "mca_5apGeP94tMts6rg3U3kR", + "profile_id": "pro_abcdefghijklmnopqrstuvwxyz", "type": "refund", "data": { "amount": 6540, @@ -22,7 +22,7 @@ )) ), responses( - (status = 200, description = "Relay request", body = CustomerResponse), + (status = 200, description = "Relay request", body = RelayResponse), (status = 400, description = "Invalid data") ), From a437639a3c074c6bda1d5215b13fbb54d8f454d8 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 11:00:58 +0000 Subject: [PATCH 5/9] docs(openapi): re-generate OpenAPI specification --- api-reference/openapi_spec.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index 17c7c5a7928..b722b824835 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -23114,7 +23114,7 @@ }, "connector_id": { "type": "string", - "description": "Identifier of the connector ( merchant connector account ) which was chosen to make the payment", + "description": "Identifier of the connector ( merchant connector account ) to which relay request is being made", "example": "mca_5apGeP94tMts6rg3U3kR" }, "profile_id": { From 3ce44bbba7427d2440dbb6f74263c0f970d322a4 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 11:06:51 +0000 Subject: [PATCH 6/9] chore: run formatter --- crates/api_models/src/relay.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/api_models/src/relay.rs b/crates/api_models/src/relay.rs index 93e3c43789b..1251dca7e80 100644 --- a/crates/api_models/src/relay.rs +++ b/crates/api_models/src/relay.rs @@ -1,10 +1,9 @@ +pub use common_utils::types::MinorUnit; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use crate::enums; -pub use common_utils::types::MinorUnit; - #[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 From 9a55135c0d2cbc04bd8ec220dadb82ed7f930eb3 Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Thu, 19 Dec 2024 16:48:45 +0530 Subject: [PATCH 7/9] address pr comments --- api-reference/openapi_spec.json | 16 +++++++++++----- crates/api_models/src/relay.rs | 11 +++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index 17c7c5a7928..c9dc39db590 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -23054,7 +23054,7 @@ "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", + "description": "The identifier that is associated to a resource at the connector to which the relay request is being made", "example": "7256228702616471803954" }, "connector_id": { @@ -23064,7 +23064,7 @@ }, "profile_id": { "type": "string", - "description": "The business profile that is associated with this payment request", + "description": "The business profile that is associated with this relay request", "example": "pro_abcdefghijklmnopqrstuvwxyz" }, "type": { @@ -23099,6 +23099,12 @@ "status": { "$ref": "#/components/schemas/RelayStatus" }, + "connector_reference_id": { + "type": "string", + "description": "The reference identifier provided by the connector for the relay request", + "example": "pi_3MKEivSFNglxLpam0ZaL98q9", + "nullable": true + }, "error": { "allOf": [ { @@ -23109,17 +23115,17 @@ }, "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", + "description": "The identifier that is associated to a resource at the connector to which the relay request is being made", "example": "7256228702616471803954" }, "connector_id": { "type": "string", - "description": "Identifier of the connector ( merchant connector account ) which was chosen to make the payment", + "description": "Identifier of the connector ( merchant connector account ) to which relay request is being made", "example": "mca_5apGeP94tMts6rg3U3kR" }, "profile_id": { "type": "string", - "description": "The business profile that is associated with this relay request.", + "description": "The business profile that is associated with this relay request", "example": "pro_abcdefghijklmnopqrstuvwxyz" }, "type": { diff --git a/crates/api_models/src/relay.rs b/crates/api_models/src/relay.rs index 93e3c43789b..a97cd198786 100644 --- a/crates/api_models/src/relay.rs +++ b/crates/api_models/src/relay.rs @@ -7,13 +7,13 @@ pub use common_utils::types::MinorUnit; #[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 + /// 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 = "mca_5apGeP94tMts6rg3U3kR", value_type = String)] pub connector_id: common_utils::id_type::MerchantConnectorAccountId, - /// The business profile that is associated with this payment 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 @@ -57,15 +57,18 @@ pub struct RelayResponse { 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(example = "pi_3MKEivSFNglxLpam0ZaL98q9")] + pub connector_reference_id: Option, /// The error details if the relay request failed pub error: Option, - /// The identifier that is associated to a resource at the connector reference to which the relay request is being made + /// 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 = "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 From e7db9e01abe8ce78f42ff89cf2a217d9a3c745d0 Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Fri, 20 Dec 2024 11:27:38 +0530 Subject: [PATCH 8/9] address pr comments --- api-reference/openapi_spec.json | 32 +++++++++++++++++++++--------- crates/api_models/src/relay.rs | 3 --- crates/openapi/src/routes/relay.rs | 22 ++++++++++++-------- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index c9dc39db590..d2dc88889b5 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -958,6 +958,26 @@ "summary": "Relay - Create", "description": "Creates a relay request.", "operationId": "Relay Request", + "parameters": [ + { + "name": "X-Profile-Id", + "in": "header", + "description": "Profile ID for authentication", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "X-Idempotency-Key", + "in": "header", + "description": "Idempotency Key for relay request", + "required": true, + "schema": { + "type": "string" + } + } + ], "requestBody": { "content": { "application/json": { @@ -1014,9 +1034,9 @@ "operationId": "Retrieve a Relay details", "parameters": [ { - "name": "id", - "in": "path", - "description": "The unique identifier for the Relay", + "name": "X-Profile-Id", + "in": "header", + "description": "Profile ID for authentication", "required": true, "schema": { "type": "string" @@ -23048,7 +23068,6 @@ "required": [ "connector_resource_id", "connector_id", - "profile_id", "type" ], "properties": { @@ -23062,11 +23081,6 @@ "description": "Identifier of the connector ( merchant connector account ) to which relay request is being made", "example": "mca_5apGeP94tMts6rg3U3kR" }, - "profile_id": { - "type": "string", - "description": "The business profile that is associated with this relay request", - "example": "pro_abcdefghijklmnopqrstuvwxyz" - }, "type": { "$ref": "#/components/schemas/RelayType" }, diff --git a/crates/api_models/src/relay.rs b/crates/api_models/src/relay.rs index dc536b21477..7e094f28360 100644 --- a/crates/api_models/src/relay.rs +++ b/crates/api_models/src/relay.rs @@ -12,9 +12,6 @@ pub struct RelayRequest { /// Identifier of the connector ( merchant connector account ) to which relay request is being made #[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 - #[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, diff --git a/crates/openapi/src/routes/relay.rs b/crates/openapi/src/routes/relay.rs index 2963f8574ee..bcbe90eddc9 100644 --- a/crates/openapi/src/routes/relay.rs +++ b/crates/openapi/src/routes/relay.rs @@ -4,11 +4,11 @@ #[utoipa::path( post, path = "/relay", - request_body ( + request_body( content = RelayRequest, - examples (( - "Create a relay request" = ( - value = json!({ + examples(( + "Create a relay request" = ( + value = json!({ "connector_resource_id": "7256228702616471803954", "connector_id": "mca_5apGeP94tMts6rg3U3kR", "profile_id": "pro_abcdefghijklmnopqrstuvwxyz", @@ -17,14 +17,17 @@ "amount": 6540, "currency": "USD" } - }) - ) - )) + }) + ) + )) ), responses( (status = 200, description = "Relay request", body = RelayResponse), (status = 400, description = "Invalid data") - + ), + params( + ("X-Profile-Id" = String, Header, description = "Profile ID for authentication"), + ("X-Idempotency-Key" = String, Header, description = "Idempotency Key for relay request") ), tag = "Relay", operation_id = "Relay Request", @@ -44,6 +47,9 @@ pub async fn relay() {} (status = 200, description = "Relay Retrieved", body = RelayResponse), (status = 404, description = "Relay details was not found") ), + params( + ("X-Profile-Id" = String, Header, description = "Profile ID for authentication") + ), tag = "Relay", operation_id = "Retrieve a Relay details", security(("api_key" = []), ("ephemeral_key" = [])) From 2b94a33a076cb264105c0c5c67abc8143192b6d0 Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Fri, 20 Dec 2024 13:39:21 +0530 Subject: [PATCH 9/9] remove profile id from the req --- api-reference/openapi_spec.json | 1 - crates/openapi/src/routes/relay.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index d2dc88889b5..0bba55384fa 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -993,7 +993,6 @@ "amount": 6540, "currency": "USD" }, - "profile_id": "pro_abcdefghijklmnopqrstuvwxyz", "type": "refund" } } diff --git a/crates/openapi/src/routes/relay.rs b/crates/openapi/src/routes/relay.rs index bcbe90eddc9..9100bf47f75 100644 --- a/crates/openapi/src/routes/relay.rs +++ b/crates/openapi/src/routes/relay.rs @@ -11,7 +11,6 @@ value = json!({ "connector_resource_id": "7256228702616471803954", "connector_id": "mca_5apGeP94tMts6rg3U3kR", - "profile_id": "pro_abcdefghijklmnopqrstuvwxyz", "type": "refund", "data": { "amount": 6540,