mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	feat(router): add connector_request_reference_id in router_data based on merchant config (#1627)
This commit is contained in:
		 Sai Harsha Vardhan
					Sai Harsha Vardhan
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							b1ae981f82
						
					
				
				
					commit
					865db9411d
				
			| @ -7,6 +7,7 @@ use router_env::{instrument, tracing}; | ||||
|  | ||||
| use super::payments::{helpers, PaymentAddress}; | ||||
| use crate::{ | ||||
|     configs::settings, | ||||
|     consts, | ||||
|     core::errors::{self, RouterResult}, | ||||
|     routes::AppState, | ||||
| @ -18,6 +19,11 @@ use crate::{ | ||||
|     utils::{generate_id, OptionExt, ValueExt}, | ||||
| }; | ||||
|  | ||||
| const IRRELEVANT_CONNECTOR_REQUEST_REFERENCE_ID_IN_DISPUTE_FLOW: &str = | ||||
|     "irrelevant_connector_request_reference_id_in_dispute_flow"; | ||||
| const IRRELEVANT_PAYMENT_ID_IN_DISPUTE_FLOW: &str = "irrelevant_payment_id_in_dispute_flow"; | ||||
| const IRRELEVANT_ATTEMPT_ID_IN_DISPUTE_FLOW: &str = "irrelevant_attempt_id_in_dispute_flow"; | ||||
|  | ||||
| #[instrument(skip_all)] | ||||
| #[allow(clippy::too_many_arguments)] | ||||
| pub async fn construct_refund_router_data<'a, F>( | ||||
| @ -107,6 +113,11 @@ pub async fn construct_refund_router_data<'a, F>( | ||||
|         payment_method_token: None, | ||||
|         connector_customer: None, | ||||
|         preprocessing_id: None, | ||||
|         connector_request_reference_id: get_connector_request_reference_id( | ||||
|             &state.conf, | ||||
|             &merchant_account.merchant_id, | ||||
|             payment_attempt, | ||||
|         ), | ||||
|     }; | ||||
|  | ||||
|     Ok(router_data) | ||||
| @ -294,6 +305,11 @@ pub async fn construct_accept_dispute_router_data<'a>( | ||||
|         connector_customer: None, | ||||
|         customer_id: None, | ||||
|         preprocessing_id: None, | ||||
|         connector_request_reference_id: get_connector_request_reference_id( | ||||
|             &state.conf, | ||||
|             &merchant_account.merchant_id, | ||||
|             payment_attempt, | ||||
|         ), | ||||
|     }; | ||||
|     Ok(router_data) | ||||
| } | ||||
| @ -355,6 +371,11 @@ pub async fn construct_submit_evidence_router_data<'a>( | ||||
|         connector_customer: None, | ||||
|         customer_id: None, | ||||
|         preprocessing_id: None, | ||||
|         connector_request_reference_id: get_connector_request_reference_id( | ||||
|             &state.conf, | ||||
|             &merchant_account.merchant_id, | ||||
|             payment_attempt, | ||||
|         ), | ||||
|     }; | ||||
|     Ok(router_data) | ||||
| } | ||||
| @ -417,6 +438,11 @@ pub async fn construct_upload_file_router_data<'a>( | ||||
|         connector_customer: None, | ||||
|         customer_id: None, | ||||
|         preprocessing_id: None, | ||||
|         connector_request_reference_id: get_connector_request_reference_id( | ||||
|             &state.conf, | ||||
|             &merchant_account.merchant_id, | ||||
|             payment_attempt, | ||||
|         ), | ||||
|     }; | ||||
|     Ok(router_data) | ||||
| } | ||||
| @ -481,6 +507,11 @@ pub async fn construct_defend_dispute_router_data<'a>( | ||||
|         customer_id: None, | ||||
|         connector_customer: None, | ||||
|         preprocessing_id: None, | ||||
|         connector_request_reference_id: get_connector_request_reference_id( | ||||
|             &state.conf, | ||||
|             &merchant_account.merchant_id, | ||||
|             payment_attempt, | ||||
|         ), | ||||
|     }; | ||||
|     Ok(router_data) | ||||
| } | ||||
| @ -517,8 +548,8 @@ pub async fn construct_retrieve_file_router_data<'a>( | ||||
|         connector: connector_id.to_string(), | ||||
|         customer_id: None, | ||||
|         connector_customer: None, | ||||
|         payment_id: "irrelevant_payment_id_in_dispute_flow".to_string(), | ||||
|         attempt_id: "irrelevant_attempt_id_in_dispute_flow".to_string(), | ||||
|         payment_id: IRRELEVANT_PAYMENT_ID_IN_DISPUTE_FLOW.to_string(), | ||||
|         attempt_id: IRRELEVANT_ATTEMPT_ID_IN_DISPUTE_FLOW.to_string(), | ||||
|         status: storage_models::enums::AttemptStatus::default(), | ||||
|         payment_method: storage_models::enums::PaymentMethod::default(), | ||||
|         connector_auth_type: auth_type, | ||||
| @ -543,6 +574,33 @@ pub async fn construct_retrieve_file_router_data<'a>( | ||||
|         reference_id: None, | ||||
|         payment_method_token: None, | ||||
|         preprocessing_id: None, | ||||
|         connector_request_reference_id: IRRELEVANT_CONNECTOR_REQUEST_REFERENCE_ID_IN_DISPUTE_FLOW | ||||
|             .to_string(), | ||||
|     }; | ||||
|     Ok(router_data) | ||||
| } | ||||
|  | ||||
| pub fn is_merchant_enabled_for_payment_id_as_connector_request_id( | ||||
|     conf: &settings::Settings, | ||||
|     merchant_id: &str, | ||||
| ) -> bool { | ||||
|     let config_map = &conf | ||||
|         .connector_request_reference_id_config | ||||
|         .merchant_ids_send_payment_id_as_connector_request_id; | ||||
|     config_map.contains(merchant_id) | ||||
| } | ||||
|  | ||||
| pub fn get_connector_request_reference_id( | ||||
|     conf: &settings::Settings, | ||||
|     merchant_id: &str, | ||||
|     payment_attempt: &storage_models::payment_attempt::PaymentAttempt, | ||||
| ) -> String { | ||||
|     let is_config_enabled_for_merchant = | ||||
|         is_merchant_enabled_for_payment_id_as_connector_request_id(conf, merchant_id); | ||||
|     // Send payment_id if config is enabled for a merchant, else send attempt_id | ||||
|     if is_config_enabled_for_merchant { | ||||
|         payment_attempt.payment_id.clone() | ||||
|     } else { | ||||
|         payment_attempt.attempt_id.clone() | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user