diff --git a/crates/router/src/connector/bluesnap/transformers.rs b/crates/router/src/connector/bluesnap/transformers.rs index 17cdf3b519bb..e98b98e874aa 100644 --- a/crates/router/src/connector/bluesnap/transformers.rs +++ b/crates/router/src/connector/bluesnap/transformers.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use api_models::{enums as api_enums, payments}; use base64::Engine; use common_utils::{ @@ -8,6 +10,7 @@ use common_utils::{ use error_stack::{IntoReport, ResultExt}; use masking::{ExposeInterface, PeekInterface}; use serde::{Deserialize, Serialize}; +use serde_json::Value; use crate::{ connector::utils::{ @@ -17,10 +20,16 @@ use crate::{ consts, core::errors, pii::Secret, - types::{self, api, storage::enums, transformers::ForeignTryFrom}, + types::{ + self, api, + storage::enums, + transformers::{ForeignFrom, ForeignTryFrom}, + }, utils::{Encode, OptionExt}, }; +const DISPLAY_METADATA: &str = "Y"; + #[derive(Debug, Serialize)] pub struct BluesnapRouterData { pub amount: String, @@ -63,6 +72,21 @@ pub struct BluesnapPaymentsRequest { transaction_fraud_info: Option, card_holder_info: Option, merchant_transaction_id: Option, + transaction_meta_data: Option, +} + +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct BluesnapMetadata { + meta_data: Vec, +} + +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RequestMetadata { + meta_key: Option, + meta_value: Option, + is_visible: Option, } #[derive(Debug, Serialize)] @@ -241,6 +265,15 @@ impl TryFrom<&BluesnapRouterData<&types::PaymentsAuthorizeRouterData>> for Blues Some(enums::CaptureMethod::Manual) => BluesnapTxnType::AuthOnly, _ => BluesnapTxnType::AuthCapture, }; + let transaction_meta_data = + item.router_data + .request + .metadata + .as_ref() + .map(|metadata| BluesnapMetadata { + meta_data: Vec::::foreign_from(metadata.peek().to_owned()), + }); + let (payment_method, card_holder_info) = match item .router_data .request @@ -405,6 +438,7 @@ impl TryFrom<&BluesnapRouterData<&types::PaymentsAuthorizeRouterData>> for Blues }), card_holder_info, merchant_transaction_id: Some(item.router_data.connector_request_reference_id.clone()), + transaction_meta_data, }) } } @@ -569,6 +603,7 @@ pub struct BluesnapCompletePaymentsRequest { transaction_fraud_info: Option, card_holder_info: Option, merchant_transaction_id: Option, + transaction_meta_data: Option, } impl TryFrom<&BluesnapRouterData<&types::PaymentsCompleteAuthorizeRouterData>> @@ -590,6 +625,15 @@ impl TryFrom<&BluesnapRouterData<&types::PaymentsCompleteAuthorizeRouterData>> .parse_value("BluesnapRedirectionResponse") .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; + let transaction_meta_data = + item.router_data + .request + .metadata + .as_ref() + .map(|metadata| BluesnapMetadata { + meta_data: Vec::::foreign_from(metadata.peek().to_owned()), + }); + let pf_token = item .router_data .request @@ -637,6 +681,7 @@ impl TryFrom<&BluesnapRouterData<&types::PaymentsCompleteAuthorizeRouterData>> )?, merchant_transaction_id: Some(item.router_data.connector_request_reference_id.clone()), pf_token, + transaction_meta_data, }) } } @@ -1021,7 +1066,7 @@ pub struct BluesnapWebhookObjectResource { reversal_ref_num: Option, } -impl TryFrom for serde_json::Value { +impl TryFrom for Value { type Error = error_stack::Report; fn try_from(details: BluesnapWebhookObjectResource) -> Result { let (card_transaction_type, processing_status, transaction_id) = match details @@ -1118,3 +1163,19 @@ impl From for utils::ErrorCodeAndMessage { } } } + +impl ForeignFrom for Vec { + fn foreign_from(metadata: Value) -> Self { + let hashmap: HashMap, Option> = + serde_json::from_str(&metadata.to_string()).unwrap_or(HashMap::new()); + let mut vector: Self = Self::new(); + for (key, value) in hashmap { + vector.push(RequestMetadata { + meta_key: key, + meta_value: value.map(|field_value| field_value.to_string()), + is_visible: Some(DISPLAY_METADATA.to_string()), + }); + } + vector + } +}