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

feat(events): taking request and response both for detail extraction for kafka events (#9993)

Shivansh Mathure97c9c28c893
diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs
index dab94e13df..c72f5dba64 100644
--- a/crates/router/src/services/api.rs
+++ b/crates/router/src/services/api.rs
@@ -318,8 +318,13 @@ where
}
};
+ let values: Vec<&serde_json::Value> = [Some(&serialized_request), serialized_response.as_ref()]
+ .into_iter()
+ .flatten()
+ .collect();
+
let infra = extract_mapped_fields(
- &serialized_request,
+ &values,
state.enhancement.as_ref(),
state.infra_components.as_ref(),
);
@@ -1854,7 +1859,7 @@ pub fn get_payment_link_status(
}
pub fn extract_mapped_fields(
- value: &serde_json::Value,
+ values: &[&serde_json::Value],
mapping: Option<&HashMap<String, String>>,
existing_enhancement: Option<&serde_json::Value>,
) -> Option<serde_json::Value> {
@@ -1870,9 +1875,19 @@ pub fn extract_mapped_fields(
};
for (dot_path, output_key) in mapping {
- if let Some(extracted_value) = extract_field_by_dot_path(value, dot_path) {
+ let mut extracted_value = None;
+
+ // Try to extract from values in order of priority
+ for value in values {
+ if let Some(found_value) = extract_field_by_dot_path(value, dot_path) {
+ extracted_value = Some(found_value);
+ break;
+ }
+ }
+
+ if let Some(value) = extracted_value {
if let Some(obj) = enhancement.as_object_mut() {
- obj.insert(output_key.clone(), extracted_value);
+ obj.insert(output_key.clone(), value);
}
}
}