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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(connector): [Volt] Refactor Payments and Refunds Webhooks (#3377)
Swangi Kumariacb329672297
diff --git a/crates/router/src/connector/volt.rs b/crates/router/src/connector/volt.rsindex 39296bb643..f125f90d93 100644--- a/crates/router/src/connector/volt.rs+++ b/crates/router/src/connector/volt.rs@@ -635,43 +635,40 @@ impl api::IncomingWebhook for Volt {&self,request: &api::IncomingWebhookRequestDetails<'_>,) -> CustomResult<api::webhooks::ObjectReferenceId, errors::ConnectorError> {- 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,- ))+ let parsed_webhook_response = request+ .body+ .parse_struct::<volt::WebhookResponse>("VoltRefundWebhookBodyReference")+ .change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;++ match parsed_webhook_response {+ volt::WebhookResponse::Payment(payment_response) => {+ let reference = match payment_response.merchant_internal_reference {+ Some(merchant_internal_reference) => {+ api_models::payments::PaymentIdType::PaymentAttemptId(+ merchant_internal_reference,+ )+ }+ None => api_models::payments::PaymentIdType::ConnectorTransactionId(+ payment_response.payment,+ ),+ };+ Ok(api_models::webhooks::ObjectReferenceId::PaymentId(+ reference,+ ))+ }+ volt::WebhookResponse::Refund(refund_response) => {+ let refund_reference = match refund_response.external_reference {+ Some(external_reference) => {+ api_models::webhooks::RefundIdType::RefundId(external_reference)+ }+ None => api_models::webhooks::RefundIdType::ConnectorRefundId(+ refund_response.refund,+ ),+ };+ Ok(api_models::webhooks::ObjectReferenceId::RefundId(+ refund_reference,+ ))+ }}}diff --git a/crates/router/src/connector/volt/transformers.rs b/crates/router/src/connector/volt/transformers.rsindex 8b9bbecb08..b1d77f3416 100644--- a/crates/router/src/connector/volt/transformers.rs+++ b/crates/router/src/connector/volt/transformers.rs@@ -46,7 +46,6 @@ 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)]@@ -488,6 +487,15 @@ pub struct VoltRefundWebhookBodyReference {pub external_reference: Option<String>,}+#[derive(Debug, Deserialize, Clone, Serialize)]+#[serde(rename_all = "camelCase")]+#[serde(untagged)]+pub enum WebhookResponse {+ // the enum order shouldn't be changed as this is being used during serialization and deserialization+ Refund(VoltRefundWebhookBodyReference),+ Payment(VoltPaymentWebhookBodyReference),+}+#[derive(Debug, Deserialize, Serialize)]#[serde(untagged)]pub enum VoltWebhookBodyEventType {