mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	feat(router): add outgoing payment webhooks for v2 (#6613)
Co-authored-by: Narayan Bhat <narayan.bhat@juspay.in> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: hrithikesh026 <hrithikesh.vm@juspay.in> Co-authored-by: Aishwariyaa Anand <124241367+Aishwariyaa-Anand@users.noreply.github.com> Co-authored-by: Aishwariyaa Anand <aishwariyaa.anand@Aishwariyaa-Anand-C3PGW02T6Y.local>
This commit is contained in:
		 Sai Harsha Vardhan
					Sai Harsha Vardhan
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							67f38f864e
						
					
				
				
					commit
					aa6ebf8aef
				
			| @ -1,13 +1,15 @@ | ||||
| use std::marker::PhantomData; | ||||
|  | ||||
| use common_utils::{errors::CustomResult, ext_traits::ValueExt}; | ||||
| use error_stack::ResultExt; | ||||
| use error_stack::{Report, ResultExt}; | ||||
| use redis_interface as redis; | ||||
| use router_env::tracing; | ||||
|  | ||||
| use super::MERCHANT_ID; | ||||
| use crate::{ | ||||
|     core::{ | ||||
|         errors::{self}, | ||||
|         metrics, | ||||
|         payments::helpers, | ||||
|     }, | ||||
|     db::{get_and_deserialize_key, StorageInterface}, | ||||
| @ -159,6 +161,43 @@ pub(crate) fn generate_event_id() -> String { | ||||
|     common_utils::generate_time_ordered_id("evt") | ||||
| } | ||||
|  | ||||
| pub fn increment_webhook_outgoing_received_count(merchant_id: &common_utils::id_type::MerchantId) { | ||||
|     metrics::WEBHOOK_OUTGOING_RECEIVED_COUNT.add( | ||||
|         1, | ||||
|         router_env::metric_attributes!((MERCHANT_ID, merchant_id.clone())), | ||||
|     ) | ||||
| } | ||||
|  | ||||
| pub fn increment_webhook_outgoing_not_received_count( | ||||
|     merchant_id: &common_utils::id_type::MerchantId, | ||||
| ) { | ||||
|     metrics::WEBHOOK_OUTGOING_NOT_RECEIVED_COUNT.add( | ||||
|         1, | ||||
|         router_env::metric_attributes!((MERCHANT_ID, merchant_id.clone())), | ||||
|     ); | ||||
| } | ||||
|  | ||||
| pub fn is_outgoing_webhook_disabled( | ||||
|     state: &SessionState, | ||||
|     webhook_url_result: &Result<String, Report<errors::WebhooksFlowError>>, | ||||
|     business_profile: &domain::Profile, | ||||
|     idempotent_event_id: &str, | ||||
| ) -> bool { | ||||
|     if !state.conf.webhooks.outgoing_enabled | ||||
|         || webhook_url_result.is_err() | ||||
|         || webhook_url_result.as_ref().is_ok_and(String::is_empty) | ||||
|     { | ||||
|         logger::debug!( | ||||
|             business_profile_id=?business_profile.get_id(), | ||||
|             %idempotent_event_id, | ||||
|             "Outgoing webhooks are disabled in application configuration, or merchant webhook URL \ | ||||
|              could not be obtained; skipping outgoing webhooks for event" | ||||
|         ); | ||||
|         return true; | ||||
|     } | ||||
|     false | ||||
| } | ||||
|  | ||||
| const WEBHOOK_LOCK_PREFIX: &str = "WEBHOOK_LOCK"; | ||||
|  | ||||
| pub(super) async fn perform_redis_lock<A>( | ||||
|  | ||||
		Reference in New Issue
	
	Block a user