Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(core): update response for PaymentsDynamicTaxCalculationResponse (#5909)
Swangi Kumari45c19a1729af
diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.jsonindex 7f59ad24c0..f7aa7923b0 100644--- a/api-reference-v2/openapi_spec.json+++ b/api-reference-v2/openapi_spec.json@@ -6224,6 +6224,28 @@"BRW"]},+ "DisplayAmountOnSdk": {+ "type": "object",+ "required": [+ "net_amount",+ "order_tax_amount",+ "shipping_cost"+ ],+ "properties": {+ "net_amount": {+ "type": "string",+ "description": "net amount = amount + order_tax_amount + shipping_cost"+ },+ "order_tax_amount": {+ "type": "string",+ "description": "order tax amount calculated by tax connectors"+ },+ "shipping_cost": {+ "type": "string",+ "description": "shipping cost for the order"+ }+ }+ },"DisputeResponse": {"type": "object","required": [@@ -13549,7 +13571,8 @@"type": "object","required": ["payment_id",- "net_amount"+ "net_amount",+ "display_amount"],"properties": {"payment_id": {@@ -13574,6 +13597,9 @@}],"nullable": true+ },+ "display_amount": {+ "$ref": "#/components/schemas/DisplayAmountOnSdk"}}},diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.jsonindex 58c8bb9afb..cf02aefcf7 100644--- a/api-reference/openapi_spec.json+++ b/api-reference/openapi_spec.json@@ -10015,6 +10015,28 @@"BRW"]},+ "DisplayAmountOnSdk": {+ "type": "object",+ "required": [+ "net_amount",+ "order_tax_amount",+ "shipping_cost"+ ],+ "properties": {+ "net_amount": {+ "type": "string",+ "description": "net amount = amount + order_tax_amount + shipping_cost"+ },+ "order_tax_amount": {+ "type": "string",+ "description": "order tax amount calculated by tax connectors"+ },+ "shipping_cost": {+ "type": "string",+ "description": "shipping cost for the order"+ }+ }+ },"DisputeResponse": {"type": "object","required": [@@ -17719,7 +17741,8 @@"type": "object","required": ["payment_id",- "net_amount"+ "net_amount",+ "display_amount"],"properties": {"payment_id": {@@ -17744,6 +17767,9 @@}],"nullable": true+ },+ "display_amount": {+ "$ref": "#/components/schemas/DisplayAmountOnSdk"}}},diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex 01a786f523..20f1205e14 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -4627,6 +4627,21 @@ pub struct PaymentsDynamicTaxCalculationResponse {pub order_tax_amount: Option<MinorUnit>,/// shipping cost for the orderpub shipping_cost: Option<MinorUnit>,+ /// amount in Base Unit display format+ pub display_amount: DisplayAmountOnSdk,+}++#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]+pub struct DisplayAmountOnSdk {+ /// net amount = amount + order_tax_amount + shipping_cost+ #[schema(value_type = String)]+ pub net_amount: StringMajorUnit,+ /// order tax amount calculated by tax connectors+ #[schema(value_type = String)]+ pub order_tax_amount: Option<StringMajorUnit>,+ /// shipping cost for the order+ #[schema(value_type = String)]+ pub shipping_cost: Option<StringMajorUnit>,}#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rsindex 6219fd6de2..297228cc25 100644--- a/crates/openapi/src/openapi.rs+++ b/crates/openapi/src/openapi.rs@@ -615,6 +615,7 @@ Never share your secret api keys. Keep them guarded and secure.api_models::payments::additional_info::UpiCollectAdditionalData,api_models::payments::PaymentsDynamicTaxCalculationRequest,api_models::payments::PaymentsDynamicTaxCalculationResponse,+ api_models::payments::DisplayAmountOnSdk,)),modifiers(&SecurityAddon))]diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rsindex 5393e8d6fa..31feb8e85b 100644--- a/crates/openapi/src/openapi_v2.rs+++ b/crates/openapi/src/openapi_v2.rs@@ -522,6 +522,7 @@ Never share your secret api keys. Keep them guarded and secure.api_models::payments::additional_info::UpiCollectAdditionalData,api_models::payments::PaymentsDynamicTaxCalculationRequest,api_models::payments::PaymentsDynamicTaxCalculationResponse,+ api_models::payments::DisplayAmountOnSdk,)),modifiers(&SecurityAddon))]diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rsindex a48aed1fb2..93fa3ed44b 100644--- a/crates/router/src/core/payments/transformers.rs+++ b/crates/router/src/core/payments/transformers.rs@@ -4,8 +4,13 @@ use api_models::payments::{Address, CustomerDetails, CustomerDetailsResponse, FrmMessage, PaymentChargeRequest,PaymentChargeResponse, RequestSurchargeDetails,};-use common_enums::RequestIncrementalAuthorization;-use common_utils::{consts::X_HS_LATENCY, fp_utils, pii::Email, types::MinorUnit};+use common_enums::{Currency, RequestIncrementalAuthorization};+use common_utils::{+ consts::X_HS_LATENCY,+ fp_utils,+ pii::Email,+ types::{AmountConvertor, MinorUnit, StringMajorUnitForConnector},+};use diesel_models::ephemeral_key;use error_stack::{report, ResultExt};use hyperswitch_domain_models::{payments::payment_intent::CustomerData, router_request_types};@@ -503,18 +508,80 @@ whereamount = amount + tax_amount;}+ let currency = payment_data+ .get_payment_attempt()+ .currency+ .get_required_value("currency")?;+Ok(services::ApplicationResponse::JsonWithHeaders((Self {net_amount: amount,payment_id: payment_data.get_payment_attempt().payment_id.clone(),order_tax_amount,shipping_cost,+ display_amount: api_models::payments::DisplayAmountOnSdk::foreign_try_from((+ amount,+ shipping_cost,+ order_tax_amount,+ currency,+ ))?,},vec![],)))}}+impl ForeignTryFrom<(MinorUnit, Option<MinorUnit>, Option<MinorUnit>, Currency)>+ for api_models::payments::DisplayAmountOnSdk+{+ type Error = error_stack::Report<errors::ApiErrorResponse>;++ fn foreign_try_from(+ (net_amount, shipping_cost, order_tax_amount, currency): (+ MinorUnit,+ Option<MinorUnit>,+ Option<MinorUnit>,+ Currency,+ ),+ ) -> Result<Self, Self::Error> {+ let major_unit_convertor = StringMajorUnitForConnector;++ let sdk_net_amount = major_unit_convertor+ .convert(net_amount, currency)+ .change_context(errors::ApiErrorResponse::PreconditionFailed {+ message: "Failed to convert net_amount to base unit".to_string(),+ })+ .attach_printable("Failed to convert net_amount to string major unit")?;++ let sdk_shipping_cost = shipping_cost+ .map(|cost| {+ major_unit_convertor+ .convert(cost, currency)+ .change_context(errors::ApiErrorResponse::PreconditionFailed {+ message: "Failed to convert shipping_cost to base unit".to_string(),+ })+ .attach_printable("Failed to convert shipping_cost to string major unit")+ })+ .transpose()?;++ let sdk_order_tax_amount = order_tax_amount+ .map(|cost| {+ major_unit_convertor+ .convert(cost, currency)+ .change_context(errors::ApiErrorResponse::PreconditionFailed {+ message: "Failed to convert order_tax_amount to base unit".to_string(),+ })+ .attach_printable("Failed to convert order_tax_amount to string major unit")+ })+ .transpose()?;+ Ok(Self {+ net_amount: sdk_net_amount,+ shipping_cost: sdk_shipping_cost,+ order_tax_amount: sdk_order_tax_amount,+ })+ }+}+impl<F, Op, D> ToResponse<F, D, Op> for api::VerifyResponsewhereF: Clone,