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(router): fix webhooks flow for checkout connector (#1126)

ItsMeShashank7f3ceb42fb95
diff --git a/crates/router/src/connector/checkout.rs b/crates/router/src/connector/checkout.rs
index aba8556626..707e4360a7 100644
--- a/crates/router/src/connector/checkout.rs
+++ b/crates/router/src/connector/checkout.rs
@@ -1075,11 +1075,16 @@ impl api::IncomingWebhook for Checkout {
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
- let secret = db
- .find_config_by_key(&key)
- .await
- .change_context(errors::ConnectorError::WebhookVerificationSecretNotFound)?;
- Ok(secret.config.into_bytes())
+ let secret = match db.find_config_by_key(&key).await {
+ Ok(config) => Some(config),
+ Err(e) => {
+ crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
+ None
+ }
+ };
+ Ok(secret
+ .map(|conf| conf.config.into_bytes())
+ .unwrap_or_default())
}
fn get_webhook_object_reference_id(
&self,
@@ -1143,7 +1148,7 @@ impl api::IncomingWebhook for Checkout {
&self,
request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api::disputes::DisputePayload, errors::ConnectorError> {
- let dispute_details: checkout::CheckoutWebhookBody = request
+ let dispute_details: checkout::CheckoutDisputeWebhookBody = request
.body
.parse_struct("CheckoutWebhookBody")
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
diff --git a/crates/router/src/connector/checkout/transformers.rs b/crates/router/src/connector/checkout/transformers.rs
index 98c24dcc3c..fdf06eeea2 100644
--- a/crates/router/src/connector/checkout/transformers.rs
+++ b/crates/router/src/connector/checkout/transformers.rs
@@ -710,15 +710,33 @@ pub struct CheckoutWebhookData {
pub action_id: Option<String>,
pub amount: i32,
pub currency: String,
+}
+#[derive(Debug, Deserialize)]
+pub struct CheckoutWebhookBody {
+ #[serde(rename = "type")]
+ pub transaction_type: CheckoutTransactionType,
+ pub data: CheckoutWebhookData,
+}
+
+#[derive(Debug, Deserialize)]
+pub struct CheckoutDisputeWebhookData {
+ pub id: String,
+ pub payment_id: Option<String>,
+ pub action_id: Option<String>,
+ pub amount: i32,
+ pub currency: String,
+ #[serde(with = "common_utils::custom_serde::iso8601::option")]
pub evidence_required_by: Option<PrimitiveDateTime>,
pub reason_code: Option<String>,
+ #[serde(with = "common_utils::custom_serde::iso8601::option")]
pub date: Option<PrimitiveDateTime>,
}
#[derive(Debug, Deserialize)]
-pub struct CheckoutWebhookBody {
+pub struct CheckoutDisputeWebhookBody {
#[serde(rename = "type")]
pub transaction_type: CheckoutTransactionType,
- pub data: CheckoutWebhookData,
+ pub data: CheckoutDisputeWebhookData,
+ #[serde(with = "common_utils::custom_serde::iso8601::option")]
pub created_on: Option<PrimitiveDateTime>,
}
#[derive(Debug, Deserialize, strum::Display, Clone)]