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(connector): [gigadat] make strict type and mask gigadat webhook payload (#10633)
Nithin Na67341bd6201
diff --git a/crates/hyperswitch_connectors/src/connectors/gigadat.rs b/crates/hyperswitch_connectors/src/connectors/gigadat.rsindex bc423e3951..d5e99b67fe 100644--- a/crates/hyperswitch_connectors/src/connectors/gigadat.rs+++ b/crates/hyperswitch_connectors/src/connectors/gigadat.rs@@ -60,7 +60,6 @@ use masking::{Mask, PeekInterface};#[cfg(feature = "payouts")]use router_env::{instrument, tracing};use transformers as gigadat;-use url::form_urlencoded;use uuid::Uuid;#[cfg(feature = "payouts")]@@ -959,20 +958,10 @@ impl webhooks::IncomingWebhook for Gigadat {let body_str = std::str::from_utf8(request.body).change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;- let details: Vec<transformers::GigadatWebhookKeyValue> =- form_urlencoded::parse(body_str.as_bytes())- .map(|(key, value)| transformers::GigadatWebhookKeyValue {- key: key.to_string(),- value: value.to_string(),- })- .collect();+ let details = transformers::GigadatWebhookKeyValueBody::decode_from_url(body_str)?;+ let webhook_type = details.webhook_type;- let webhook_type = details- .iter()- .find(|&entry| entry.key == "type")- .ok_or(errors::ConnectorError::WebhookBodyDecodingFailed)?;-- let reference_id = match transformers::GigadatFlow::get_flow(webhook_type.value.as_str())? {+ let reference_id = match transformers::GigadatFlow::get_flow(&webhook_type)? {transformers::GigadatFlow::Payment => {api_models::webhooks::ObjectReferenceId::PaymentId(api_models::payments::PaymentIdType::ConnectorTransactionId(@@ -996,20 +985,11 @@ impl webhooks::IncomingWebhook for Gigadat {let body_str = std::str::from_utf8(request.body).change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;- let details: Vec<transformers::GigadatWebhookKeyValue> =- form_urlencoded::parse(body_str.as_bytes())- .map(|(key, value)| transformers::GigadatWebhookKeyValue {- key: key.to_string(),- value: value.to_string(),- })- .collect();+ let details = transformers::GigadatWebhookKeyValueBody::decode_from_url(body_str)?;- let webhook_type = details- .iter()- .find(|&entry| entry.key == "type")- .ok_or(errors::ConnectorError::WebhookBodyDecodingFailed)?;+ let webhook_type = details.webhook_type;- let flow_type = transformers::GigadatFlow::get_flow(webhook_type.value.as_str())?;+ let flow_type = transformers::GigadatFlow::get_flow(&webhook_type)?;let event_type =transformers::get_gigadat_webhook_event_type(query_params.status, flow_type);Ok(event_type)@@ -1022,16 +1002,8 @@ impl webhooks::IncomingWebhook for Gigadat {let body_str = std::str::from_utf8(request.body).change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;- let details: Vec<transformers::GigadatWebhookKeyValue> =- form_urlencoded::parse(body_str.as_bytes())- .map(|(key, value)| transformers::GigadatWebhookKeyValue {- key: key.to_string(),- value: value.to_string(),- })- .collect();- let resource_object = serde_json::to_string(&details)- .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;- Ok(Box::new(resource_object))+ let details = transformers::GigadatWebhookKeyValueBody::decode_from_url(body_str)?;+ Ok(Box::new(details))}async fn verify_webhook_source(&self,diff --git a/crates/hyperswitch_connectors/src/connectors/gigadat/transformers.rs b/crates/hyperswitch_connectors/src/connectors/gigadat/transformers.rsindex 1526c65087..cb1719265f 100644--- a/crates/hyperswitch_connectors/src/connectors/gigadat/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/gigadat/transformers.rs@@ -623,7 +623,23 @@ pub struct GigadatWebhookQueryParameters {}#[derive(Debug, Serialize, Deserialize)]-pub struct GigadatWebhookKeyValue {- pub key: String,- pub value: String,+#[serde(rename_all = "camelCase")]+pub struct GigadatWebhookKeyValueBody {+ #[serde(rename = "type")]+ pub webhook_type: String,+ pub final_type: Option<String>,+ pub cpi_type: Option<String>,+ // donot remove the below fields+ pub name: Option<Secret<String>>,+ pub mobile: Option<Secret<String>>,+ pub user_id: Option<Secret<String>>,+ pub email: Option<Secret<String>>,+ pub financial_institution: Option<Secret<String>>,+}++impl GigadatWebhookKeyValueBody {+ pub fn decode_from_url(body_str: &str) -> Result<Self, errors::ConnectorError> {+ serde_urlencoded::from_str(body_str)+ .map_err(|_| errors::ConnectorError::WebhookBodyDecodingFailed)+ }}