diff --git a/crates/router/src/connector/cryptopay/transformers.rs b/crates/router/src/connector/cryptopay/transformers.rs index aaf21af05825..e6db0cf320cc 100644 --- a/crates/router/src/connector/cryptopay/transformers.rs +++ b/crates/router/src/connector/cryptopay/transformers.rs @@ -4,7 +4,7 @@ use reqwest::Url; use serde::{Deserialize, Serialize}; use crate::{ - connector::utils::{self, is_payment_failure, CryptoData}, + connector::utils::{self, is_payment_failure, CryptoData, PaymentsAuthorizeRequestData}, consts, core::errors, services, @@ -70,7 +70,8 @@ impl TryFrom<&CryptopayRouterData<&types::PaymentsAuthorizeRouterData>> pay_currency, success_redirect_url: item.router_data.request.router_return_url.clone(), unsuccess_redirect_url: item.router_data.request.router_return_url.clone(), - metadata: item.router_data.request.metadata.clone(), + //Cryptopay only accepts metadata as Object. If any other type, payment will fail with error. + metadata: item.router_data.request.get_metadata_as_object(), custom_id: item.router_data.connector_request_reference_id.clone(), }) } diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index 5bdf8b501ad7..3edaa319fb5f 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -498,6 +498,7 @@ pub trait PaymentsAuthorizeRequestData { fn get_surcharge_amount(&self) -> Option; fn get_tax_on_surcharge_amount(&self) -> Option; fn get_total_surcharge_amount(&self) -> Option; + fn get_metadata_as_object(&self) -> Option; } pub trait PaymentMethodTokenizationRequestData { @@ -632,6 +633,19 @@ impl PaymentsAuthorizeRequestData for types::PaymentsAuthorizeData { fn is_customer_initiated_mandate_payment(&self) -> bool { self.setup_mandate_details.is_some() } + + fn get_metadata_as_object(&self) -> Option { + self.metadata + .clone() + .and_then(|meta_data| match meta_data.peek() { + serde_json::Value::Null + | serde_json::Value::Bool(_) + | serde_json::Value::Number(_) + | serde_json::Value::String(_) + | serde_json::Value::Array(_) => None, + serde_json::Value::Object(_) => Some(meta_data), + }) + } } pub trait ConnectorCustomerData {