Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(connector): [Volt] Add support for refund webhooks (#3326)

Swangi Kumarie376f68c167a
diff --git a/crates/router/src/connector/volt.rs b/crates/router/src/connector/volt.rs
index 3641c0c3dd..39296bb643 100644
--- a/crates/router/src/connector/volt.rs
+++ b/crates/router/src/connector/volt.rs
@@ -635,21 +635,44 @@ impl api::IncomingWebhook for Volt {
&self,
request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api::webhooks::ObjectReferenceId, errors::ConnectorError> {
- let webhook_body: volt::VoltWebhookBodyReference = request
- .body
- .parse_struct("VoltWebhookBodyReference")
- .change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;
- let reference = match webhook_body.merchant_internal_reference {
- Some(merchant_internal_reference) => {
- api_models::payments::PaymentIdType::PaymentAttemptId(merchant_internal_reference)
- }
- None => {
- api_models::payments::PaymentIdType::ConnectorTransactionId(webhook_body.payment)
- }
- };
- Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
- reference,
- ))
+ let x_volt_type =
+ utils::get_header_key_value(webhook_headers::X_VOLT_TYPE, request.headers)?;
+ if x_volt_type == "refund_confirmed" || x_volt_type == "refund_failed" {
+ let refund_webhook_body: volt::VoltRefundWebhookBodyReference = request
+ .body
+ .parse_struct("VoltRefundWebhookBodyReference")
+ .change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;
+
+ let refund_reference = match refund_webhook_body.external_reference {
+ Some(external_reference) => {
+ api_models::webhooks::RefundIdType::RefundId(external_reference)
+ }
+ None => api_models::webhooks::RefundIdType::ConnectorRefundId(
+ refund_webhook_body.refund,
+ ),
+ };
+ Ok(api_models::webhooks::ObjectReferenceId::RefundId(
+ refund_reference,
+ ))
+ } else {
+ let webhook_body: volt::VoltPaymentWebhookBodyReference = request
+ .body
+ .parse_struct("VoltPaymentWebhookBodyReference")
+ .change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;
+ let reference = match webhook_body.merchant_internal_reference {
+ Some(merchant_internal_reference) => {
+ api_models::payments::PaymentIdType::PaymentAttemptId(
+ merchant_internal_reference,
+ )
+ }
+ None => api_models::payments::PaymentIdType::ConnectorTransactionId(
+ webhook_body.payment,
+ ),
+ };
+ Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
+ reference,
+ ))
+ }
}
fn get_webhook_event_type(
@@ -663,7 +686,7 @@ impl api::IncomingWebhook for Volt {
.body
.parse_struct("VoltWebhookBodyEventType")
.change_context(errors::ConnectorError::WebhookEventTypeNotFound)?;
- Ok(api::IncomingWebhookEvent::from(payload.status))
+ Ok(api::IncomingWebhookEvent::from(payload))
}
}
diff --git a/crates/router/src/connector/volt/transformers.rs b/crates/router/src/connector/volt/transformers.rs
index 4c6eaeb52f..8b9bbecb08 100644
--- a/crates/router/src/connector/volt/transformers.rs
+++ b/crates/router/src/connector/volt/transformers.rs
@@ -46,6 +46,7 @@ pub mod webhook_headers {
pub const X_VOLT_SIGNED: &str = "X-Volt-Signed";
pub const X_VOLT_TIMED: &str = "X-Volt-Timed";
pub const USER_AGENT: &str = "User-Agent";
+ pub const X_VOLT_TYPE: &str = "X-Volt-Type";
}
#[derive(Debug, Serialize)]
@@ -318,8 +319,8 @@ pub enum VoltPaymentStatus {
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum VoltPaymentsResponseData {
- WebhookResponse(VoltWebhookObjectResource),
PsyncResponse(VoltPsyncResponse),
+ WebhookResponse(VoltPaymentWebhookObjectResource),
}
#[derive(Debug, Serialize, Clone, Deserialize)]
@@ -418,13 +419,16 @@ impl<F, T>
}
}
}
-
-impl From<VoltWebhookStatus> for enums::AttemptStatus {
- fn from(status: VoltWebhookStatus) -> Self {
+impl From<VoltWebhookPaymentStatus> for enums::AttemptStatus {
+ fn from(status: VoltWebhookPaymentStatus) -> Self {
match status {
- VoltWebhookStatus::Completed | VoltWebhookStatus::Received => Self::Charged,
- VoltWebhookStatus::Failed | VoltWebhookStatus::NotReceived => Self::Failure,
- VoltWebhookStatus::Pending => Self::Pending,
+ VoltWebhookPaymentStatus::Completed | VoltWebhookPaymentStatus::Received => {
+ Self::Charged
+ }
+ VoltWebhookPaymentStatus::Failed | VoltWebhookPaymentStatus::NotReceived => {
+ Self::Failure
+ }
+ VoltWebhookPaymentStatus::Pending => Self::Pending,
}
}
}
@@ -432,6 +436,7 @@ impl From<VoltWebhookStatus> for enums::AttemptStatus {
// REFUND :
// Type definition for RefundRequest
#[derive(Default, Debug, Serialize)]
+#[serde(rename_all = "camelCase")]
pub struct VoltRefundRequest {
pub amount: i64,
pub external_reference: String,
@@ -447,28 +452,6 @@ impl<F> TryFrom<&VoltRouterData<&types::RefundsRouterData<F>>> for VoltRefundReq
}
}
-// Type definition for Refund Response
-
-#[allow(dead_code)]
-#[derive(Debug, Serialize, Default, Deserialize, Clone)]
-pub enum RefundStatus {
- Succeeded,
- Failed,
- #[default]
- Processing,
-}
-
-impl From<RefundStatus> for enums::RefundStatus {
- fn from(item: RefundStatus) -> Self {
- match item {
- RefundStatus::Succeeded => Self::Success,
- RefundStatus::Failed => Self::Failure,
- RefundStatus::Processing => Self::Pending,
- //TODO: Review mapping
- }
- }
-}
-
#[derive(Default, Debug, Clone, Deserialize)]
pub struct RefundResponse {
id: String,
@@ -492,30 +475,66 @@ impl TryFrom<types::RefundsResponseRouterData<api::Execute, RefundResponse>>
}
#[derive(Debug, Deserialize, Clone, Serialize)]
-pub struct VoltWebhookBodyReference {
+#[serde(rename_all = "camelCase")]
+pub struct VoltPaymentWebhookBodyReference {
pub payment: String,
pub merchant_internal_reference: Option<String>,
}
+#[derive(Debug, Deserialize, Clone, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct VoltRefundWebhookBodyReference {
+ pub refund: String,
+ pub external_reference: Option<String>,
+}
+
+#[derive(Debug, Deserialize, Serialize)]
+#[serde(untagged)]
+pub enum VoltWebhookBodyEventType {
+ Payment(VoltPaymentsWebhookBodyEventType),
+ Refund(VoltRefundsWebhookBodyEventType),
+}
+
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
-pub struct VoltWebhookBodyEventType {
- pub status: VoltWebhookStatus,
+pub struct VoltPaymentsWebhookBodyEventType {
+ pub status: VoltWebhookPaymentStatus,
pub detailed_status: Option<VoltDetailedStatus>,
}
+#[derive(Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct VoltRefundsWebhookBodyEventType {
+ pub status: VoltWebhookRefundsStatus,
+}
+
+#[derive(Debug, Deserialize, Serialize)]
+#[serde(untagged)]
+pub enum VoltWebhookObjectResource {
+ Payment(VoltPaymentWebhookObjectResource),
+ Refund(VoltRefundWebhookObjectResource),
+}
+
#[derive(Debug, Deserialize, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
-pub struct VoltWebhookObjectResource {
+pub struct VoltPaymentWebhookObjectResource {
pub payment: String,
pub merchant_internal_reference: Option<String>,
- pub status: VoltWebhookStatus,
+ pub status: VoltWebhookPaymentStatus,
pub detailed_status: Option<VoltDetailedStatus>,
}
+#[derive(Debug, Deserialize, Clone, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct VoltRefundWebhookObjectResource {
+ pub refund: String,
+ pub external_reference: Option<String>,
+ pub status: VoltWebhookRefundsStatus,
+}
+
#[derive(Debug, Deserialize, Clone, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
-pub enum VoltWebhookStatus {
+pub enum VoltWebhookPaymentStatus {
Completed,
Failed,
Pending,
@@ -523,6 +542,13 @@ pub enum VoltWebhookStatus {
NotReceived,
}
+#[derive(Debug, Deserialize, Clone, Serialize)]
+#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
+pub enum VoltWebhookRefundsStatus {
+ RefundConfirmed,
+ RefundFailed,
+}
+
#[derive(Debug, Deserialize, Clone, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[derive(strum::Display)]
@@ -539,16 +565,22 @@ pub enum VoltDetailedStatus {
AwaitingCheckoutAuthorisation,
}
-impl From<VoltWebhookStatus> for api::IncomingWebhookEvent {
- fn from(status: VoltWebhookStatus) -> Self {
+impl From<VoltWebhookBodyEventType> for api::IncomingWebhookEvent {
+ fn from(status: VoltWebhookBodyEventType) -> Self {
match status {
- VoltWebhookStatus::Completed | VoltWebhookStatus::Received => {
- Self::PaymentIntentSuccess
- }
- VoltWebhookStatus::Failed | VoltWebhookStatus::NotReceived => {
- Self::PaymentIntentFailure
- }
- VoltWebhookStatus::Pending => Self::PaymentIntentProcessing,
+ VoltWebhookBodyEventType::Payment(payment_data) => match payment_data.status {
+ VoltWebhookPaymentStatus::Completed | VoltWebhookPaymentStatus::Received => {
+ Self::PaymentIntentSuccess
+ }
+ VoltWebhookPaymentStatus::Failed | VoltWebhookPaymentStatus::NotReceived => {
+ Self::PaymentIntentFailure
+ }
+ VoltWebhookPaymentStatus::Pending => Self::PaymentIntentProcessing,
+ },
+ VoltWebhookBodyEventType::Refund(refund_data) => match refund_data.status {
+ VoltWebhookRefundsStatus::RefundConfirmed => Self::RefundSuccess,
+ VoltWebhookRefundsStatus::RefundFailed => Self::RefundFailure,
+ },
}
}
}