diff --git a/crates/common_utils/Cargo.toml b/crates/common_utils/Cargo.toml index 3619c93d772c..3a41b111b39d 100644 --- a/crates/common_utils/Cargo.toml +++ b/crates/common_utils/Cargo.toml @@ -38,6 +38,7 @@ strum = { version = "0.24.1", features = ["derive"] } thiserror = "1.0.40" time = { version = "0.3.21", features = ["serde", "serde-well-known", "std"] } tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"], optional = true } +utoipa = { version = "3.3.0", features = ["preserve_order"] } # First party crates common_enums = { version = "0.1.0", path = "../common_enums" } diff --git a/crates/common_utils/src/types.rs b/crates/common_utils/src/types.rs index cf94f2fe26ce..2fdbcdba700c 100644 --- a/crates/common_utils/src/types.rs +++ b/crates/common_utils/src/types.rs @@ -1,6 +1,7 @@ //! Types that can be used in other crates use error_stack::{IntoReport, ResultExt}; use serde::{de::Visitor, Deserialize, Deserializer}; +use utoipa::ToSchema; use crate::{ consts, @@ -8,7 +9,7 @@ use crate::{ }; /// Represents Percentage Value between 0 and 100 both inclusive -#[derive(Clone, Default, Debug, PartialEq, serde::Serialize)] +#[derive(Clone, Default, Debug, PartialEq, serde::Serialize, ToSchema)] pub struct Percentage { // this value will range from 0 to 100, decimal length defined by precision macro /// Percentage value ranging between 0 and 100 @@ -141,7 +142,7 @@ impl<'de, const PRECISION: u8> Deserialize<'de> for Percentage { } /// represents surcharge type and value -#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)] #[serde(rename_all = "snake_case", tag = "type", content = "value")] pub enum Surcharge { /// Fixed Surcharge value diff --git a/crates/router/src/openapi.rs b/crates/router/src/openapi.rs index cfb0268a9f80..19c4d87e184e 100644 --- a/crates/router/src/openapi.rs +++ b/crates/router/src/openapi.rs @@ -317,6 +317,7 @@ Never share your secret api keys. Keep them guarded and secure. api_models::payments::CaptureResponse, api_models::payment_methods::RequiredFieldInfo, api_models::payment_methods::MaskedBankDetails, + api_models::payment_methods::SurchargeDetailsResponse, api_models::refunds::RefundListRequest, api_models::refunds::RefundListResponse, api_models::payments::TimeRange, @@ -361,7 +362,9 @@ Never share your secret api keys. Keep them guarded and secure. api_models::payments::PaymentLinkResponse, api_models::payments::RetrievePaymentLinkResponse, api_models::payments::PaymentLinkInitiateRequest, - api_models::payments::PaymentLinkObject + api_models::payments::PaymentLinkObject, + common_utils::types::Surcharge, + common_utils::types::Percentage<{common_utils::consts::SURCHARGE_PERCENTAGE_PRECISION_LENGTH}> )), modifiers(&SecurityAddon) )] diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json index f5ad99f05752..17b7ee9a2826 100644 --- a/openapi/openapi_spec.json +++ b/openapi/openapi_spec.json @@ -5102,6 +5102,14 @@ ], "nullable": true }, + "surcharge_details": { + "allOf": [ + { + "$ref": "#/components/schemas/SurchargeDetailsResponse" + } + ], + "nullable": true + }, "requires_cvv": { "type": "boolean", "description": "Whether this payment method requires CVV to be collected", @@ -11158,6 +11166,20 @@ } } }, + "Percentage": { + "type": "object", + "description": "Represents Percentage Value between 0 and 100 both inclusive", + "required": [ + "percentage" + ], + "properties": { + "percentage": { + "type": "number", + "format": "float", + "description": "Percentage value ranging between 0 and 100" + } + } + }, "PhoneDetails": { "type": "object", "properties": { @@ -11975,6 +11997,89 @@ } } }, + "Surcharge": { + "oneOf": [ + { + "type": "object", + "required": [ + "type", + "value" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "fixed" + ] + }, + "value": { + "type": "integer", + "format": "int64", + "description": "Fixed Surcharge value" + } + } + }, + { + "type": "object", + "required": [ + "type", + "value" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "rate" + ] + }, + "value": { + "$ref": "#/components/schemas/Percentage" + } + } + } + ], + "description": "represents surcharge type and value", + "discriminator": { + "propertyName": "type" + } + }, + "SurchargeDetailsResponse": { + "type": "object", + "required": [ + "surcharge", + "display_surcharge_amount", + "display_tax_on_surcharge_amount", + "display_final_amount" + ], + "properties": { + "surcharge": { + "$ref": "#/components/schemas/Surcharge" + }, + "tax_on_surcharge": { + "allOf": [ + { + "$ref": "#/components/schemas/Percentage" + } + ], + "nullable": true + }, + "display_surcharge_amount": { + "type": "number", + "format": "double", + "description": "surcharge amount for this payment" + }, + "display_tax_on_surcharge_amount": { + "type": "number", + "format": "double", + "description": "tax on surcharge amount for this payment" + }, + "display_final_amount": { + "type": "number", + "format": "double", + "description": "sum of original amount," + } + } + }, "SwishQrData": { "type": "object" },