mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
refactor(router): move api models into separate crate (#103)
This commit is contained in:
48
crates/api_models/src/webhooks.rs
Normal file
48
crates/api_models/src/webhooks.rs
Normal file
@ -0,0 +1,48 @@
|
||||
use common_utils::custom_serde;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use time::PrimitiveDateTime;
|
||||
|
||||
use crate::{enums as api_enums, payments};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum IncomingWebhookEvent {
|
||||
PaymentIntentSuccess,
|
||||
}
|
||||
|
||||
pub enum WebhookFlow {
|
||||
Payment,
|
||||
Refund,
|
||||
Subscription,
|
||||
}
|
||||
|
||||
impl From<IncomingWebhookEvent> for WebhookFlow {
|
||||
fn from(evt: IncomingWebhookEvent) -> Self {
|
||||
match evt {
|
||||
IncomingWebhookEvent::PaymentIntentSuccess => Self::Payment,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type MerchantWebhookConfig = std::collections::HashSet<IncomingWebhookEvent>;
|
||||
|
||||
pub struct IncomingWebhookDetails {
|
||||
pub object_reference_id: String,
|
||||
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),
|
||||
}
|
||||
Reference in New Issue
Block a user