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

refactor(connector): [AUTHORIZEDOTNET] Add metadata information to connector request (#7011)

Debarshi Guptaea1888677df7
diff --git a/crates/router/src/connector/authorizedotnet/transformers.rs b/crates/router/src/connector/authorizedotnet/transformers.rs
index d2b212e3ea..8e0af603a3 100644
--- a/crates/router/src/connector/authorizedotnet/transformers.rs
+++ b/crates/router/src/connector/authorizedotnet/transformers.rs
@@ -1,3 +1,5 @@
+use std::collections::BTreeMap;
+
use common_utils::{
errors::CustomResult,
ext_traits::{Encode, ValueExt},
@@ -6,6 +8,7 @@ use error_stack::ResultExt;
use masking::{ExposeInterface, PeekInterface, Secret, StrongSecret};
use rand::distributions::{Alphanumeric, DistString};
use serde::{Deserialize, Serialize};
+use serde_json::Value;
use crate::{
connector::utils::{
@@ -143,12 +146,27 @@ struct TransactionRequest {
#[serde(skip_serializing_if = "Option::is_none")]
bill_to: Option<BillTo>,
#[serde(skip_serializing_if = "Option::is_none")]
+ user_fields: Option<UserFields>,
+ #[serde(skip_serializing_if = "Option::is_none")]
processing_options: Option<ProcessingOptions>,
#[serde(skip_serializing_if = "Option::is_none")]
subsequent_auth_information: Option<SubsequentAuthInformation>,
authorization_indicator_type: Option<AuthorizationIndicator>,
}
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct UserFields {
+ user_field: Vec<UserField>,
+}
+
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct UserField {
+ name: String,
+ value: String,
+}
+
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
enum ProfileDetails {
@@ -299,6 +317,25 @@ pub enum ValidationMode {
LiveMode,
}
+impl ForeignTryFrom<Value> for Vec<UserField> {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn foreign_try_from(metadata: Value) -> Result<Self, Self::Error> {
+ let hashmap: BTreeMap<String, Value> = serde_json::from_str(&metadata.to_string())
+ .change_context(errors::ConnectorError::RequestEncodingFailedWithReason(
+ "Failed to serialize request metadata".to_owned(),
+ ))
+ .attach_printable("")?;
+ let mut vector: Self = Self::new();
+ for (key, value) in hashmap {
+ vector.push(UserField {
+ name: key,
+ value: value.to_string(),
+ });
+ }
+ Ok(vector)
+ }
+}
+
impl TryFrom<&types::SetupMandateRouterData> for CreateCustomerProfileRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &types::SetupMandateRouterData) -> Result<Self, Self::Error> {
@@ -622,6 +659,12 @@ impl
zip: address.zip.clone(),
country: address.country,
}),
+ user_fields: match item.router_data.request.metadata.clone() {
+ Some(metadata) => Some(UserFields {
+ user_field: Vec::<UserField>::foreign_try_from(metadata)?,
+ }),
+ None => None,
+ },
processing_options: Some(ProcessingOptions {
is_subsequent_auth: true,
}),
@@ -675,6 +718,12 @@ impl
},
customer: None,
bill_to: None,
+ user_fields: match item.router_data.request.metadata.clone() {
+ Some(metadata) => Some(UserFields {
+ user_field: Vec::<UserField>::foreign_try_from(metadata)?,
+ }),
+ None => None,
+ },
processing_options: Some(ProcessingOptions {
is_subsequent_auth: true,
}),
@@ -764,6 +813,12 @@ impl
zip: address.zip.clone(),
country: address.country,
}),
+ user_fields: match item.router_data.request.metadata.clone() {
+ Some(metadata) => Some(UserFields {
+ user_field: Vec::<UserField>::foreign_try_from(metadata)?,
+ }),
+ None => None,
+ },
processing_options: None,
subsequent_auth_information: None,
authorization_indicator_type: match item.router_data.request.capture_method {
@@ -815,6 +870,12 @@ impl
zip: address.zip.clone(),
country: address.country,
}),
+ user_fields: match item.router_data.request.metadata.clone() {
+ Some(metadata) => Some(UserFields {
+ user_field: Vec::<UserField>::foreign_try_from(metadata)?,
+ }),
+ None => None,
+ },
processing_options: None,
subsequent_auth_information: None,
authorization_indicator_type: match item.router_data.request.capture_method {