mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
feat: calculate surcharge for customer saved card list (#3039)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -8,7 +8,7 @@ use common_utils::{
|
||||
types::{Percentage, Surcharge},
|
||||
};
|
||||
use serde::de;
|
||||
use utoipa::ToSchema;
|
||||
use utoipa::{schema, ToSchema};
|
||||
|
||||
#[cfg(feature = "payouts")]
|
||||
use crate::payouts;
|
||||
@ -264,19 +264,6 @@ pub struct CardNetworkTypes {
|
||||
pub card_network: api_enums::CardNetwork,
|
||||
|
||||
/// surcharge details for this card network
|
||||
#[schema(example = r#"
|
||||
{
|
||||
"surcharge": {
|
||||
"type": "rate",
|
||||
"value": {
|
||||
"percentage": 2.5
|
||||
}
|
||||
},
|
||||
"tax_on_surcharge": {
|
||||
"percentage": 1.5
|
||||
}
|
||||
}
|
||||
"#)]
|
||||
pub surcharge_details: Option<SurchargeDetailsResponse>,
|
||||
|
||||
/// The list of eligible connectors for a given card network
|
||||
@ -313,31 +300,19 @@ pub struct ResponsePaymentMethodTypes {
|
||||
pub required_fields: Option<HashMap<String, RequiredFieldInfo>>,
|
||||
|
||||
/// surcharge details for this payment method type if exists
|
||||
#[schema(example = r#"
|
||||
{
|
||||
"surcharge": {
|
||||
"type": "rate",
|
||||
"value": {
|
||||
"percentage": 2.5
|
||||
}
|
||||
},
|
||||
"tax_on_surcharge": {
|
||||
"percentage": 1.5
|
||||
}
|
||||
}
|
||||
"#)]
|
||||
pub surcharge_details: Option<SurchargeDetailsResponse>,
|
||||
|
||||
/// auth service connector label for this payment method type, if exists
|
||||
pub pm_auth_connector: Option<String>,
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, ToSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct SurchargeDetailsResponse {
|
||||
/// surcharge value
|
||||
pub surcharge: Surcharge,
|
||||
pub surcharge: SurchargeResponse,
|
||||
/// tax on surcharge value
|
||||
pub tax_on_surcharge: Option<Percentage<SURCHARGE_PERCENTAGE_PRECISION_LENGTH>>,
|
||||
pub tax_on_surcharge: Option<SurchargePercentage>,
|
||||
/// surcharge amount for this payment
|
||||
pub display_surcharge_amount: f64,
|
||||
/// tax on surcharge amount for this payment
|
||||
@ -348,6 +323,36 @@ pub struct SurchargeDetailsResponse {
|
||||
pub display_final_amount: f64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, ToSchema)]
|
||||
#[serde(rename_all = "snake_case", tag = "type", content = "value")]
|
||||
pub enum SurchargeResponse {
|
||||
/// Fixed Surcharge value
|
||||
Fixed(i64),
|
||||
/// Surcharge percentage
|
||||
Rate(SurchargePercentage),
|
||||
}
|
||||
|
||||
impl From<Surcharge> for SurchargeResponse {
|
||||
fn from(value: Surcharge) -> Self {
|
||||
match value {
|
||||
Surcharge::Fixed(amount) => Self::Fixed(amount),
|
||||
Surcharge::Rate(percentage) => Self::Rate(percentage.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Debug, PartialEq, serde::Serialize, ToSchema)]
|
||||
pub struct SurchargePercentage {
|
||||
percentage: f32,
|
||||
}
|
||||
|
||||
impl From<Percentage<SURCHARGE_PERCENTAGE_PRECISION_LENGTH>> for SurchargePercentage {
|
||||
fn from(value: Percentage<SURCHARGE_PERCENTAGE_PRECISION_LENGTH>) -> Self {
|
||||
Self {
|
||||
percentage: value.get_percentage(),
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Required fields info used while listing the payment_method_data
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq, Eq, ToSchema, Hash)]
|
||||
pub struct RequiredFieldInfo {
|
||||
@ -716,6 +721,9 @@ pub struct CustomerPaymentMethod {
|
||||
#[schema(example = json!({"mask": "0000"}))]
|
||||
pub bank: Option<MaskedBankDetails>,
|
||||
|
||||
/// Surcharge details for this saved card
|
||||
pub surcharge_details: Option<SurchargeDetailsResponse>,
|
||||
|
||||
/// Whether this payment method requires CVV to be collected
|
||||
#[schema(example = true)]
|
||||
pub requires_cvv: bool,
|
||||
|
||||
Reference in New Issue
Block a user