Skip to content

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

feat(router): Add Cancel Event in Webhooks and Mapping it in Stripe (#2573)

DEEPANSHU BANSAL92f7918e6f98
diff --git a/crates/api_models/src/webhooks.rs b/crates/api_models/src/webhooks.rs
index da5d8a6567..bc8e75f6d4 100644
--- a/crates/api_models/src/webhooks.rs
+++ b/crates/api_models/src/webhooks.rs
@@ -12,6 +12,7 @@ pub enum IncomingWebhookEvent {
PaymentIntentSuccess,
PaymentIntentProcessing,
PaymentIntentPartiallyFunded,
+ PaymentIntentCancelled,
PaymentActionRequired,
EventNotSupported,
SourceChargeable,
@@ -84,7 +85,8 @@ impl From<IncomingWebhookEvent> for WebhookFlow {
| IncomingWebhookEvent::PaymentIntentSuccess
| IncomingWebhookEvent::PaymentIntentProcessing
| IncomingWebhookEvent::PaymentActionRequired
- | IncomingWebhookEvent::PaymentIntentPartiallyFunded => Self::Payment,
+ | IncomingWebhookEvent::PaymentIntentPartiallyFunded
+ | IncomingWebhookEvent::PaymentIntentCancelled => Self::Payment,
IncomingWebhookEvent::EventNotSupported => Self::ReturnResponse,
IncomingWebhookEvent::RefundSuccess | IncomingWebhookEvent::RefundFailure => {
Self::Refund
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs
index 39e1848396..a44725bc91 100644
--- a/crates/common_enums/src/enums.rs
+++ b/crates/common_enums/src/enums.rs
@@ -794,6 +794,7 @@ pub enum EventType {
PaymentSucceeded,
PaymentFailed,
PaymentProcessing,
+ PaymentCancelled,
ActionRequired,
RefundSucceeded,
RefundFailed,
diff --git a/crates/router/src/compatibility/stripe/webhooks.rs b/crates/router/src/compatibility/stripe/webhooks.rs
index 1b5f8969d5..c44e265a96 100644
--- a/crates/router/src/compatibility/stripe/webhooks.rs
+++ b/crates/router/src/compatibility/stripe/webhooks.rs
@@ -168,6 +168,7 @@ fn get_stripe_event_type(event_type: api_models::enums::EventType) -> &'static s
api_models::enums::EventType::PaymentSucceeded => "payment_intent.succeeded",
api_models::enums::EventType::PaymentFailed => "payment_intent.payment_failed",
api_models::enums::EventType::PaymentProcessing => "payment_intent.processing",
+ api_models::enums::EventType::PaymentCancelled => "payment_intent.canceled",
// the below are not really stripe compatible because stripe doesn't provide this
api_models::enums::EventType::ActionRequired => "action.required",
diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rs
index ff89882543..59700ecf35 100644
--- a/crates/router/src/connector/stripe.rs
+++ b/crates/router/src/connector/stripe.rs
@@ -1844,6 +1844,9 @@ impl api::IncomingWebhook for Stripe {
stripe::WebhookEventType::PaymentIntentSucceed => {
api::IncomingWebhookEvent::PaymentIntentSuccess
}
+ stripe::WebhookEventType::PaymentIntentCanceled => {
+ api::IncomingWebhookEvent::PaymentIntentCancelled
+ }
stripe::WebhookEventType::ChargeSucceeded => {
if let Some(stripe::WebhookPaymentMethodDetails {
payment_method:
@@ -1898,7 +1901,6 @@ impl api::IncomingWebhook for Stripe {
| stripe::WebhookEventType::ChargePending
| stripe::WebhookEventType::ChargeUpdated
| stripe::WebhookEventType::ChargeRefunded
- | stripe::WebhookEventType::PaymentIntentCanceled
| stripe::WebhookEventType::PaymentIntentCreated
| stripe::WebhookEventType::PaymentIntentProcessing
| stripe::WebhookEventType::PaymentIntentAmountCapturableUpdated
diff --git a/crates/router/src/core/webhooks/utils.rs b/crates/router/src/core/webhooks/utils.rs
index ac7e5081c8..b187001e10 100644
--- a/crates/router/src/core/webhooks/utils.rs
+++ b/crates/router/src/core/webhooks/utils.rs
@@ -17,6 +17,7 @@ fn default_webhook_config() -> api::MerchantWebhookConfig {
api::IncomingWebhookEvent::PaymentIntentSuccess,
api::IncomingWebhookEvent::PaymentIntentFailure,
api::IncomingWebhookEvent::PaymentIntentProcessing,
+ api::IncomingWebhookEvent::PaymentIntentCancelled,
api::IncomingWebhookEvent::PaymentActionRequired,
api::IncomingWebhookEvent::RefundSuccess,
])
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index 8686729ea2..31ec31cfa9 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -257,8 +257,8 @@ impl ForeignFrom<api_enums::IntentStatus> for Option<storage_enums::EventType> {
| api_enums::IntentStatus::RequiresCustomerAction => {
Some(storage_enums::EventType::ActionRequired)
}
- api_enums::IntentStatus::Cancelled
- | api_enums::IntentStatus::RequiresPaymentMethod
+ api_enums::IntentStatus::Cancelled => Some(storage_enums::EventType::PaymentCancelled),
+ api_enums::IntentStatus::RequiresPaymentMethod
| api_enums::IntentStatus::RequiresConfirmation
| api_enums::IntentStatus::RequiresCapture
| api_enums::IntentStatus::PartiallyCaptured => None,
diff --git a/migrations/2023-10-13-100447_add-payment-cancelled-event-type/down.sql b/migrations/2023-10-13-100447_add-payment-cancelled-event-type/down.sql
new file mode 100644
index 0000000000..87e4e81e04
--- /dev/null
+++ b/migrations/2023-10-13-100447_add-payment-cancelled-event-type/down.sql
@@ -0,0 +1,2 @@
+-- This file should undo anything in `up.sql`
+Select 1;
\ No newline at end of file
diff --git a/migrations/2023-10-13-100447_add-payment-cancelled-event-type/up.sql b/migrations/2023-10-13-100447_add-payment-cancelled-event-type/up.sql
new file mode 100644
index 0000000000..5854491a6e
--- /dev/null
+++ b/migrations/2023-10-13-100447_add-payment-cancelled-event-type/up.sql
@@ -0,0 +1,2 @@
+-- Your SQL goes here
+ALTER TYPE "EventType" ADD VALUE 'payment_cancelled';
\ No newline at end of file
diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json
index 971a573b8e..3f1f168033 100644
--- a/openapi/openapi_spec.json
+++ b/openapi/openapi_spec.json
@@ -5076,6 +5076,7 @@
"payment_succeeded",
"payment_failed",
"payment_processing",
+ "payment_cancelled",
"action_required",
"refund_succeeded",
"refund_failed",