mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
refactor(core): update response for PaymentsDynamicTaxCalculationResponse (#5909)
This commit is contained in:
@ -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"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -4627,6 +4627,21 @@ pub struct PaymentsDynamicTaxCalculationResponse {
|
||||
pub order_tax_amount: Option<MinorUnit>,
|
||||
/// shipping cost for the order
|
||||
pub 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)]
|
||||
|
||||
@ -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)
|
||||
)]
|
||||
|
||||
@ -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)
|
||||
)]
|
||||
|
||||
@ -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 @@ where
|
||||
amount = 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::VerifyResponse
|
||||
where
|
||||
F: Clone,
|
||||
|
||||
Reference in New Issue
Block a user