Skip to content

Commit

Permalink
feat(router): Add Cancel Event in Webhooks and Mapping it in Stripe (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
deepanshu-iiitu authored Oct 13, 2023
1 parent d401975 commit 92f7918
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion crates/api_models/src/webhooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub enum IncomingWebhookEvent {
PaymentIntentSuccess,
PaymentIntentProcessing,
PaymentIntentPartiallyFunded,
PaymentIntentCancelled,
PaymentActionRequired,
EventNotSupported,
SourceChargeable,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ pub enum EventType {
PaymentSucceeded,
PaymentFailed,
PaymentProcessing,
PaymentCancelled,
ActionRequired,
RefundSucceeded,
RefundFailed,
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/compatibility/stripe/webhooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion crates/router/src/connector/stripe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/webhooks/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
])
Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/types/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
Select 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TYPE "EventType" ADD VALUE 'payment_cancelled';
1 change: 1 addition & 0 deletions openapi/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5076,6 +5076,7 @@
"payment_succeeded",
"payment_failed",
"payment_processing",
"payment_cancelled",
"action_required",
"refund_succeeded",
"refund_failed",
Expand Down

0 comments on commit 92f7918

Please sign in to comment.