mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
refactor(connector): [Volt] Refactor Payments and Refunds Webhooks (#3377)
This commit is contained in:
@ -635,43 +635,40 @@ impl api::IncomingWebhook for Volt {
|
|||||||
&self,
|
&self,
|
||||||
request: &api::IncomingWebhookRequestDetails<'_>,
|
request: &api::IncomingWebhookRequestDetails<'_>,
|
||||||
) -> CustomResult<api::webhooks::ObjectReferenceId, errors::ConnectorError> {
|
) -> CustomResult<api::webhooks::ObjectReferenceId, errors::ConnectorError> {
|
||||||
let x_volt_type =
|
let parsed_webhook_response = request
|
||||||
utils::get_header_key_value(webhook_headers::X_VOLT_TYPE, request.headers)?;
|
.body
|
||||||
if x_volt_type == "refund_confirmed" || x_volt_type == "refund_failed" {
|
.parse_struct::<volt::WebhookResponse>("VoltRefundWebhookBodyReference")
|
||||||
let refund_webhook_body: volt::VoltRefundWebhookBodyReference = request
|
.change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;
|
||||||
.body
|
|
||||||
.parse_struct("VoltRefundWebhookBodyReference")
|
|
||||||
.change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;
|
|
||||||
|
|
||||||
let refund_reference = match refund_webhook_body.external_reference {
|
match parsed_webhook_response {
|
||||||
Some(external_reference) => {
|
volt::WebhookResponse::Payment(payment_response) => {
|
||||||
api_models::webhooks::RefundIdType::RefundId(external_reference)
|
let reference = match payment_response.merchant_internal_reference {
|
||||||
}
|
Some(merchant_internal_reference) => {
|
||||||
None => api_models::webhooks::RefundIdType::ConnectorRefundId(
|
api_models::payments::PaymentIdType::PaymentAttemptId(
|
||||||
refund_webhook_body.refund,
|
merchant_internal_reference,
|
||||||
),
|
)
|
||||||
};
|
}
|
||||||
Ok(api_models::webhooks::ObjectReferenceId::RefundId(
|
None => api_models::payments::PaymentIdType::ConnectorTransactionId(
|
||||||
refund_reference,
|
payment_response.payment,
|
||||||
))
|
),
|
||||||
} else {
|
};
|
||||||
let webhook_body: volt::VoltPaymentWebhookBodyReference = request
|
Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
|
||||||
.body
|
reference,
|
||||||
.parse_struct("VoltPaymentWebhookBodyReference")
|
))
|
||||||
.change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;
|
}
|
||||||
let reference = match webhook_body.merchant_internal_reference {
|
volt::WebhookResponse::Refund(refund_response) => {
|
||||||
Some(merchant_internal_reference) => {
|
let refund_reference = match refund_response.external_reference {
|
||||||
api_models::payments::PaymentIdType::PaymentAttemptId(
|
Some(external_reference) => {
|
||||||
merchant_internal_reference,
|
api_models::webhooks::RefundIdType::RefundId(external_reference)
|
||||||
)
|
}
|
||||||
}
|
None => api_models::webhooks::RefundIdType::ConnectorRefundId(
|
||||||
None => api_models::payments::PaymentIdType::ConnectorTransactionId(
|
refund_response.refund,
|
||||||
webhook_body.payment,
|
),
|
||||||
),
|
};
|
||||||
};
|
Ok(api_models::webhooks::ObjectReferenceId::RefundId(
|
||||||
Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
|
refund_reference,
|
||||||
reference,
|
))
|
||||||
))
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,6 @@ pub mod webhook_headers {
|
|||||||
pub const X_VOLT_SIGNED: &str = "X-Volt-Signed";
|
pub const X_VOLT_SIGNED: &str = "X-Volt-Signed";
|
||||||
pub const X_VOLT_TIMED: &str = "X-Volt-Timed";
|
pub const X_VOLT_TIMED: &str = "X-Volt-Timed";
|
||||||
pub const USER_AGENT: &str = "User-Agent";
|
pub const USER_AGENT: &str = "User-Agent";
|
||||||
pub const X_VOLT_TYPE: &str = "X-Volt-Type";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
@ -488,6 +487,15 @@ pub struct VoltRefundWebhookBodyReference {
|
|||||||
pub external_reference: Option<String>,
|
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)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum VoltWebhookBodyEventType {
|
pub enum VoltWebhookBodyEventType {
|
||||||
|
|||||||
Reference in New Issue
Block a user