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

This commit is contained in:
DEEPANSHU BANSAL
2023-10-13 16:35:00 +05:30
committed by GitHub
parent d4019751ff
commit 92f7918e6f
9 changed files with 16 additions and 4 deletions

View File

@ -12,6 +12,7 @@ pub enum IncomingWebhookEvent {
PaymentIntentSuccess, PaymentIntentSuccess,
PaymentIntentProcessing, PaymentIntentProcessing,
PaymentIntentPartiallyFunded, PaymentIntentPartiallyFunded,
PaymentIntentCancelled,
PaymentActionRequired, PaymentActionRequired,
EventNotSupported, EventNotSupported,
SourceChargeable, SourceChargeable,
@ -84,7 +85,8 @@ impl From<IncomingWebhookEvent> for WebhookFlow {
| IncomingWebhookEvent::PaymentIntentSuccess | IncomingWebhookEvent::PaymentIntentSuccess
| IncomingWebhookEvent::PaymentIntentProcessing | IncomingWebhookEvent::PaymentIntentProcessing
| IncomingWebhookEvent::PaymentActionRequired | IncomingWebhookEvent::PaymentActionRequired
| IncomingWebhookEvent::PaymentIntentPartiallyFunded => Self::Payment, | IncomingWebhookEvent::PaymentIntentPartiallyFunded
| IncomingWebhookEvent::PaymentIntentCancelled => Self::Payment,
IncomingWebhookEvent::EventNotSupported => Self::ReturnResponse, IncomingWebhookEvent::EventNotSupported => Self::ReturnResponse,
IncomingWebhookEvent::RefundSuccess | IncomingWebhookEvent::RefundFailure => { IncomingWebhookEvent::RefundSuccess | IncomingWebhookEvent::RefundFailure => {
Self::Refund Self::Refund

View File

@ -794,6 +794,7 @@ pub enum EventType {
PaymentSucceeded, PaymentSucceeded,
PaymentFailed, PaymentFailed,
PaymentProcessing, PaymentProcessing,
PaymentCancelled,
ActionRequired, ActionRequired,
RefundSucceeded, RefundSucceeded,
RefundFailed, RefundFailed,

View File

@ -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::PaymentSucceeded => "payment_intent.succeeded",
api_models::enums::EventType::PaymentFailed => "payment_intent.payment_failed", api_models::enums::EventType::PaymentFailed => "payment_intent.payment_failed",
api_models::enums::EventType::PaymentProcessing => "payment_intent.processing", 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 // the below are not really stripe compatible because stripe doesn't provide this
api_models::enums::EventType::ActionRequired => "action.required", api_models::enums::EventType::ActionRequired => "action.required",

View File

@ -1844,6 +1844,9 @@ impl api::IncomingWebhook for Stripe {
stripe::WebhookEventType::PaymentIntentSucceed => { stripe::WebhookEventType::PaymentIntentSucceed => {
api::IncomingWebhookEvent::PaymentIntentSuccess api::IncomingWebhookEvent::PaymentIntentSuccess
} }
stripe::WebhookEventType::PaymentIntentCanceled => {
api::IncomingWebhookEvent::PaymentIntentCancelled
}
stripe::WebhookEventType::ChargeSucceeded => { stripe::WebhookEventType::ChargeSucceeded => {
if let Some(stripe::WebhookPaymentMethodDetails { if let Some(stripe::WebhookPaymentMethodDetails {
payment_method: payment_method:
@ -1898,7 +1901,6 @@ impl api::IncomingWebhook for Stripe {
| stripe::WebhookEventType::ChargePending | stripe::WebhookEventType::ChargePending
| stripe::WebhookEventType::ChargeUpdated | stripe::WebhookEventType::ChargeUpdated
| stripe::WebhookEventType::ChargeRefunded | stripe::WebhookEventType::ChargeRefunded
| stripe::WebhookEventType::PaymentIntentCanceled
| stripe::WebhookEventType::PaymentIntentCreated | stripe::WebhookEventType::PaymentIntentCreated
| stripe::WebhookEventType::PaymentIntentProcessing | stripe::WebhookEventType::PaymentIntentProcessing
| stripe::WebhookEventType::PaymentIntentAmountCapturableUpdated | stripe::WebhookEventType::PaymentIntentAmountCapturableUpdated

View File

@ -17,6 +17,7 @@ fn default_webhook_config() -> api::MerchantWebhookConfig {
api::IncomingWebhookEvent::PaymentIntentSuccess, api::IncomingWebhookEvent::PaymentIntentSuccess,
api::IncomingWebhookEvent::PaymentIntentFailure, api::IncomingWebhookEvent::PaymentIntentFailure,
api::IncomingWebhookEvent::PaymentIntentProcessing, api::IncomingWebhookEvent::PaymentIntentProcessing,
api::IncomingWebhookEvent::PaymentIntentCancelled,
api::IncomingWebhookEvent::PaymentActionRequired, api::IncomingWebhookEvent::PaymentActionRequired,
api::IncomingWebhookEvent::RefundSuccess, api::IncomingWebhookEvent::RefundSuccess,
]) ])

View File

@ -257,8 +257,8 @@ impl ForeignFrom<api_enums::IntentStatus> for Option<storage_enums::EventType> {
| api_enums::IntentStatus::RequiresCustomerAction => { | api_enums::IntentStatus::RequiresCustomerAction => {
Some(storage_enums::EventType::ActionRequired) Some(storage_enums::EventType::ActionRequired)
} }
api_enums::IntentStatus::Cancelled api_enums::IntentStatus::Cancelled => Some(storage_enums::EventType::PaymentCancelled),
| api_enums::IntentStatus::RequiresPaymentMethod api_enums::IntentStatus::RequiresPaymentMethod
| api_enums::IntentStatus::RequiresConfirmation | api_enums::IntentStatus::RequiresConfirmation
| api_enums::IntentStatus::RequiresCapture | api_enums::IntentStatus::RequiresCapture
| api_enums::IntentStatus::PartiallyCaptured => None, | api_enums::IntentStatus::PartiallyCaptured => None,

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
Select 1;

View File

@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TYPE "EventType" ADD VALUE 'payment_cancelled';

View File

@ -5076,6 +5076,7 @@
"payment_succeeded", "payment_succeeded",
"payment_failed", "payment_failed",
"payment_processing", "payment_processing",
"payment_cancelled",
"action_required", "action_required",
"refund_succeeded", "refund_succeeded",
"refund_failed", "refund_failed",