mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 05:17:02 +08:00
feat(router): add mandates incoming webhooks flow (#2464)
This commit is contained in:
committed by
GitHub
parent
3f0d927cb8
commit
1cf8b6cf53
@ -1,5 +1,5 @@
|
||||
use api_models::{
|
||||
enums::DisputeStatus,
|
||||
enums::{DisputeStatus, MandateStatus},
|
||||
webhooks::{self as api},
|
||||
};
|
||||
use common_utils::{crypto::SignMessage, date_time, ext_traits};
|
||||
@ -73,6 +73,7 @@ pub enum StripeWebhookObject {
|
||||
PaymentIntent(StripePaymentIntentResponse),
|
||||
Refund(StripeRefundResponse),
|
||||
Dispute(StripeDisputeResponse),
|
||||
Mandate(StripeMandateResponse),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
@ -85,6 +86,22 @@ pub struct StripeDisputeResponse {
|
||||
pub status: StripeDisputeStatus,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
pub struct StripeMandateResponse {
|
||||
pub mandate_id: String,
|
||||
pub status: StripeMandateStatus,
|
||||
pub payment_method_id: String,
|
||||
pub payment_method: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum StripeMandateStatus {
|
||||
Active,
|
||||
Inactive,
|
||||
Pending,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum StripeDisputeStatus {
|
||||
@ -111,6 +128,27 @@ impl From<api_models::disputes::DisputeResponse> for StripeDisputeResponse {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<api_models::mandates::MandateResponse> for StripeMandateResponse {
|
||||
fn from(res: api_models::mandates::MandateResponse) -> Self {
|
||||
Self {
|
||||
mandate_id: res.mandate_id,
|
||||
payment_method: res.payment_method,
|
||||
payment_method_id: res.payment_method_id,
|
||||
status: StripeMandateStatus::from(res.status),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MandateStatus> for StripeMandateStatus {
|
||||
fn from(status: MandateStatus) -> Self {
|
||||
match status {
|
||||
MandateStatus::Active => Self::Active,
|
||||
MandateStatus::Inactive | MandateStatus::Revoked => Self::Inactive,
|
||||
MandateStatus::Pending => Self::Pending,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DisputeStatus> for StripeDisputeStatus {
|
||||
fn from(status: DisputeStatus) -> Self {
|
||||
match status {
|
||||
@ -142,6 +180,8 @@ fn get_stripe_event_type(event_type: api_models::enums::EventType) -> &'static s
|
||||
api_models::enums::EventType::DisputeChallenged => "dispute.challenged",
|
||||
api_models::enums::EventType::DisputeWon => "dispute.won",
|
||||
api_models::enums::EventType::DisputeLost => "dispute.lost",
|
||||
api_models::enums::EventType::MandateActive => "mandate.active",
|
||||
api_models::enums::EventType::MandateRevoked => "mandate.revoked",
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,6 +219,9 @@ impl From<api::OutgoingWebhookContent> for StripeWebhookObject {
|
||||
api::OutgoingWebhookContent::DisputeDetails(dispute) => {
|
||||
Self::Dispute((*dispute).into())
|
||||
}
|
||||
api::OutgoingWebhookContent::MandateDetails(mandate) => {
|
||||
Self::Mandate((*mandate).into())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user