Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(core): Add outgoing webhook for manual `partial_capture` events (#3388)
Sakil Mostakd5e9866b522b
diff --git a/crates/router/src/utils.rs b/crates/router/src/utils.rsindex aaa145099e..68909d1127 100644--- a/crates/router/src/utils.rs+++ b/crates/router/src/utils.rs@@ -51,7 +51,7 @@ use crate::{types::{encrypt_optional, AsyncLift},},storage,- transformers::{ForeignTryFrom, ForeignTryInto},+ transformers::ForeignFrom,},};@@ -681,23 +681,6 @@ pub fn add_apple_pay_payment_status_metrics(}}-impl ForeignTryFrom<enums::IntentStatus> for enums::EventType {- type Error = errors::ValidationError;-- fn foreign_try_from(value: enums::IntentStatus) -> Result<Self, Self::Error> {- match value {- enums::IntentStatus::Succeeded => Ok(Self::PaymentSucceeded),- enums::IntentStatus::Failed => Ok(Self::PaymentFailed),- enums::IntentStatus::Processing => Ok(Self::PaymentProcessing),- enums::IntentStatus::RequiresMerchantAction- | enums::IntentStatus::RequiresCustomerAction => Ok(Self::ActionRequired),- _ => Err(errors::ValidationError::IncorrectValueProvided {- field_name: "intent_status",- }),- }- }-}-pub async fn trigger_payments_webhook<F, Req, Op>(merchant_account: domain::MerchantAccount,business_profile: diesel_models::business_profile::BusinessProfile,@@ -726,7 +709,9 @@ whereif matches!(status,- enums::IntentStatus::Succeeded | enums::IntentStatus::Failed+ enums::IntentStatus::Succeeded+ | enums::IntentStatus::Failed+ | enums::IntentStatus::PartiallyCaptured) {let payments_response = crate::core::payments::transformers::payments_to_payments_response(req,@@ -742,11 +727,7 @@ whereNone,)?;- let event_type: enums::EventType = status- .foreign_try_into()- .into_report()- .change_context(errors::ApiErrorResponse::WebhookProcessingFailure)- .attach_printable("payment event type mapping failed")?;+ let event_type = ForeignFrom::foreign_from(status);if let services::ApplicationResponse::JsonWithHeaders((payments_response_json, _)) =payments_response@@ -755,27 +736,34 @@ where// This spawns this futures in a background thread, the exception inside this future won't affect// the current thread and the lifecycle of spawn thread is not handled by runtime.// So when server shutdown won't wait for this thread's completion.- tokio::spawn(- async move {- Box::pin(- webhooks_core::create_event_and_trigger_appropriate_outgoing_webhook(- m_state,- merchant_account,- business_profile,- event_type,- diesel_models::enums::EventClass::Payments,- None,- payment_id,- diesel_models::enums::EventObjectType::PaymentDetails,- webhooks::OutgoingWebhookContent::PaymentDetails(- payments_response_json,++ if let Some(event_type) = event_type {+ tokio::spawn(+ async move {+ Box::pin(+ webhooks_core::create_event_and_trigger_appropriate_outgoing_webhook(+ m_state,+ merchant_account,+ business_profile,+ event_type,+ diesel_models::enums::EventClass::Payments,+ None,+ payment_id,+ diesel_models::enums::EventObjectType::PaymentDetails,+ webhooks::OutgoingWebhookContent::PaymentDetails(+ payments_response_json,+ ),),- ),- )- .await- }- .in_current_span(),- );+ )+ .await+ }+ .in_current_span(),+ );+ } else {+ logger::warn!(+ "Outgoing webhook not sent because of missing event type status mapping"+ );+ }}}