diff --git a/crates/hyperswitch_connectors/src/connectors/novalnet.rs b/crates/hyperswitch_connectors/src/connectors/novalnet.rs index 7450a48884a7..8331e229acb9 100644 --- a/crates/hyperswitch_connectors/src/connectors/novalnet.rs +++ b/crates/hyperswitch_connectors/src/connectors/novalnet.rs @@ -37,7 +37,7 @@ use hyperswitch_interfaces::{ ConnectorValidation, }, configs::Connectors, - errors, + disputes, errors, events::connector_api_logs::ConnectorEvent, types::{self, Response}, webhooks, @@ -877,4 +877,44 @@ impl webhooks::IncomingWebhook for Novalnet { .change_context(errors::ConnectorError::WebhookResourceObjectNotFound)?; Ok(Box::new(notif)) } + + fn get_dispute_details( + &self, + request: &webhooks::IncomingWebhookRequestDetails<'_>, + ) -> CustomResult { + let notif: transformers::NovalnetWebhookNotificationResponse = + get_webhook_object_from_body(request.body) + .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?; + let (amount, currency, reason, reason_code) = match notif.transaction { + novalnet::NovalnetWebhookTransactionData::CaptureTransactionData(data) => { + (data.amount, data.currency, None, None) + } + novalnet::NovalnetWebhookTransactionData::CancelTransactionData(data) => { + (data.amount, data.currency, None, None) + } + + novalnet::NovalnetWebhookTransactionData::RefundsTransactionData(data) => { + (data.amount, data.currency, None, None) + } + + novalnet::NovalnetWebhookTransactionData::SyncTransactionData(data) => { + (data.amount, data.currency, data.reason, data.reason_code) + } + }; + + let dispute_status = + novalnet::get_novalnet_dispute_status(notif.event.event_type).to_string(); + Ok(disputes::DisputePayload { + amount: novalnet::option_to_result(amount)?.to_string(), + currency: novalnet::option_to_result(currency)?.to_string(), + dispute_stage: api_models::enums::DisputeStage::Dispute, + connector_dispute_id: notif.event.tid.to_string(), + connector_reason: reason, + connector_reason_code: reason_code, + challenge_required_by: None, + connector_status: dispute_status, + created_at: None, + updated_at: None, + }) + } } diff --git a/crates/hyperswitch_connectors/src/connectors/novalnet/transformers.rs b/crates/hyperswitch_connectors/src/connectors/novalnet/transformers.rs index 313e35eeb0e6..1888511e9ba2 100644 --- a/crates/hyperswitch_connectors/src/connectors/novalnet/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/novalnet/transformers.rs @@ -1294,6 +1294,8 @@ pub enum WebhookEventType { TransactionCapture, TransactionCancel, TransactionRefund, + Chargeback, + Credit, } #[derive(Serialize, Deserialize, Debug)] @@ -1356,9 +1358,30 @@ pub fn get_incoming_webhook_event( } _ => IncomingWebhookEvent::RefundFailure, }, + WebhookEventType::Chargeback => IncomingWebhookEvent::DisputeOpened, + WebhookEventType::Credit => IncomingWebhookEvent::DisputeWon, } } pub fn reverse_string(s: &str) -> String { s.chars().rev().collect() } + +#[derive(Display, Debug, Serialize, Deserialize)] +pub enum WebhookDisputeStatus { + DisputeOpened, + DisputeWon, + Unknown, +} + +pub fn get_novalnet_dispute_status(status: WebhookEventType) -> WebhookDisputeStatus { + match status { + WebhookEventType::Chargeback => WebhookDisputeStatus::DisputeOpened, + WebhookEventType::Credit => WebhookDisputeStatus::DisputeWon, + _ => WebhookDisputeStatus::Unknown, + } +} + +pub fn option_to_result(opt: Option) -> Result { + opt.ok_or(errors::ConnectorError::WebhookBodyDecodingFailed) +}