mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-31 01:57:45 +08:00
feat(core): add new payments webhook events (#3212)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: hrithikeshvm <vmhrithikesh@gmail.com>
This commit is contained in:
@ -8,11 +8,18 @@ use crate::{disputes, enums as api_enums, mandates, payments, refunds};
|
|||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Copy)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Copy)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum IncomingWebhookEvent {
|
pub enum IncomingWebhookEvent {
|
||||||
|
/// Authorization + Capture success
|
||||||
PaymentIntentFailure,
|
PaymentIntentFailure,
|
||||||
|
/// Authorization + Capture failure
|
||||||
PaymentIntentSuccess,
|
PaymentIntentSuccess,
|
||||||
PaymentIntentProcessing,
|
PaymentIntentProcessing,
|
||||||
PaymentIntentPartiallyFunded,
|
PaymentIntentPartiallyFunded,
|
||||||
PaymentIntentCancelled,
|
PaymentIntentCancelled,
|
||||||
|
PaymentIntentCancelFailure,
|
||||||
|
PaymentIntentAuthorizationSuccess,
|
||||||
|
PaymentIntentAuthorizationFailure,
|
||||||
|
PaymentIntentCaptureSuccess,
|
||||||
|
PaymentIntentCaptureFailure,
|
||||||
PaymentActionRequired,
|
PaymentActionRequired,
|
||||||
EventNotSupported,
|
EventNotSupported,
|
||||||
SourceChargeable,
|
SourceChargeable,
|
||||||
@ -86,7 +93,12 @@ impl From<IncomingWebhookEvent> for WebhookFlow {
|
|||||||
| IncomingWebhookEvent::PaymentIntentProcessing
|
| IncomingWebhookEvent::PaymentIntentProcessing
|
||||||
| IncomingWebhookEvent::PaymentActionRequired
|
| IncomingWebhookEvent::PaymentActionRequired
|
||||||
| IncomingWebhookEvent::PaymentIntentPartiallyFunded
|
| 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::EventNotSupported => Self::ReturnResponse,
|
||||||
IncomingWebhookEvent::RefundSuccess | IncomingWebhookEvent::RefundFailure => {
|
IncomingWebhookEvent::RefundSuccess | IncomingWebhookEvent::RefundFailure => {
|
||||||
Self::Refund
|
Self::Refund
|
||||||
|
|||||||
@ -921,10 +921,14 @@ impl Currency {
|
|||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
#[strum(serialize_all = "snake_case")]
|
#[strum(serialize_all = "snake_case")]
|
||||||
pub enum EventType {
|
pub enum EventType {
|
||||||
|
/// Authorize + Capture success
|
||||||
PaymentSucceeded,
|
PaymentSucceeded,
|
||||||
|
/// Authorize + Capture failed
|
||||||
PaymentFailed,
|
PaymentFailed,
|
||||||
PaymentProcessing,
|
PaymentProcessing,
|
||||||
PaymentCancelled,
|
PaymentCancelled,
|
||||||
|
PaymentAuthorized,
|
||||||
|
PaymentCaptured,
|
||||||
ActionRequired,
|
ActionRequired,
|
||||||
RefundSucceeded,
|
RefundSucceeded,
|
||||||
RefundFailed,
|
RefundFailed,
|
||||||
|
|||||||
@ -183,6 +183,13 @@ fn get_stripe_event_type(event_type: api_models::enums::EventType) -> &'static s
|
|||||||
api_models::enums::EventType::DisputeLost => "dispute.lost",
|
api_models::enums::EventType::DisputeLost => "dispute.lost",
|
||||||
api_models::enums::EventType::MandateActive => "mandate.active",
|
api_models::enums::EventType::MandateActive => "mandate.active",
|
||||||
api_models::enums::EventType::MandateRevoked => "mandate.revoked",
|
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",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -873,6 +873,21 @@ impl api::IncomingWebhook for Nmi {
|
|||||||
reference_body.event_body.order_id,
|
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(
|
nmi::NmiActionType::Refund => api_models::webhooks::ObjectReferenceId::RefundId(
|
||||||
api_models::webhooks::RefundIdType::RefundId(reference_body.event_body.order_id),
|
api_models::webhooks::RefundIdType::RefundId(reference_body.event_body.order_id),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1166,21 +1166,19 @@ pub enum NmiWebhookEventType {
|
|||||||
impl ForeignFrom<NmiWebhookEventType> for webhooks::IncomingWebhookEvent {
|
impl ForeignFrom<NmiWebhookEventType> for webhooks::IncomingWebhookEvent {
|
||||||
fn foreign_from(status: NmiWebhookEventType) -> Self {
|
fn foreign_from(status: NmiWebhookEventType) -> Self {
|
||||||
match status {
|
match status {
|
||||||
NmiWebhookEventType::SaleSuccess | NmiWebhookEventType::CaptureSuccess => {
|
NmiWebhookEventType::SaleSuccess => Self::PaymentIntentSuccess,
|
||||||
Self::PaymentIntentSuccess
|
NmiWebhookEventType::SaleFailure => Self::PaymentIntentFailure,
|
||||||
}
|
|
||||||
NmiWebhookEventType::SaleFailure | NmiWebhookEventType::CaptureFailure => {
|
|
||||||
Self::PaymentIntentFailure
|
|
||||||
}
|
|
||||||
NmiWebhookEventType::RefundSuccess => Self::RefundSuccess,
|
NmiWebhookEventType::RefundSuccess => Self::RefundSuccess,
|
||||||
NmiWebhookEventType::RefundFailure => Self::RefundFailure,
|
NmiWebhookEventType::RefundFailure => Self::RefundFailure,
|
||||||
NmiWebhookEventType::VoidSuccess => Self::PaymentIntentCancelled,
|
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::SaleUnknown
|
||||||
| NmiWebhookEventType::RefundUnknown
|
| NmiWebhookEventType::RefundUnknown
|
||||||
| NmiWebhookEventType::AuthSuccess
|
|
||||||
| NmiWebhookEventType::AuthFailure
|
|
||||||
| NmiWebhookEventType::AuthUnknown
|
| NmiWebhookEventType::AuthUnknown
|
||||||
| NmiWebhookEventType::VoidFailure
|
|
||||||
| NmiWebhookEventType::VoidUnknown
|
| NmiWebhookEventType::VoidUnknown
|
||||||
| NmiWebhookEventType::CaptureUnknown => Self::EventNotSupported,
|
| NmiWebhookEventType::CaptureUnknown => Self::EventNotSupported,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1977,6 +1977,9 @@ impl api::IncomingWebhook for Stripe {
|
|||||||
stripe::WebhookEventType::PaymentIntentCanceled => {
|
stripe::WebhookEventType::PaymentIntentCanceled => {
|
||||||
api::IncomingWebhookEvent::PaymentIntentCancelled
|
api::IncomingWebhookEvent::PaymentIntentCancelled
|
||||||
}
|
}
|
||||||
|
stripe::WebhookEventType::PaymentIntentAmountCapturableUpdated => {
|
||||||
|
api::IncomingWebhookEvent::PaymentIntentAuthorizationSuccess
|
||||||
|
}
|
||||||
stripe::WebhookEventType::ChargeSucceeded => {
|
stripe::WebhookEventType::ChargeSucceeded => {
|
||||||
if let Some(stripe::WebhookPaymentMethodDetails {
|
if let Some(stripe::WebhookPaymentMethodDetails {
|
||||||
payment_method:
|
payment_method:
|
||||||
@ -2033,7 +2036,6 @@ impl api::IncomingWebhook for Stripe {
|
|||||||
| stripe::WebhookEventType::ChargeRefunded
|
| stripe::WebhookEventType::ChargeRefunded
|
||||||
| stripe::WebhookEventType::PaymentIntentCreated
|
| stripe::WebhookEventType::PaymentIntentCreated
|
||||||
| stripe::WebhookEventType::PaymentIntentProcessing
|
| stripe::WebhookEventType::PaymentIntentProcessing
|
||||||
| stripe::WebhookEventType::PaymentIntentAmountCapturableUpdated
|
|
||||||
| stripe::WebhookEventType::SourceTransactionCreated => {
|
| stripe::WebhookEventType::SourceTransactionCreated => {
|
||||||
api::IncomingWebhookEvent::EventNotSupported
|
api::IncomingWebhookEvent::EventNotSupported
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3315,7 +3315,7 @@ pub enum WebhookEventType {
|
|||||||
PaymentIntentProcessing,
|
PaymentIntentProcessing,
|
||||||
#[serde(rename = "payment_intent.requires_action")]
|
#[serde(rename = "payment_intent.requires_action")]
|
||||||
PaymentIntentRequiresAction,
|
PaymentIntentRequiresAction,
|
||||||
#[serde(rename = "amount_capturable_updated")]
|
#[serde(rename = "payment_intent.amount_capturable_updated")]
|
||||||
PaymentIntentAmountCapturableUpdated,
|
PaymentIntentAmountCapturableUpdated,
|
||||||
#[serde(rename = "source.chargeable")]
|
#[serde(rename = "source.chargeable")]
|
||||||
SourceChargeable,
|
SourceChargeable,
|
||||||
|
|||||||
@ -352,11 +352,15 @@ impl ForeignFrom<api_enums::IntentStatus> for Option<storage_enums::EventType> {
|
|||||||
Some(storage_enums::EventType::ActionRequired)
|
Some(storage_enums::EventType::ActionRequired)
|
||||||
}
|
}
|
||||||
api_enums::IntentStatus::Cancelled => Some(storage_enums::EventType::PaymentCancelled),
|
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::RequiresPaymentMethod
|
||||||
| api_enums::IntentStatus::RequiresConfirmation
|
| api_enums::IntentStatus::RequiresConfirmation => None,
|
||||||
| api_enums::IntentStatus::RequiresCapture
|
|
||||||
| api_enums::IntentStatus::PartiallyCaptured
|
|
||||||
| api_enums::IntentStatus::PartiallyCapturedAndCapturable => None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,2 @@
|
|||||||
|
-- This file should undo anything in `up.sql`
|
||||||
|
SELECT 1;
|
||||||
@ -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';
|
||||||
@ -5556,6 +5556,8 @@
|
|||||||
"payment_failed",
|
"payment_failed",
|
||||||
"payment_processing",
|
"payment_processing",
|
||||||
"payment_cancelled",
|
"payment_cancelled",
|
||||||
|
"payment_authorized",
|
||||||
|
"payment_captured",
|
||||||
"action_required",
|
"action_required",
|
||||||
"refund_succeeded",
|
"refund_succeeded",
|
||||||
"refund_failed",
|
"refund_failed",
|
||||||
|
|||||||
Reference in New Issue
Block a user