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 new payments webhook events (#3212)
Hrithikeshe0e28b87c064
diff --git a/crates/api_models/src/webhooks.rs b/crates/api_models/src/webhooks.rsindex bc8e75f6d4..7b3564732b 100644--- a/crates/api_models/src/webhooks.rs+++ b/crates/api_models/src/webhooks.rs@@ -8,11 +8,18 @@ use crate::{disputes, enums as api_enums, mandates, payments, refunds};#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Copy)]#[serde(rename_all = "snake_case")]pub enum IncomingWebhookEvent {+ /// Authorization + Capture successPaymentIntentFailure,+ /// Authorization + Capture failurePaymentIntentSuccess,PaymentIntentProcessing,PaymentIntentPartiallyFunded,PaymentIntentCancelled,+ PaymentIntentCancelFailure,+ PaymentIntentAuthorizationSuccess,+ PaymentIntentAuthorizationFailure,+ PaymentIntentCaptureSuccess,+ PaymentIntentCaptureFailure,PaymentActionRequired,EventNotSupported,SourceChargeable,@@ -86,7 +93,12 @@ impl From<IncomingWebhookEvent> for WebhookFlow {| IncomingWebhookEvent::PaymentIntentProcessing| IncomingWebhookEvent::PaymentActionRequired| IncomingWebhookEvent::PaymentIntentPartiallyFunded- | IncomingWebhookEvent::PaymentIntentCancelled => Self::Payment,+ | IncomingWebhookEvent::PaymentIntentCancelled+ | IncomingWebhookEvent::PaymentIntentCancelFailure+ | IncomingWebhookEvent::PaymentIntentAuthorizationSuccess+ | IncomingWebhookEvent::PaymentIntentAuthorizationFailure+ | IncomingWebhookEvent::PaymentIntentCaptureSuccess+ | IncomingWebhookEvent::PaymentIntentCaptureFailure => Self::Payment,IncomingWebhookEvent::EventNotSupported => Self::ReturnResponse,IncomingWebhookEvent::RefundSuccess | IncomingWebhookEvent::RefundFailure => {Self::Refunddiff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rsindex 0c4b9720ca..3af1c0e826 100644--- a/crates/common_enums/src/enums.rs+++ b/crates/common_enums/src/enums.rs@@ -921,10 +921,14 @@ impl Currency {#[serde(rename_all = "snake_case")]#[strum(serialize_all = "snake_case")]pub enum EventType {+ /// Authorize + Capture successPaymentSucceeded,+ /// Authorize + Capture failedPaymentFailed,PaymentProcessing,PaymentCancelled,+ PaymentAuthorized,+ PaymentCaptured,ActionRequired,RefundSucceeded,RefundFailed,diff --git a/crates/router/src/compatibility/stripe/webhooks.rs b/crates/router/src/compatibility/stripe/webhooks.rsindex c44e265a96..807278e0af 100644--- a/crates/router/src/compatibility/stripe/webhooks.rs+++ b/crates/router/src/compatibility/stripe/webhooks.rs@@ -183,6 +183,13 @@ fn get_stripe_event_type(event_type: api_models::enums::EventType) -> &'static sapi_models::enums::EventType::DisputeLost => "dispute.lost",api_models::enums::EventType::MandateActive => "mandate.active",api_models::enums::EventType::MandateRevoked => "mandate.revoked",++ // as per this doc https://stripe.com/docs/api/events/types#event_types-payment_intent.amount_capturable_updated+ api_models::enums::EventType::PaymentAuthorized => {+ "payment_intent.amount_capturable_updated"+ }+ // stripe treats partially captured payments as succeeded.+ api_models::enums::EventType::PaymentCaptured => "payment_intent.succeeded",}}diff --git a/crates/router/src/connector/nmi.rs b/crates/router/src/connector/nmi.rsindex d514eefb10..0550908649 100644--- a/crates/router/src/connector/nmi.rs+++ b/crates/router/src/connector/nmi.rs@@ -873,6 +873,21 @@ impl api::IncomingWebhook for Nmi {reference_body.event_body.order_id,),),+ nmi::NmiActionType::Auth => api_models::webhooks::ObjectReferenceId::PaymentId(+ api_models::payments::PaymentIdType::PaymentAttemptId(+ reference_body.event_body.order_id,+ ),+ ),+ nmi::NmiActionType::Capture => api_models::webhooks::ObjectReferenceId::PaymentId(+ api_models::payments::PaymentIdType::PaymentAttemptId(+ reference_body.event_body.order_id,+ ),+ ),+ nmi::NmiActionType::Void => api_models::webhooks::ObjectReferenceId::PaymentId(+ api_models::payments::PaymentIdType::PaymentAttemptId(+ reference_body.event_body.order_id,+ ),+ ),nmi::NmiActionType::Refund => api_models::webhooks::ObjectReferenceId::RefundId(api_models::webhooks::RefundIdType::RefundId(reference_body.event_body.order_id),),diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rsindex 677bf303d9..fcf35bfbe3 100644--- a/crates/router/src/connector/nmi/transformers.rs+++ b/crates/router/src/connector/nmi/transformers.rs@@ -1166,21 +1166,19 @@ pub enum NmiWebhookEventType {impl ForeignFrom<NmiWebhookEventType> for webhooks::IncomingWebhookEvent {fn foreign_from(status: NmiWebhookEventType) -> Self {match status {- NmiWebhookEventType::SaleSuccess | NmiWebhookEventType::CaptureSuccess => {- Self::PaymentIntentSuccess- }- NmiWebhookEventType::SaleFailure | NmiWebhookEventType::CaptureFailure => {- Self::PaymentIntentFailure- }+ NmiWebhookEventType::SaleSuccess => Self::PaymentIntentSuccess,+ NmiWebhookEventType::SaleFailure => Self::PaymentIntentFailure,NmiWebhookEventType::RefundSuccess => Self::RefundSuccess,NmiWebhookEventType::RefundFailure => Self::RefundFailure,NmiWebhookEventType::VoidSuccess => Self::PaymentIntentCancelled,+ NmiWebhookEventType::AuthSuccess => Self::PaymentIntentAuthorizationSuccess,+ NmiWebhookEventType::CaptureSuccess => Self::PaymentIntentCaptureSuccess,+ NmiWebhookEventType::AuthFailure => Self::PaymentIntentAuthorizationFailure,+ NmiWebhookEventType::CaptureFailure => Self::PaymentIntentCaptureFailure,+ NmiWebhookEventType::VoidFailure => Self::PaymentIntentCancelFailure,NmiWebhookEventType::SaleUnknown| NmiWebhookEventType::RefundUnknown- | NmiWebhookEventType::AuthSuccess- | NmiWebhookEventType::AuthFailure| NmiWebhookEventType::AuthUnknown- | NmiWebhookEventType::VoidFailure| NmiWebhookEventType::VoidUnknown| NmiWebhookEventType::CaptureUnknown => Self::EventNotSupported,}diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rsindex 8c43e2c16a..c151c5af45 100644--- a/crates/router/src/connector/stripe.rs+++ b/crates/router/src/connector/stripe.rs@@ -1977,6 +1977,9 @@ impl api::IncomingWebhook for Stripe {stripe::WebhookEventType::PaymentIntentCanceled => {api::IncomingWebhookEvent::PaymentIntentCancelled}+ stripe::WebhookEventType::PaymentIntentAmountCapturableUpdated => {+ api::IncomingWebhookEvent::PaymentIntentAuthorizationSuccess+ }stripe::WebhookEventType::ChargeSucceeded => {if let Some(stripe::WebhookPaymentMethodDetails {payment_method:@@ -2033,7 +2036,6 @@ impl api::IncomingWebhook for Stripe {| stripe::WebhookEventType::ChargeRefunded| stripe::WebhookEventType::PaymentIntentCreated| stripe::WebhookEventType::PaymentIntentProcessing- | stripe::WebhookEventType::PaymentIntentAmountCapturableUpdated| stripe::WebhookEventType::SourceTransactionCreated => {api::IncomingWebhookEvent::EventNotSupported}diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rsindex 8875fdecfd..89e1869241 100644--- a/crates/router/src/connector/stripe/transformers.rs+++ b/crates/router/src/connector/stripe/transformers.rs@@ -3315,7 +3315,7 @@ pub enum WebhookEventType {PaymentIntentProcessing,#[serde(rename = "payment_intent.requires_action")]PaymentIntentRequiresAction,- #[serde(rename = "amount_capturable_updated")]+ #[serde(rename = "payment_intent.amount_capturable_updated")]PaymentIntentAmountCapturableUpdated,#[serde(rename = "source.chargeable")]SourceChargeable,diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rsindex c3818caf05..786a8c5518 100644--- a/crates/router/src/types/transformers.rs+++ b/crates/router/src/types/transformers.rs@@ -352,11 +352,15 @@ impl ForeignFrom<api_enums::IntentStatus> for Option<storage_enums::EventType> {Some(storage_enums::EventType::ActionRequired)}api_enums::IntentStatus::Cancelled => Some(storage_enums::EventType::PaymentCancelled),+ api_enums::IntentStatus::PartiallyCaptured+ | api_enums::IntentStatus::PartiallyCapturedAndCapturable => {+ Some(storage_enums::EventType::PaymentCaptured)+ }+ api_enums::IntentStatus::RequiresCapture => {+ Some(storage_enums::EventType::PaymentAuthorized)+ }api_enums::IntentStatus::RequiresPaymentMethod- | api_enums::IntentStatus::RequiresConfirmation- | api_enums::IntentStatus::RequiresCapture- | api_enums::IntentStatus::PartiallyCaptured- | api_enums::IntentStatus::PartiallyCapturedAndCapturable => None,+ | api_enums::IntentStatus::RequiresConfirmation => None,}}}diff --git a/migrations/2023-12-28-063619_add_enum_types_to_EventType/down.sql b/migrations/2023-12-28-063619_add_enum_types_to_EventType/down.sqlnew file mode 100644index 0000000000..c7c9cbeb40--- /dev/null+++ b/migrations/2023-12-28-063619_add_enum_types_to_EventType/down.sql@@ -0,0 +1,2 @@+-- This file should undo anything in `up.sql`+SELECT 1;\ No newline at end of filediff --git a/migrations/2023-12-28-063619_add_enum_types_to_EventType/up.sql b/migrations/2023-12-28-063619_add_enum_types_to_EventType/up.sqlnew file mode 100644index 0000000000..74b87199c2--- /dev/null+++ b/migrations/2023-12-28-063619_add_enum_types_to_EventType/up.sql@@ -0,0 +1,3 @@+-- Your SQL goes here+ALTER TYPE "EventType" ADD VALUE IF NOT EXISTS 'payment_authorized';+ALTER TYPE "EventType" ADD VALUE IF NOT EXISTS 'payment_captured';diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.jsonindex 4e6c69b2eb..df5b944897 100644--- a/openapi/openapi_spec.json+++ b/openapi/openapi_spec.json@@ -5556,6 +5556,8 @@"payment_failed","payment_processing","payment_cancelled",+ "payment_authorized",+ "payment_captured","action_required","refund_succeeded","refund_failed",