mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	refactor: use business profile domain models instead of diesel models (#5566)
This commit is contained in:
		| @ -48,7 +48,7 @@ const OUTGOING_WEBHOOK_TIMEOUT_SECS: u64 = 5; | ||||
| pub(crate) async fn create_event_and_trigger_outgoing_webhook( | ||||
|     state: SessionState, | ||||
|     merchant_account: domain::MerchantAccount, | ||||
|     business_profile: diesel_models::business_profile::BusinessProfile, | ||||
|     business_profile: domain::BusinessProfile, | ||||
|     merchant_key_store: &domain::MerchantKeyStore, | ||||
|     event_type: enums::EventType, | ||||
|     event_class: enums::EventClass, | ||||
| @ -87,16 +87,10 @@ pub(crate) async fn create_event_and_trigger_outgoing_webhook( | ||||
|         timestamp: now, | ||||
|     }; | ||||
|  | ||||
|     let request_content = get_outgoing_webhook_request( | ||||
|         &state, | ||||
|         &merchant_account, | ||||
|         outgoing_webhook, | ||||
|         &business_profile, | ||||
|         merchant_key_store, | ||||
|     ) | ||||
|     .await | ||||
|     .change_context(errors::ApiErrorResponse::WebhookProcessingFailure) | ||||
|     .attach_printable("Failed to construct outgoing webhook request content")?; | ||||
|     let request_content = | ||||
|         get_outgoing_webhook_request(&merchant_account, outgoing_webhook, &business_profile) | ||||
|             .change_context(errors::ApiErrorResponse::WebhookProcessingFailure) | ||||
|             .attach_printable("Failed to construct outgoing webhook request content")?; | ||||
|  | ||||
|     let event_metadata = storage::EventMetadata::foreign_from((&content, &primary_object_id)); | ||||
|     let key_manager_state = &(&state).into(); | ||||
| @ -199,7 +193,7 @@ pub(crate) async fn create_event_and_trigger_outgoing_webhook( | ||||
| #[instrument(skip_all)] | ||||
| pub(crate) async fn trigger_webhook_and_raise_event( | ||||
|     state: SessionState, | ||||
|     business_profile: diesel_models::business_profile::BusinessProfile, | ||||
|     business_profile: domain::BusinessProfile, | ||||
|     merchant_key_store: &domain::MerchantKeyStore, | ||||
|     event: domain::Event, | ||||
|     request_content: OutgoingWebhookRequestContent, | ||||
| @ -231,7 +225,7 @@ pub(crate) async fn trigger_webhook_and_raise_event( | ||||
|  | ||||
| async fn trigger_webhook_to_merchant( | ||||
|     state: SessionState, | ||||
|     business_profile: diesel_models::business_profile::BusinessProfile, | ||||
|     business_profile: domain::BusinessProfile, | ||||
|     merchant_key_store: &domain::MerchantKeyStore, | ||||
|     event: domain::Event, | ||||
|     request_content: OutgoingWebhookRequestContent, | ||||
| @ -475,7 +469,7 @@ fn raise_webhooks_analytics_event( | ||||
|  | ||||
| pub(crate) async fn add_outgoing_webhook_retry_task_to_process_tracker( | ||||
|     db: &dyn StorageInterface, | ||||
|     business_profile: &diesel_models::business_profile::BusinessProfile, | ||||
|     business_profile: &domain::BusinessProfile, | ||||
|     event: &domain::Event, | ||||
| ) -> CustomResult<storage::ProcessTracker, errors::StorageError> { | ||||
|     let schedule_time = outgoing_webhook_retry::get_webhook_delivery_retry_schedule_time( | ||||
| @ -539,7 +533,7 @@ pub(crate) async fn add_outgoing_webhook_retry_task_to_process_tracker( | ||||
| } | ||||
|  | ||||
| fn get_webhook_url_from_business_profile( | ||||
|     business_profile: &diesel_models::business_profile::BusinessProfile, | ||||
|     business_profile: &domain::BusinessProfile, | ||||
| ) -> CustomResult<String, errors::WebhooksFlowError> { | ||||
|     let webhook_details = business_profile | ||||
|         .webhook_details | ||||
| @ -554,19 +548,15 @@ fn get_webhook_url_from_business_profile( | ||||
|         .map(ExposeInterface::expose) | ||||
| } | ||||
|  | ||||
| pub(crate) async fn get_outgoing_webhook_request( | ||||
|     state: &SessionState, | ||||
| pub(crate) fn get_outgoing_webhook_request( | ||||
|     merchant_account: &domain::MerchantAccount, | ||||
|     outgoing_webhook: api::OutgoingWebhook, | ||||
|     business_profile: &diesel_models::business_profile::BusinessProfile, | ||||
|     key_store: &domain::MerchantKeyStore, | ||||
|     business_profile: &domain::BusinessProfile, | ||||
| ) -> CustomResult<OutgoingWebhookRequestContent, errors::WebhooksFlowError> { | ||||
|     #[inline] | ||||
|     async fn get_outgoing_webhook_request_inner<WebhookType: types::OutgoingWebhookType>( | ||||
|         state: &SessionState, | ||||
|     fn get_outgoing_webhook_request_inner<WebhookType: types::OutgoingWebhookType>( | ||||
|         outgoing_webhook: api::OutgoingWebhook, | ||||
|         business_profile: &diesel_models::business_profile::BusinessProfile, | ||||
|         key_store: &domain::MerchantKeyStore, | ||||
|         business_profile: &domain::BusinessProfile, | ||||
|     ) -> CustomResult<OutgoingWebhookRequestContent, errors::WebhooksFlowError> { | ||||
|         let mut headers = vec![( | ||||
|             reqwest::header::CONTENT_TYPE.to_string(), | ||||
| @ -575,30 +565,18 @@ pub(crate) async fn get_outgoing_webhook_request( | ||||
|  | ||||
|         let transformed_outgoing_webhook = WebhookType::from(outgoing_webhook); | ||||
|         let payment_response_hash_key = business_profile.payment_response_hash_key.clone(); | ||||
|         let custom_headers = crypto_operation::<serde_json::Value, masking::WithType>( | ||||
|             &state.into(), | ||||
|             type_name!(domain::Event), | ||||
|             CryptoOperation::DecryptOptional( | ||||
|                 business_profile | ||||
|                     .outgoing_webhook_custom_http_headers | ||||
|                     .clone(), | ||||
|             ), | ||||
|             Identifier::Merchant(key_store.merchant_id.clone()), | ||||
|             key_store.key.get_inner().peek(), | ||||
|         ) | ||||
|         .await | ||||
|         .and_then(|val| val.try_into_optionaloperation()) | ||||
|         .change_context(errors::WebhooksFlowError::OutgoingWebhookEncodingFailed) | ||||
|         .attach_printable("Failed to decrypt outgoing webhook custom HTTP headers")? | ||||
|         .map(|decrypted_value| { | ||||
|             decrypted_value | ||||
|                 .into_inner() | ||||
|                 .expose() | ||||
|                 .parse_value::<HashMap<String, String>>("HashMap<String,String>") | ||||
|                 .change_context(errors::WebhooksFlowError::OutgoingWebhookEncodingFailed) | ||||
|                 .attach_printable("Failed to deserialize outgoing webhook custom HTTP headers") | ||||
|         }) | ||||
|         .transpose()?; | ||||
|         let custom_headers = business_profile | ||||
|             .outgoing_webhook_custom_http_headers | ||||
|             .clone() | ||||
|             .map(|headers| { | ||||
|                 headers | ||||
|                     .into_inner() | ||||
|                     .expose() | ||||
|                     .parse_value::<HashMap<String, String>>("HashMap<String,String>") | ||||
|                     .change_context(errors::WebhooksFlowError::OutgoingWebhookEncodingFailed) | ||||
|                     .attach_printable("Failed to deserialize outgoing webhook custom HTTP headers") | ||||
|             }) | ||||
|             .transpose()?; | ||||
|         if let Some(ref map) = custom_headers { | ||||
|             headers.extend( | ||||
|                 map.iter() | ||||
| @ -623,24 +601,13 @@ pub(crate) async fn get_outgoing_webhook_request( | ||||
|  | ||||
|     match merchant_account.get_compatible_connector() { | ||||
|         #[cfg(feature = "stripe")] | ||||
|         Some(api_models::enums::Connector::Stripe) => { | ||||
|             get_outgoing_webhook_request_inner::<stripe_webhooks::StripeOutgoingWebhook>( | ||||
|                 state, | ||||
|                 outgoing_webhook, | ||||
|                 business_profile, | ||||
|                 key_store, | ||||
|             ) | ||||
|             .await | ||||
|         } | ||||
|         _ => { | ||||
|             get_outgoing_webhook_request_inner::<webhooks::OutgoingWebhook>( | ||||
|                 state, | ||||
|                 outgoing_webhook, | ||||
|                 business_profile, | ||||
|                 key_store, | ||||
|             ) | ||||
|             .await | ||||
|         } | ||||
|         Some(api_models::enums::Connector::Stripe) => get_outgoing_webhook_request_inner::< | ||||
|             stripe_webhooks::StripeOutgoingWebhook, | ||||
|         >(outgoing_webhook, business_profile), | ||||
|         _ => get_outgoing_webhook_request_inner::<webhooks::OutgoingWebhook>( | ||||
|             outgoing_webhook, | ||||
|             business_profile, | ||||
|         ), | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Sanchith Hegde
					Sanchith Hegde