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
fix(router): hotfixes for stripe webhook event mapping and reference id retrieval (#1368)
ItsMeShashank5c2232b737f5
diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rsindex 0aea295b17..12d38fc1c2 100644--- a/crates/router/src/connector/stripe.rs+++ b/crates/router/src/connector/stripe.rs@@ -1666,9 +1666,15 @@ impl api::IncomingWebhook for Stripe {.change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;Ok(match details.event_data.event_object.object {- stripe::WebhookEventObjectType::PaymentIntent- | stripe::WebhookEventObjectType::Charge- | stripe::WebhookEventObjectType::Dispute => {+ stripe::WebhookEventObjectType::PaymentIntent => {+ api_models::webhooks::ObjectReferenceId::PaymentId(+ api_models::payments::PaymentIdType::ConnectorTransactionId(+ details.event_data.event_object.id,+ ),+ )+ }++ stripe::WebhookEventObjectType::Charge | stripe::WebhookEventObjectType::Dispute => {api_models::webhooks::ObjectReferenceId::PaymentId(api_models::payments::PaymentIdType::ConnectorTransactionId(details@@ -1693,7 +1699,7 @@ impl api::IncomingWebhook for Stripe {&self,request: &api::IncomingWebhookRequestDetails<'_>,) -> CustomResult<api::IncomingWebhookEvent, errors::ConnectorError> {- let details: stripe::WebhookEvent = request+ let details: stripe::WebhookEventTypeBody = request.body.parse_struct("WebhookEvent").change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;@@ -1705,21 +1711,27 @@ impl api::IncomingWebhook for Stripe {stripe::WebhookEventType::PaymentIntentSucceed => {api::IncomingWebhookEvent::PaymentIntentSuccess}+ stripe::WebhookEventType::ChargeSucceeded => {+ if let Some(stripe::WebhookPaymentMethodDetails {+ payment_method: stripe::WebhookPaymentMethodType::AchCreditTransfer,+ }) = details.event_data.event_object.payment_method_details+ {+ api::IncomingWebhookEvent::PaymentIntentSuccess+ } else {+ api::IncomingWebhookEvent::EventNotSupported+ }+ }stripe::WebhookEventType::SourceChargeable => {api::IncomingWebhookEvent::SourceChargeable}- stripe::WebhookEventType::ChargeSucceeded => {- api::IncomingWebhookEvent::PaymentIntentSuccess- }stripe::WebhookEventType::DisputeCreated => api::IncomingWebhookEvent::DisputeOpened,stripe::WebhookEventType::DisputeClosed => api::IncomingWebhookEvent::DisputeCancelled,- stripe::WebhookEventType::DisputeUpdated => api::IncomingWebhookEvent::try_from(- details- .event_data- .event_object- .status- .ok_or(errors::ConnectorError::WebhookEventTypeNotFound)?,- )?,+ stripe::WebhookEventType::DisputeUpdated => details+ .event_data+ .event_object+ .status+ .map(Into::into)+ .unwrap_or(api::IncomingWebhookEvent::EventNotSupported),stripe::WebhookEventType::PaymentIntentPartiallyFunded => {api::IncomingWebhookEvent::PaymentIntentPartiallyFunded}diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rsindex 911cd9f593..caa695837e 100644--- a/crates/router/src/connector/stripe/transformers.rs+++ b/crates/router/src/connector/stripe/transformers.rs@@ -566,17 +566,27 @@ pub enum StripeBankNames {Boz,}-impl TryFrom<WebhookEventStatus> for api_models::webhooks::IncomingWebhookEvent {- type Error = errors::ConnectorError;- fn try_from(value: WebhookEventStatus) -> Result<Self, Self::Error> {- Ok(match value {+impl From<WebhookEventStatus> for api_models::webhooks::IncomingWebhookEvent {+ fn from(value: WebhookEventStatus) -> Self {+ match value {WebhookEventStatus::WarningNeedsResponse => Self::DisputeOpened,WebhookEventStatus::WarningClosed => Self::DisputeCancelled,WebhookEventStatus::WarningUnderReview => Self::DisputeChallenged,WebhookEventStatus::Won => Self::DisputeWon,WebhookEventStatus::Lost => Self::DisputeLost,- _ => Err(errors::ConnectorError::WebhookEventTypeNotFound)?,- })+ WebhookEventStatus::NeedsResponse+ | WebhookEventStatus::UnderReview+ | WebhookEventStatus::ChargeRefunded+ | WebhookEventStatus::Succeeded+ | WebhookEventStatus::RequiresPaymentMethod+ | WebhookEventStatus::RequiresConfirmation+ | WebhookEventStatus::RequiresAction+ | WebhookEventStatus::Processing+ | WebhookEventStatus::RequiresCapture+ | WebhookEventStatus::Canceled+ | WebhookEventStatus::Chargeable+ | WebhookEventStatus::Unknown => Self::EventNotSupported,+ }}}@@ -2297,12 +2307,46 @@ pub struct WebhookEvent {pub event_data: WebhookEventData,}+#[derive(Debug, Deserialize)]+pub struct WebhookEventTypeBody {+ #[serde(rename = "type")]+ pub event_type: WebhookEventType,+ #[serde(rename = "data")]+ pub event_data: WebhookStatusData,+}+#[derive(Debug, Deserialize)]pub struct WebhookEventData {#[serde(rename = "object")]pub event_object: WebhookEventObjectData,}+#[derive(Debug, Deserialize)]+pub struct WebhookStatusData {+ #[serde(rename = "object")]+ pub event_object: WebhookStatusObjectData,+}++#[derive(Debug, Deserialize)]+pub struct WebhookStatusObjectData {+ pub status: Option<WebhookEventStatus>,+ pub payment_method_details: Option<WebhookPaymentMethodDetails>,+}++#[derive(Debug, Deserialize)]+#[serde(rename_all = "snake_case")]+pub enum WebhookPaymentMethodType {+ AchCreditTransfer,+ #[serde(other)]+ Unknown,+}++#[derive(Debug, Deserialize)]+pub struct WebhookPaymentMethodDetails {+ #[serde(rename = "type")]+ pub payment_method: WebhookPaymentMethodType,+}+#[derive(Debug, Deserialize)]pub struct WebhookEventObjectData {pub id: String,@@ -2397,6 +2441,8 @@ pub enum WebhookEventStatus {RequiresCapture,Canceled,Chargeable,+ #[serde(other)]+ Unknown,}#[derive(Debug, Deserialize, PartialEq)]