mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 09:07:09 +08:00
Co-authored-by: arvindpatel24 <arvind.patel@juspay.in> Co-authored-by: Jagan Elavarasan <jaganelavarasan@gmail.com>
96 lines
3.1 KiB
Rust
96 lines
3.1 KiB
Rust
use common_utils::custom_serde;
|
|
use serde::{Deserialize, Serialize};
|
|
use time::PrimitiveDateTime;
|
|
|
|
use crate::{disputes, enums as api_enums, payments, refunds};
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum IncomingWebhookEvent {
|
|
PaymentIntentFailure,
|
|
PaymentIntentSuccess,
|
|
PaymentIntentProcessing,
|
|
PaymentActionRequired,
|
|
EventNotSupported,
|
|
RefundFailure,
|
|
RefundSuccess,
|
|
DisputeOpened,
|
|
DisputeExpired,
|
|
DisputeAccepted,
|
|
DisputeCancelled,
|
|
DisputeChallenged,
|
|
// dispute has been successfully challenged by the merchant
|
|
DisputeWon,
|
|
// dispute has been unsuccessfully challenged
|
|
DisputeLost,
|
|
EndpointVerification,
|
|
}
|
|
|
|
pub enum WebhookFlow {
|
|
Payment,
|
|
Refund,
|
|
Dispute,
|
|
Subscription,
|
|
ReturnResponse,
|
|
}
|
|
|
|
impl From<IncomingWebhookEvent> for WebhookFlow {
|
|
fn from(evt: IncomingWebhookEvent) -> Self {
|
|
match evt {
|
|
IncomingWebhookEvent::PaymentIntentFailure => Self::Payment,
|
|
IncomingWebhookEvent::PaymentIntentSuccess => Self::Payment,
|
|
IncomingWebhookEvent::PaymentIntentProcessing => Self::Payment,
|
|
IncomingWebhookEvent::PaymentActionRequired => Self::Payment,
|
|
IncomingWebhookEvent::EventNotSupported => Self::Payment,
|
|
IncomingWebhookEvent::RefundSuccess => Self::Refund,
|
|
IncomingWebhookEvent::RefundFailure => Self::Refund,
|
|
IncomingWebhookEvent::DisputeOpened => Self::Dispute,
|
|
IncomingWebhookEvent::DisputeAccepted => Self::Dispute,
|
|
IncomingWebhookEvent::DisputeExpired => Self::Dispute,
|
|
IncomingWebhookEvent::DisputeCancelled => Self::Dispute,
|
|
IncomingWebhookEvent::DisputeChallenged => Self::Dispute,
|
|
IncomingWebhookEvent::DisputeWon => Self::Dispute,
|
|
IncomingWebhookEvent::DisputeLost => Self::Dispute,
|
|
IncomingWebhookEvent::EndpointVerification => Self::ReturnResponse,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub type MerchantWebhookConfig = std::collections::HashSet<IncomingWebhookEvent>;
|
|
|
|
pub enum RefundIdType {
|
|
RefundId(String),
|
|
ConnectorRefundId(String),
|
|
}
|
|
|
|
pub enum ObjectReferenceId {
|
|
PaymentId(payments::PaymentIdType),
|
|
RefundId(RefundIdType),
|
|
}
|
|
|
|
pub struct IncomingWebhookDetails {
|
|
pub object_reference_id: ObjectReferenceId,
|
|
pub resource_object: Vec<u8>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize)]
|
|
pub struct OutgoingWebhook {
|
|
pub merchant_id: String,
|
|
pub event_id: String,
|
|
pub event_type: api_enums::EventType,
|
|
pub content: OutgoingWebhookContent,
|
|
#[serde(default, with = "custom_serde::iso8601")]
|
|
pub timestamp: PrimitiveDateTime,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize)]
|
|
#[serde(tag = "type", content = "object", rename_all = "snake_case")]
|
|
pub enum OutgoingWebhookContent {
|
|
PaymentDetails(payments::PaymentsResponse),
|
|
RefundDetails(refunds::RefundResponse),
|
|
DisputeDetails(Box<disputes::DisputeResponse>),
|
|
}
|
|
|
|
pub trait OutgoingWebhookType: Serialize + From<OutgoingWebhook> + Sync + Send {}
|
|
impl OutgoingWebhookType for OutgoingWebhook {}
|