Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connector): [fiserv] fix metadata deserialization in merchant_connector_account #2746

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 33 additions & 15 deletions crates/router/src/connector/fiserv/transformers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common_utils::ext_traits::ValueExt;
use common_utils::{ext_traits::ValueExt, pii};
use error_stack::ResultExt;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -150,9 +150,11 @@ impl TryFrom<&FiservRouterData<&types::PaymentsAuthorizeRouterData>> for FiservP
merchant_transaction_id: item.router_data.connector_request_reference_id.clone(),
};
let metadata = item.router_data.get_connector_meta()?;
let session: SessionObject = metadata
.parse_value("SessionObject")
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
let session: FiservSessionObject = metadata
.parse_value("FiservSessionObject")
.change_context(errors::ConnectorError::InvalidConnectorConfig {
config: "Merchant connector account metadata",
})?;

let merchant_details = MerchantDetails {
merchant_id: auth.merchant_account,
Expand Down Expand Up @@ -230,9 +232,11 @@ impl TryFrom<&types::PaymentsCancelRouterData> for FiservCancelRequest {
fn try_from(item: &types::PaymentsCancelRouterData) -> Result<Self, Self::Error> {
let auth: FiservAuthType = FiservAuthType::try_from(&item.connector_auth_type)?;
let metadata = item.get_connector_meta()?;
let session: SessionObject = metadata
.parse_value("SessionObject")
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
let session: FiservSessionObject = metadata
.parse_value("FiservSessionObject")
.change_context(errors::ConnectorError::InvalidConnectorConfig {
config: "Merchant connector account metadata",
})?;
Ok(Self {
merchant_details: MerchantDetails {
merchant_id: auth.merchant_account,
Expand Down Expand Up @@ -418,11 +422,21 @@ pub struct ReferenceTransactionDetails {
}

#[derive(Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SessionObject {
pub struct FiservSessionObject {
pub terminal_id: String,
}

impl TryFrom<&Option<pii::SecretSerdeValue>> for FiservSessionObject {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(meta_data: &Option<pii::SecretSerdeValue>) -> Result<Self, Self::Error> {
let metadata: Self = utils::to_connector_meta_from_secret::<Self>(meta_data.clone())
.change_context(errors::ConnectorError::InvalidConnectorConfig {
config: "metadata",
})?;
Ok(metadata)
}
}

impl TryFrom<&FiservRouterData<&types::PaymentsCaptureRouterData>> for FiservCaptureRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
Expand All @@ -434,9 +448,11 @@ impl TryFrom<&FiservRouterData<&types::PaymentsCaptureRouterData>> for FiservCap
.connector_meta_data
.clone()
.ok_or(errors::ConnectorError::RequestEncodingFailed)?;
let session: SessionObject = metadata
.parse_value("SessionObject")
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
let session: FiservSessionObject = metadata
.parse_value("FiservSessionObject")
.change_context(errors::ConnectorError::InvalidConnectorConfig {
config: "Merchant connector account metadata",
})?;
Ok(Self {
amount: Amount {
total: item.amount.clone(),
Expand Down Expand Up @@ -527,9 +543,11 @@ impl<F> TryFrom<&FiservRouterData<&types::RefundsRouterData<F>>> for FiservRefun
.connector_meta_data
.clone()
.ok_or(errors::ConnectorError::RequestEncodingFailed)?;
let session: SessionObject = metadata
.parse_value("SessionObject")
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
let session: FiservSessionObject = metadata
.parse_value("FiservSessionObject")
.change_context(errors::ConnectorError::InvalidConnectorConfig {
config: "Merchant connector account metadata",
})?;
Ok(Self {
amount: Amount {
total: item.amount.clone(),
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,7 @@ pub(crate) fn validate_auth_and_metadata_type(
}
api_enums::Connector::Fiserv => {
fiserv::transformers::FiservAuthType::try_from(val)?;
fiserv::transformers::FiservSessionObject::try_from(connector_meta_data)?;
Ok(())
}
api_enums::Connector::Forte => {
Expand Down
Loading