mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
fix: handle session and confirm flow discrepancy in surcharge details (#2696)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@ -6,7 +6,6 @@ use common_utils::{
|
||||
types::Percentage,
|
||||
};
|
||||
use serde::de;
|
||||
use serde_with::serde_as;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[cfg(feature = "payouts")]
|
||||
@ -15,7 +14,7 @@ use crate::{
|
||||
admin,
|
||||
customers::CustomerId,
|
||||
enums as api_enums,
|
||||
payments::{self, BankCodeResponse},
|
||||
payments::{self, BankCodeResponse, RequestSurchargeDetails},
|
||||
};
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
|
||||
@ -342,15 +341,85 @@ pub struct SurchargeDetailsResponse {
|
||||
pub final_amount: i64,
|
||||
}
|
||||
|
||||
#[serde_as]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
impl SurchargeDetailsResponse {
|
||||
pub fn is_request_surcharge_matching(
|
||||
&self,
|
||||
request_surcharge_details: RequestSurchargeDetails,
|
||||
) -> bool {
|
||||
request_surcharge_details.surcharge_amount == self.surcharge_amount
|
||||
&& request_surcharge_details.tax_amount.unwrap_or(0) == self.tax_on_surcharge_amount
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SurchargeMetadata {
|
||||
#[serde_as(as = "HashMap<_, _>")]
|
||||
pub surcharge_results: HashMap<String, SurchargeDetailsResponse>,
|
||||
surcharge_results: HashMap<
|
||||
(
|
||||
common_enums::PaymentMethod,
|
||||
common_enums::PaymentMethodType,
|
||||
Option<common_enums::CardNetwork>,
|
||||
),
|
||||
SurchargeDetailsResponse,
|
||||
>,
|
||||
pub payment_attempt_id: String,
|
||||
}
|
||||
|
||||
impl SurchargeMetadata {
|
||||
pub fn get_key_for_surcharge_details_hash_map(
|
||||
pub fn new(payment_attempt_id: String) -> Self {
|
||||
Self {
|
||||
surcharge_results: HashMap::new(),
|
||||
payment_attempt_id,
|
||||
}
|
||||
}
|
||||
pub fn is_empty_result(&self) -> bool {
|
||||
self.surcharge_results.is_empty()
|
||||
}
|
||||
pub fn get_surcharge_results_size(&self) -> usize {
|
||||
self.surcharge_results.len()
|
||||
}
|
||||
pub fn insert_surcharge_details(
|
||||
&mut self,
|
||||
payment_method: &common_enums::PaymentMethod,
|
||||
payment_method_type: &common_enums::PaymentMethodType,
|
||||
card_network: Option<&common_enums::CardNetwork>,
|
||||
surcharge_details: SurchargeDetailsResponse,
|
||||
) {
|
||||
let key = (
|
||||
payment_method.to_owned(),
|
||||
payment_method_type.to_owned(),
|
||||
card_network.cloned(),
|
||||
);
|
||||
self.surcharge_results.insert(key, surcharge_details);
|
||||
}
|
||||
pub fn get_surcharge_details(
|
||||
&self,
|
||||
payment_method: &common_enums::PaymentMethod,
|
||||
payment_method_type: &common_enums::PaymentMethodType,
|
||||
card_network: Option<&common_enums::CardNetwork>,
|
||||
) -> Option<&SurchargeDetailsResponse> {
|
||||
let key = &(
|
||||
payment_method.to_owned(),
|
||||
payment_method_type.to_owned(),
|
||||
card_network.cloned(),
|
||||
);
|
||||
self.surcharge_results.get(key)
|
||||
}
|
||||
pub fn get_surcharge_metadata_redis_key(payment_attempt_id: &str) -> String {
|
||||
format!("surcharge_metadata_{}", payment_attempt_id)
|
||||
}
|
||||
pub fn get_individual_surcharge_key_value_pairs(
|
||||
&self,
|
||||
) -> Vec<(String, SurchargeDetailsResponse)> {
|
||||
self.surcharge_results
|
||||
.iter()
|
||||
.map(|((pm, pmt, card_network), surcharge_details)| {
|
||||
let key =
|
||||
Self::get_surcharge_details_redis_hashset_key(pm, pmt, card_network.as_ref());
|
||||
(key, surcharge_details.to_owned())
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
pub fn get_surcharge_details_redis_hashset_key(
|
||||
payment_method: &common_enums::PaymentMethod,
|
||||
payment_method_type: &common_enums::PaymentMethodType,
|
||||
card_network: Option<&common_enums::CardNetwork>,
|
||||
|
||||
Reference in New Issue
Block a user