mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 12:15:40 +08:00
fix(connector): [Paypal] dispute webhook deserialization failure (#5111)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -1465,7 +1465,6 @@ impl
|
|||||||
self, req, connectors,
|
self, req, connectors,
|
||||||
)?)
|
)?)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Ok(Some(request))
|
Ok(Some(request))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1546,11 +1545,11 @@ impl api::IncomingWebhook for Paypal {
|
|||||||
}
|
}
|
||||||
paypal::PaypalResource::PaypalDisputeWebhooks(resource) => {
|
paypal::PaypalResource::PaypalDisputeWebhooks(resource) => {
|
||||||
Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
|
Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
|
||||||
api_models::payments::PaymentIdType::PaymentAttemptId(
|
api_models::payments::PaymentIdType::ConnectorTransactionId(
|
||||||
resource
|
resource
|
||||||
.dispute_transactions
|
.disputed_transactions
|
||||||
.first()
|
.first()
|
||||||
.map(|transaction| transaction.reference_id.clone())
|
.map(|transaction| transaction.seller_transaction_id.clone())
|
||||||
.ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)?,
|
.ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)?,
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
@ -1567,17 +1566,17 @@ impl api::IncomingWebhook for Paypal {
|
|||||||
.parse_struct("PaypalWebooksEventType")
|
.parse_struct("PaypalWebooksEventType")
|
||||||
.change_context(errors::ConnectorError::WebhookEventTypeNotFound)?;
|
.change_context(errors::ConnectorError::WebhookEventTypeNotFound)?;
|
||||||
let outcome = match payload.event_type {
|
let outcome = match payload.event_type {
|
||||||
PaypalWebhookEventType::CustomerDisputeCreated
|
PaypalWebhookEventType::CustomerDisputeResolved => Some(
|
||||||
| PaypalWebhookEventType::CustomerDisputeResolved
|
|
||||||
| PaypalWebhookEventType::CustomerDisputedUpdated
|
|
||||||
| PaypalWebhookEventType::RiskDisputeCreated => Some(
|
|
||||||
request
|
request
|
||||||
.body
|
.body
|
||||||
.parse_struct::<paypal::DisputeOutcome>("PaypalWebooksEventType")
|
.parse_struct::<paypal::DisputeOutcome>("PaypalWebooksEventType")
|
||||||
.change_context(errors::ConnectorError::WebhookEventTypeNotFound)?
|
.change_context(errors::ConnectorError::WebhookEventTypeNotFound)?
|
||||||
.outcome_code,
|
.outcome_code,
|
||||||
),
|
),
|
||||||
PaypalWebhookEventType::PaymentAuthorizationCreated
|
PaypalWebhookEventType::CustomerDisputeCreated
|
||||||
|
| PaypalWebhookEventType::RiskDisputeCreated
|
||||||
|
| PaypalWebhookEventType::CustomerDisputedUpdated
|
||||||
|
| PaypalWebhookEventType::PaymentAuthorizationCreated
|
||||||
| PaypalWebhookEventType::PaymentAuthorizationVoided
|
| PaypalWebhookEventType::PaymentAuthorizationVoided
|
||||||
| PaypalWebhookEventType::PaymentCaptureDeclined
|
| PaypalWebhookEventType::PaymentCaptureDeclined
|
||||||
| PaypalWebhookEventType::PaymentCaptureCompleted
|
| PaypalWebhookEventType::PaymentCaptureCompleted
|
||||||
@ -1622,10 +1621,18 @@ impl api::IncomingWebhook for Paypal {
|
|||||||
&self,
|
&self,
|
||||||
request: &api::IncomingWebhookRequestDetails<'_>,
|
request: &api::IncomingWebhookRequestDetails<'_>,
|
||||||
) -> CustomResult<api::disputes::DisputePayload, errors::ConnectorError> {
|
) -> CustomResult<api::disputes::DisputePayload, errors::ConnectorError> {
|
||||||
let payload: paypal::PaypalDisputeWebhooks = request
|
let webhook_payload: paypal::PaypalWebhooksBody = request
|
||||||
.body
|
.body
|
||||||
.parse_struct("PaypalDisputeWebhooks")
|
.parse_struct("PaypalWebhooksBody")
|
||||||
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
|
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
|
||||||
|
match webhook_payload.resource {
|
||||||
|
transformers::PaypalResource::PaypalCardWebhooks(_)
|
||||||
|
| transformers::PaypalResource::PaypalRedirectsWebhooks(_)
|
||||||
|
| transformers::PaypalResource::PaypalRefundWebhooks(_) => {
|
||||||
|
Err(errors::ConnectorError::ResponseDeserializationFailed)
|
||||||
|
.attach_printable("Expected Dispute webhooks,but found other webhooks")?
|
||||||
|
}
|
||||||
|
transformers::PaypalResource::PaypalDisputeWebhooks(payload) => {
|
||||||
Ok(api::disputes::DisputePayload {
|
Ok(api::disputes::DisputePayload {
|
||||||
amount: connector_utils::to_currency_lower_unit(
|
amount: connector_utils::to_currency_lower_unit(
|
||||||
payload.dispute_amount.value.get_amount_as_string(),
|
payload.dispute_amount.value.get_amount_as_string(),
|
||||||
@ -1637,14 +1644,16 @@ impl api::IncomingWebhook for Paypal {
|
|||||||
),
|
),
|
||||||
connector_status: payload.status.to_string(),
|
connector_status: payload.status.to_string(),
|
||||||
connector_dispute_id: payload.dispute_id,
|
connector_dispute_id: payload.dispute_id,
|
||||||
connector_reason: payload.reason,
|
connector_reason: payload.reason.clone(),
|
||||||
connector_reason_code: payload.external_reason_code,
|
connector_reason_code: payload.reason,
|
||||||
challenge_required_by: payload.seller_response_due_date,
|
challenge_required_by: None,
|
||||||
created_at: payload.create_time,
|
created_at: payload.create_time,
|
||||||
updated_at: payload.update_time,
|
updated_at: payload.update_time,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl services::ConnectorRedirectResponse for Paypal {
|
impl services::ConnectorRedirectResponse for Paypal {
|
||||||
fn get_flow_type(
|
fn get_flow_type(
|
||||||
|
|||||||
@ -1980,7 +1980,7 @@ pub struct OrderErrorDetails {
|
|||||||
|
|
||||||
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
|
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
|
||||||
pub struct PaypalOrderErrorResponse {
|
pub struct PaypalOrderErrorResponse {
|
||||||
pub name: String,
|
pub name: Option<String>,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub debug_id: Option<String>,
|
pub debug_id: Option<String>,
|
||||||
pub details: Option<Vec<OrderErrorDetails>>,
|
pub details: Option<Vec<OrderErrorDetails>>,
|
||||||
@ -1994,7 +1994,7 @@ pub struct ErrorDetails {
|
|||||||
|
|
||||||
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
|
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
|
||||||
pub struct PaypalPaymentErrorResponse {
|
pub struct PaypalPaymentErrorResponse {
|
||||||
pub name: String,
|
pub name: Option<String>,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub debug_id: Option<String>,
|
pub debug_id: Option<String>,
|
||||||
pub details: Option<Vec<ErrorDetails>>,
|
pub details: Option<Vec<ErrorDetails>>,
|
||||||
@ -2056,21 +2056,24 @@ pub enum PaypalResource {
|
|||||||
#[derive(Deserialize, Debug, Serialize)]
|
#[derive(Deserialize, Debug, Serialize)]
|
||||||
pub struct PaypalDisputeWebhooks {
|
pub struct PaypalDisputeWebhooks {
|
||||||
pub dispute_id: String,
|
pub dispute_id: String,
|
||||||
pub dispute_transactions: Vec<DisputeTransaction>,
|
pub disputed_transactions: Vec<DisputeTransaction>,
|
||||||
pub dispute_amount: OrderAmount,
|
pub dispute_amount: OrderAmount,
|
||||||
pub dispute_outcome: DisputeOutcome,
|
pub dispute_outcome: Option<DisputeOutcome>,
|
||||||
pub dispute_life_cycle_stage: DisputeLifeCycleStage,
|
pub dispute_life_cycle_stage: DisputeLifeCycleStage,
|
||||||
pub status: DisputeStatus,
|
pub status: DisputeStatus,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub external_reason_code: Option<String>,
|
pub external_reason_code: Option<String>,
|
||||||
|
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
|
||||||
pub seller_response_due_date: Option<PrimitiveDateTime>,
|
pub seller_response_due_date: Option<PrimitiveDateTime>,
|
||||||
|
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
|
||||||
pub update_time: Option<PrimitiveDateTime>,
|
pub update_time: Option<PrimitiveDateTime>,
|
||||||
|
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
|
||||||
pub create_time: Option<PrimitiveDateTime>,
|
pub create_time: Option<PrimitiveDateTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Serialize)]
|
#[derive(Deserialize, Debug, Serialize)]
|
||||||
pub struct DisputeTransaction {
|
pub struct DisputeTransaction {
|
||||||
pub reference_id: String,
|
pub seller_transaction_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Debug, strum::Display, Serialize)]
|
#[derive(Clone, Deserialize, Debug, strum::Display, Serialize)]
|
||||||
|
|||||||
Reference in New Issue
Block a user