Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions crates/router/src/connector/stripe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions crates/router/src/connector/stripe/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()),
},
})
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading