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

fix(connector): [Stripe] Deserialization Error while parsing Dispute Webhook Body (#3256)

Sakil Mostak01b4ac30e40a
diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rs
index 65fd652629..8c43e2c16a 100644
--- a/crates/router/src/connector/stripe.rs
+++ b/crates/router/src/connector/stripe.rs
@@ -1858,10 +1858,15 @@ impl api::IncomingWebhook for Stripe {
Ok(match details.event_data.event_object.object {
stripe::WebhookEventObjectType::PaymentIntent => {
- match details.event_data.event_object.metadata {
+ match details
+ .event_data
+ .event_object
+ .metadata
+ .and_then(|meta_data| meta_data.order_id)
+ {
// if order_id is present
- Some(meta_data) => api_models::webhooks::ObjectReferenceId::PaymentId(
- api_models::payments::PaymentIdType::PaymentAttemptId(meta_data.order_id),
+ Some(order_id) => api_models::webhooks::ObjectReferenceId::PaymentId(
+ api_models::payments::PaymentIdType::PaymentAttemptId(order_id),
),
// else used connector_transaction_id
None => api_models::webhooks::ObjectReferenceId::PaymentId(
@@ -1872,10 +1877,15 @@ impl api::IncomingWebhook for Stripe {
}
}
stripe::WebhookEventObjectType::Charge => {
- match details.event_data.event_object.metadata {
+ match details
+ .event_data
+ .event_object
+ .metadata
+ .and_then(|meta_data| meta_data.order_id)
+ {
// if order_id is present
- Some(meta_data) => api_models::webhooks::ObjectReferenceId::PaymentId(
- api_models::payments::PaymentIdType::PaymentAttemptId(meta_data.order_id),
+ Some(order_id) => api_models::webhooks::ObjectReferenceId::PaymentId(
+ api_models::payments::PaymentIdType::PaymentAttemptId(order_id),
),
// else used connector_transaction_id
None => api_models::webhooks::ObjectReferenceId::PaymentId(
@@ -1908,14 +1918,25 @@ impl api::IncomingWebhook for Stripe {
)
}
stripe::WebhookEventObjectType::Refund => {
- match details.event_data.event_object.metadata {
+ match details
+ .event_data
+ .event_object
+ .metadata
+ .clone()
+ .and_then(|meta_data| meta_data.order_id)
+ {
// if meta_data is present
- Some(meta_data) => {
+ Some(order_id) => {
// Issue: 2076
- match meta_data.is_refund_id_as_reference {
+ match details
+ .event_data
+ .event_object
+ .metadata
+ .and_then(|meta_data| meta_data.is_refund_id_as_reference)
+ {
// if the order_id is refund_id
Some(_) => api_models::webhooks::ObjectReferenceId::RefundId(
- api_models::webhooks::RefundIdType::RefundId(meta_data.order_id),
+ api_models::webhooks::RefundIdType::RefundId(order_id),
),
// if the order_id is payment_id
// since payment_id was being passed before the deployment of this pr
diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs
index ba5dfc7fef..4338e8f9ff 100644
--- a/crates/router/src/connector/stripe/transformers.rs
+++ b/crates/router/src/connector/stripe/transformers.rs
@@ -135,7 +135,7 @@ pub struct PaymentIntentRequest {
pub struct StripeMetadata {
// merchant_reference_id
#[serde(rename(serialize = "metadata[order_id]"))]
- pub order_id: String,
+ pub order_id: Option<String>,
// to check whether the order_id is refund_id or payemnt_id
// before deployment, order id is set to payemnt_id in refunds but now it is set as refund_id
// it is set as string instead of bool because stripe pass it as string even if we set it as bool
@@ -1861,7 +1861,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
statement_descriptor_suffix: item.request.statement_descriptor_suffix.clone(),
statement_descriptor: item.request.statement_descriptor.clone(),
meta_data: StripeMetadata {
- order_id,
+ order_id: Some(order_id),
is_refund_id_as_reference: None,
},
return_url: item
@@ -2696,7 +2696,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for RefundRequest {
amount: Some(amount),
payment_intent,
meta_data: StripeMetadata {
- order_id: item.request.refund_id.clone(),
+ order_id: Some(item.request.refund_id.clone()),
is_refund_id_as_reference: Some("true".to_string()),
},
})
@@ -3203,7 +3203,7 @@ pub struct WebhookPaymentMethodDetails {
pub payment_method: WebhookPaymentMethodType,
}
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Clone, Deserialize)]
pub struct WebhookEventObjectData {
pub id: String,
pub object: WebhookEventObjectType,
@@ -3218,7 +3218,7 @@ pub struct WebhookEventObjectData {
pub metadata: Option<StripeMetadata>,
}
-#[derive(Debug, Deserialize, strum::Display)]
+#[derive(Debug, Clone, Deserialize, strum::Display)]
#[serde(rename_all = "snake_case")]
pub enum WebhookEventObjectType {
PaymentIntent,
@@ -3280,7 +3280,7 @@ pub enum WebhookEventType {
Unknown,
}
-#[derive(Debug, Serialize, strum::Display, Deserialize, PartialEq)]
+#[derive(Debug, Clone, Serialize, strum::Display, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum WebhookEventStatus {
WarningNeedsResponse,
@@ -3304,7 +3304,7 @@ pub enum WebhookEventStatus {
Unknown,
}
-#[derive(Debug, Deserialize, PartialEq)]
+#[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct EvidenceDetails {
#[serde(with = "common_utils::custom_serde::timestamp")]
pub due_by: PrimitiveDateTime,