Skip to content

Commit 92f7918

Browse files
feat(router): Add Cancel Event in Webhooks and Mapping it in Stripe (#2573)
1 parent d401975 commit 92f7918

File tree

9 files changed

+16
-4
lines changed

9 files changed

+16
-4
lines changed

crates/api_models/src/webhooks.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub enum IncomingWebhookEvent {
1212
PaymentIntentSuccess,
1313
PaymentIntentProcessing,
1414
PaymentIntentPartiallyFunded,
15+
PaymentIntentCancelled,
1516
PaymentActionRequired,
1617
EventNotSupported,
1718
SourceChargeable,
@@ -84,7 +85,8 @@ impl From<IncomingWebhookEvent> for WebhookFlow {
8485
| IncomingWebhookEvent::PaymentIntentSuccess
8586
| IncomingWebhookEvent::PaymentIntentProcessing
8687
| IncomingWebhookEvent::PaymentActionRequired
87-
| IncomingWebhookEvent::PaymentIntentPartiallyFunded => Self::Payment,
88+
| IncomingWebhookEvent::PaymentIntentPartiallyFunded
89+
| IncomingWebhookEvent::PaymentIntentCancelled => Self::Payment,
8890
IncomingWebhookEvent::EventNotSupported => Self::ReturnResponse,
8991
IncomingWebhookEvent::RefundSuccess | IncomingWebhookEvent::RefundFailure => {
9092
Self::Refund

crates/common_enums/src/enums.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ pub enum EventType {
794794
PaymentSucceeded,
795795
PaymentFailed,
796796
PaymentProcessing,
797+
PaymentCancelled,
797798
ActionRequired,
798799
RefundSucceeded,
799800
RefundFailed,

crates/router/src/compatibility/stripe/webhooks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ fn get_stripe_event_type(event_type: api_models::enums::EventType) -> &'static s
168168
api_models::enums::EventType::PaymentSucceeded => "payment_intent.succeeded",
169169
api_models::enums::EventType::PaymentFailed => "payment_intent.payment_failed",
170170
api_models::enums::EventType::PaymentProcessing => "payment_intent.processing",
171+
api_models::enums::EventType::PaymentCancelled => "payment_intent.canceled",
171172

172173
// the below are not really stripe compatible because stripe doesn't provide this
173174
api_models::enums::EventType::ActionRequired => "action.required",

crates/router/src/connector/stripe.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,9 @@ impl api::IncomingWebhook for Stripe {
18441844
stripe::WebhookEventType::PaymentIntentSucceed => {
18451845
api::IncomingWebhookEvent::PaymentIntentSuccess
18461846
}
1847+
stripe::WebhookEventType::PaymentIntentCanceled => {
1848+
api::IncomingWebhookEvent::PaymentIntentCancelled
1849+
}
18471850
stripe::WebhookEventType::ChargeSucceeded => {
18481851
if let Some(stripe::WebhookPaymentMethodDetails {
18491852
payment_method:
@@ -1898,7 +1901,6 @@ impl api::IncomingWebhook for Stripe {
18981901
| stripe::WebhookEventType::ChargePending
18991902
| stripe::WebhookEventType::ChargeUpdated
19001903
| stripe::WebhookEventType::ChargeRefunded
1901-
| stripe::WebhookEventType::PaymentIntentCanceled
19021904
| stripe::WebhookEventType::PaymentIntentCreated
19031905
| stripe::WebhookEventType::PaymentIntentProcessing
19041906
| stripe::WebhookEventType::PaymentIntentAmountCapturableUpdated

crates/router/src/core/webhooks/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fn default_webhook_config() -> api::MerchantWebhookConfig {
1717
api::IncomingWebhookEvent::PaymentIntentSuccess,
1818
api::IncomingWebhookEvent::PaymentIntentFailure,
1919
api::IncomingWebhookEvent::PaymentIntentProcessing,
20+
api::IncomingWebhookEvent::PaymentIntentCancelled,
2021
api::IncomingWebhookEvent::PaymentActionRequired,
2122
api::IncomingWebhookEvent::RefundSuccess,
2223
])

crates/router/src/types/transformers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ impl ForeignFrom<api_enums::IntentStatus> for Option<storage_enums::EventType> {
257257
| api_enums::IntentStatus::RequiresCustomerAction => {
258258
Some(storage_enums::EventType::ActionRequired)
259259
}
260-
api_enums::IntentStatus::Cancelled
261-
| api_enums::IntentStatus::RequiresPaymentMethod
260+
api_enums::IntentStatus::Cancelled => Some(storage_enums::EventType::PaymentCancelled),
261+
api_enums::IntentStatus::RequiresPaymentMethod
262262
| api_enums::IntentStatus::RequiresConfirmation
263263
| api_enums::IntentStatus::RequiresCapture
264264
| api_enums::IntentStatus::PartiallyCaptured => None,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- This file should undo anything in `up.sql`
2+
Select 1;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Your SQL goes here
2+
ALTER TYPE "EventType" ADD VALUE 'payment_cancelled';

openapi/openapi_spec.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5076,6 +5076,7 @@
50765076
"payment_succeeded",
50775077
"payment_failed",
50785078
"payment_processing",
5079+
"payment_cancelled",
50795080
"action_required",
50805081
"refund_succeeded",
50815082
"refund_failed",

0 commit comments

Comments
 (0)