mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 11:24:45 +08:00
feat(router): added incoming dispute webhooks flow (#769)
Co-authored-by: Sangamesh <sangamesh.kulkarni@juspay.in> Co-authored-by: sai harsha <sai.harsha@sai.harsha-MacBookPro> Co-authored-by: Arun Raj M <jarnura47@gmail.com>
This commit is contained in:
@ -1 +1,38 @@
|
||||
use masking::Serialize;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
use super::enums::{DisputeStage, DisputeStatus};
|
||||
|
||||
#[derive(Default, Clone, Debug, Serialize, ToSchema)]
|
||||
pub struct DisputeResponse {
|
||||
/// The identifier for dispute
|
||||
pub dispute_id: String,
|
||||
/// The identifier for payment_intent
|
||||
pub payment_id: String,
|
||||
/// The identifier for payment_attempt
|
||||
pub attempt_id: String,
|
||||
/// The dispute amount
|
||||
pub amount: String,
|
||||
/// The three-letter ISO currency code
|
||||
pub currency: String,
|
||||
/// Stage of the dispute
|
||||
pub dispute_stage: DisputeStage,
|
||||
/// Status of the dispute
|
||||
pub dispute_status: DisputeStatus,
|
||||
/// Status of the dispute sent by connector
|
||||
pub connector_status: String,
|
||||
/// Dispute id sent by connector
|
||||
pub connector_dispute_id: String,
|
||||
/// Reason of dispute sent by connector
|
||||
pub connector_reason: Option<String>,
|
||||
/// Reason code of dispute sent by connector
|
||||
pub connector_reason_code: Option<String>,
|
||||
/// Evidence deadline of dispute sent by connector
|
||||
pub challenge_required_by: Option<String>,
|
||||
/// Dispute created time sent by connector
|
||||
pub created_at: Option<String>,
|
||||
/// Dispute updated time sent by connector
|
||||
pub updated_at: Option<String>,
|
||||
/// Time at which dispute is received
|
||||
pub received_at: String,
|
||||
}
|
||||
|
||||
@ -267,6 +267,13 @@ pub enum EventType {
|
||||
PaymentSucceeded,
|
||||
RefundSucceeded,
|
||||
RefundFailed,
|
||||
DisputeOpened,
|
||||
DisputeExpired,
|
||||
DisputeAccepted,
|
||||
DisputeCancelled,
|
||||
DisputeChallenged,
|
||||
DisputeWon,
|
||||
DisputeLost,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
@ -767,3 +774,51 @@ impl From<AttemptStatus> for IntentStatus {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
Default,
|
||||
Debug,
|
||||
Eq,
|
||||
Hash,
|
||||
PartialEq,
|
||||
serde::Deserialize,
|
||||
serde::Serialize,
|
||||
strum::Display,
|
||||
strum::EnumString,
|
||||
frunk::LabelledGeneric,
|
||||
ToSchema,
|
||||
)]
|
||||
pub enum DisputeStage {
|
||||
PreDispute,
|
||||
#[default]
|
||||
Dispute,
|
||||
PreArbitration,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
Default,
|
||||
Eq,
|
||||
Hash,
|
||||
PartialEq,
|
||||
serde::Deserialize,
|
||||
serde::Serialize,
|
||||
strum::Display,
|
||||
strum::EnumString,
|
||||
frunk::LabelledGeneric,
|
||||
ToSchema,
|
||||
)]
|
||||
pub enum DisputeStatus {
|
||||
#[default]
|
||||
DisputeOpened,
|
||||
DisputeExpired,
|
||||
DisputeAccepted,
|
||||
DisputeCancelled,
|
||||
DisputeChallenged,
|
||||
// dispute has been successfully challenged by the merchant
|
||||
DisputeWon,
|
||||
// dispute has been unsuccessfully challenged
|
||||
DisputeLost,
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ use common_utils::custom_serde;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use time::PrimitiveDateTime;
|
||||
|
||||
use crate::{enums as api_enums, payments, refunds};
|
||||
use crate::{disputes, enums as api_enums, payments, refunds};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
@ -11,12 +11,22 @@ pub enum IncomingWebhookEvent {
|
||||
PaymentIntentSuccess,
|
||||
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,
|
||||
}
|
||||
@ -28,6 +38,13 @@ impl From<IncomingWebhookEvent> for WebhookFlow {
|
||||
IncomingWebhookEvent::PaymentIntentSuccess => 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,
|
||||
}
|
||||
}
|
||||
@ -73,6 +90,7 @@ pub struct OutgoingWebhook {
|
||||
pub enum OutgoingWebhookContent {
|
||||
PaymentDetails(payments::PaymentsResponse),
|
||||
RefundDetails(refunds::RefundResponse),
|
||||
DisputeDetails(Box<disputes::DisputeResponse>),
|
||||
}
|
||||
|
||||
pub trait OutgoingWebhookType: Serialize + From<OutgoingWebhook> + Sync + Send {}
|
||||
|
||||
Reference in New Issue
Block a user