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(connectors): Mask fields for webhook_resource_object (#4400)
Sakil Mostak110bf22511cf
diff --git a/crates/router/src/connector/checkout.rs b/crates/router/src/connector/checkout.rsindex ee4e04e7b1..3c628fe9ec 100644--- a/crates/router/src/connector/checkout.rs+++ b/crates/router/src/connector/checkout.rs@@ -2,11 +2,7 @@ pub mod transformers;use std::fmt::Debug;-use common_utils::{- crypto,- ext_traits::{ByteSliceExt, Encode},- request::RequestContent,-};+use common_utils::{crypto, ext_traits::ByteSliceExt, request::RequestContent};use diesel_models::enums;use error_stack::ResultExt;use masking::PeekInterface;@@ -1295,27 +1291,19 @@ impl api::IncomingWebhook for Checkout {let event_type_data: checkout::CheckoutWebhookEventTypeBody = request.body.parse_struct("CheckoutWebhookBody")- .change_context(errors::ConnectorError::WebhookEventTypeNotFound)?;- let resource_object = if checkout::is_chargeback_event(&event_type_data.transaction_type)- || checkout::is_refund_event(&event_type_data.transaction_type)- {- // if other event, just return the json data.- let resource_object_data: checkout::CheckoutWebhookObjectResource = request+ .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;++ if checkout::is_chargeback_event(&event_type_data.transaction_type) {+ let dispute_webhook_body: checkout::CheckoutDisputeWebhookBody = request.body- .parse_struct("CheckoutWebhookObjectResource")- .change_context(errors::ConnectorError::WebhookEventTypeNotFound)?;- resource_object_data.data+ .parse_struct("CheckoutDisputeWebhookBody")+ .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;+ Ok(Box::new(dispute_webhook_body.data))+ } else if checkout::is_refund_event(&event_type_data.transaction_type) {+ Ok(Box::new(checkout::RefundResponse::try_from(request)?))} else {- // if payment_event, construct PaymentResponse and then serialize it to json and return.- let payment_response = checkout::PaymentsResponse::try_from(request)?;- payment_response- .encode_to_value()- .change_context(errors::ConnectorError::WebhookResourceObjectNotFound)?- };- // Ideally this should be a strict type that has type information- // PII information is likely being logged here when this response will be logged.-- Ok(Box::new(resource_object))+ Ok(Box::new(checkout::PaymentsResponse::try_from(request)?))+ }}fn get_dispute_details(diff --git a/crates/router/src/connector/checkout/transformers.rs b/crates/router/src/connector/checkout/transformers.rsindex a1a4a0095f..3fff6d940d 100644--- a/crates/router/src/connector/checkout/transformers.rs+++ b/crates/router/src/connector/checkout/transformers.rs@@ -1237,7 +1237,7 @@ pub struct CheckoutWebhookBody {pub links: Links,}-#[derive(Debug, Deserialize)]+#[derive(Debug, Serialize, Deserialize)]pub struct CheckoutDisputeWebhookData {pub id: String,pub payment_id: Option<String>,@@ -1382,7 +1382,7 @@ impl TryFrom<&api::IncomingWebhookRequestDetails<'_>> for PaymentsResponse {let details: CheckoutWebhookBody = request.body.parse_struct("CheckoutWebhookBody")- .change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;+ .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;let data = details.data;let psync_struct = Self {id: data.payment_id.unwrap_or(data.id),@@ -1403,6 +1403,28 @@ impl TryFrom<&api::IncomingWebhookRequestDetails<'_>> for PaymentsResponse {}}+impl TryFrom<&api::IncomingWebhookRequestDetails<'_>> for RefundResponse {+ type Error = error_stack::Report<errors::ConnectorError>;++ fn try_from(request: &api::IncomingWebhookRequestDetails<'_>) -> Result<Self, Self::Error> {+ let details: CheckoutWebhookBody = request+ .body+ .parse_struct("CheckoutWebhookBody")+ .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;+ let data = details.data;+ let refund_struct = Self {+ action_id: data+ .action_id+ .ok_or(errors::ConnectorError::WebhookBodyDecodingFailed)?,+ reference: data+ .reference+ .ok_or(errors::ConnectorError::WebhookBodyDecodingFailed)?,+ };++ Ok(refund_struct)+ }+}+impl TryFrom<&types::SubmitEvidenceRouterData> for Evidence {type Error = error_stack::Report<errors::ConnectorError>;fn try_from(item: &types::SubmitEvidenceRouterData) -> Result<Self, Self::Error> {diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rsindex 79b3c3e239..e499cdda12 100644--- a/crates/router/src/connector/stripe.rs+++ b/crates/router/src/connector/stripe.rs@@ -2172,12 +2172,12 @@ impl api::IncomingWebhook for Stripe {&self,request: &api::IncomingWebhookRequestDetails<'_>,) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> {- let details: stripe::WebhookEventObjectResource = request+ let details: stripe::WebhookEvent = request.body- .parse_struct("WebhookEventObjectResource")- .change_context(errors::ConnectorError::WebhookResourceObjectNotFound)?;+ .parse_struct("WebhookEvent")+ .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;- Ok(Box::new(details.data.object))+ Ok(Box::new(details.event_data.event_object))}fn get_dispute_details(&self,diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rsindex 5a5210517e..a7577632ba 100644--- a/crates/router/src/connector/stripe/transformers.rs+++ b/crates/router/src/connector/stripe/transformers.rs@@ -3536,13 +3536,14 @@ pub struct WebhookPaymentMethodDetails {pub payment_method: WebhookPaymentMethodType,}-#[derive(Debug, Clone, Deserialize)]+#[derive(Debug, Clone, Serialize, Deserialize)]pub struct WebhookEventObjectData {pub id: String,pub object: WebhookEventObjectType,pub amount: Option<i32>,pub currency: String,pub payment_intent: Option<String>,+ pub client_secret: Option<Secret<String>>,pub reason: Option<String>,#[serde(with = "common_utils::custom_serde::timestamp")]pub created: PrimitiveDateTime,@@ -3551,7 +3552,7 @@ pub struct WebhookEventObjectData {pub metadata: Option<StripeMetadata>,}-#[derive(Debug, Clone, Deserialize, strum::Display)]+#[derive(Debug, Clone, Serialize, Deserialize, strum::Display)]#[serde(rename_all = "snake_case")]pub enum WebhookEventObjectType {PaymentIntent,@@ -3637,7 +3638,7 @@ pub enum WebhookEventStatus {Unknown,}-#[derive(Debug, Clone, Deserialize, PartialEq)]+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]pub struct EvidenceDetails {#[serde(with = "common_utils::custom_serde::timestamp")]pub due_by: PrimitiveDateTime,diff --git a/crates/router/src/core/webhooks.rs b/crates/router/src/core/webhooks.rsindex 14ec842a90..d236ad094c 100644--- a/crates/router/src/core/webhooks.rs+++ b/crates/router/src/core/webhooks.rs@@ -1449,6 +1449,8 @@ pub async fn webhooks_wrapper<W: types::OutgoingWebhookType, Ctx: PaymentMethodR)).await?;+ logger::info!(incoming_webhook_payload = ?serialized_req);+let request_duration = Instant::now().saturating_duration_since(start_instant).as_millis();diff --git a/crates/router/src/routes/webhooks.rs b/crates/router/src/routes/webhooks.rsindex 03fe6a1d75..073b1c5700 100644--- a/crates/router/src/routes/webhooks.rs+++ b/crates/router/src/routes/webhooks.rs@@ -25,8 +25,8 @@ pub async fn receive_incoming_webhook<W: types::OutgoingWebhookType>(flow.clone(),state,&req,- WebhookBytes(body),- |state, auth, payload, req_state| {+ (),+ |state, auth, _, req_state| {webhooks::webhooks_wrapper::<W, Oss>(&flow,state.to_owned(),@@ -35,7 +35,7 @@ pub async fn receive_incoming_webhook<W: types::OutgoingWebhookType>(auth.merchant_account,auth.key_store,&connector_id_or_name,- payload.0,+ body.clone(),)},&auth::MerchantIdAuth(merchant_id),diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rsindex df3d91bc01..30c3ce164e 100644--- a/crates/router/src/services/api.rs+++ b/crates/router/src/services/api.rs@@ -386,7 +386,6 @@ where.await;let external_latency = current_time.elapsed().as_millis();logger::info!(raw_connector_request=?masked_request_body);- logger::info!(raw_connector_response=?response);let status_code = response.as_ref().map(|i| {