Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions crates/router/src/connector/authorizedotnet/transformers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::BTreeMap;

use common_utils::{
errors::CustomResult,
ext_traits::{Encode, ValueExt},
Expand All @@ -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::{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -299,6 +317,23 @@ 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::ResponseDeserializationFailed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we throwing ResponseDeserializationFailed error here?

Lets use RequestEncodingFailedWithReason error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I have resolved it.

.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> {
Expand Down Expand Up @@ -622,6 +657,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,
}),
Expand Down Expand Up @@ -675,6 +716,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,
}),
Expand Down Expand Up @@ -762,6 +809,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 {
Expand Down Expand Up @@ -813,6 +866,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 {
Expand Down
Loading