mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +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:
		| @ -1,10 +1,18 @@ | ||||
| use std::{marker::PhantomData, str::FromStr}; | ||||
|  | ||||
| use api_models::enums::{DisputeStage, DisputeStatus}; | ||||
| use api_models::{ | ||||
|     enums::{DisputeStage, DisputeStatus}, | ||||
|     payment_methods::{SurchargeDetailsResponse, SurchargeMetadata}, | ||||
| }; | ||||
| #[cfg(feature = "payouts")] | ||||
| use common_utils::{crypto::Encryptable, pii::Email}; | ||||
| use common_utils::{errors::CustomResult, ext_traits::AsyncExt}; | ||||
| use common_utils::{ | ||||
|     errors::CustomResult, | ||||
|     ext_traits::{AsyncExt, Encode}, | ||||
| }; | ||||
| use error_stack::{report, IntoReport, ResultExt}; | ||||
| use euclid::enums as euclid_enums; | ||||
| use redis_interface::errors::RedisError; | ||||
| use router_env::{instrument, tracing}; | ||||
| use uuid::Uuid; | ||||
|  | ||||
| @ -1073,3 +1081,65 @@ pub fn get_flow_name<F>() -> RouterResult<String> { | ||||
|         .attach_printable("Flow stringify failed")? | ||||
|         .to_string()) | ||||
| } | ||||
|  | ||||
| pub async fn persist_individual_surcharge_details_in_redis( | ||||
|     state: &AppState, | ||||
|     merchant_account: &domain::MerchantAccount, | ||||
|     surcharge_metadata: &SurchargeMetadata, | ||||
| ) -> RouterResult<()> { | ||||
|     if !surcharge_metadata.is_empty_result() { | ||||
|         let redis_conn = state | ||||
|             .store | ||||
|             .get_redis_conn() | ||||
|             .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|             .attach_printable("Failed to get redis connection")?; | ||||
|         let redis_key = SurchargeMetadata::get_surcharge_metadata_redis_key( | ||||
|             &surcharge_metadata.payment_attempt_id, | ||||
|         ); | ||||
|  | ||||
|         let mut value_list = Vec::with_capacity(surcharge_metadata.get_surcharge_results_size()); | ||||
|         for (key, value) in surcharge_metadata | ||||
|             .get_individual_surcharge_key_value_pairs() | ||||
|             .into_iter() | ||||
|         { | ||||
|             value_list.push(( | ||||
|                 key, | ||||
|                 Encode::<SurchargeDetailsResponse>::encode_to_string_of_json(&value) | ||||
|                     .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|                     .attach_printable("Failed to encode to string of json")?, | ||||
|             )); | ||||
|         } | ||||
|         let intent_fulfillment_time = merchant_account | ||||
|             .intent_fulfillment_time | ||||
|             .unwrap_or(consts::DEFAULT_FULFILLMENT_TIME); | ||||
|         redis_conn | ||||
|             .set_hash_fields(&redis_key, value_list, Some(intent_fulfillment_time)) | ||||
|             .await | ||||
|             .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|             .attach_printable("Failed to write to redis")?; | ||||
|     } | ||||
|     Ok(()) | ||||
| } | ||||
|  | ||||
| pub async fn get_individual_surcharge_detail_from_redis( | ||||
|     state: &AppState, | ||||
|     payment_method: &euclid_enums::PaymentMethod, | ||||
|     payment_method_type: &euclid_enums::PaymentMethodType, | ||||
|     card_network: Option<euclid_enums::CardNetwork>, | ||||
|     payment_attempt_id: &str, | ||||
| ) -> CustomResult<SurchargeDetailsResponse, RedisError> { | ||||
|     let redis_conn = state | ||||
|         .store | ||||
|         .get_redis_conn() | ||||
|         .attach_printable("Failed to get redis connection")?; | ||||
|     let redis_key = SurchargeMetadata::get_surcharge_metadata_redis_key(payment_attempt_id); | ||||
|     let value_key = SurchargeMetadata::get_surcharge_details_redis_hashset_key( | ||||
|         payment_method, | ||||
|         payment_method_type, | ||||
|         card_network.as_ref(), | ||||
|     ); | ||||
|  | ||||
|     redis_conn | ||||
|         .get_hash_field_and_deserialize(&redis_key, &value_key, "SurchargeDetailsResponse") | ||||
|         .await | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Hrithikesh
					Hrithikesh