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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(connector): Use `ConnectorError::InvalidConnectorConfig` for an invalid `CoinbaseConnectorMeta` (#3168)
Branislav Konturd827c9af29b8
diff --git a/crates/router/src/connector/coinbase/transformers.rs b/crates/router/src/connector/coinbase/transformers.rsindex ce9bb3e871..b1435e50df 100644--- a/crates/router/src/connector/coinbase/transformers.rs+++ b/crates/router/src/connector/coinbase/transformers.rs@@ -1,5 +1,7 @@use std::collections::HashMap;+use common_utils::pii;+use error_stack::ResultExt;use serde::{Deserialize, Serialize};use crate::{@@ -250,6 +252,14 @@ pub struct CoinbaseConnectorMeta {pub pricing_type: String,}+impl TryFrom<&Option<pii::SecretSerdeValue>> for CoinbaseConnectorMeta {+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(meta_data: &Option<pii::SecretSerdeValue>) -> Result<Self, Self::Error> {+ utils::to_connector_meta_from_secret(meta_data.clone())+ .change_context(errors::ConnectorError::InvalidConnectorConfig { config: "metadata" })+ }+}+fn get_crypto_specific_payment_data(item: &types::PaymentsAuthorizeRouterData,) -> Result<CoinbasePaymentsRequest, error_stack::Report<errors::ConnectorError>> {@@ -260,11 +270,10 @@ fn get_crypto_specific_payment_data(let name =billing_address.and_then(|add| add.get_first_name().ok().map(|name| name.to_owned()));let description = item.get_description().ok();- let connector_meta: CoinbaseConnectorMeta =- utils::to_connector_meta_from_secret_with_required_field(- item.connector_meta_data.clone(),- "Pricing Type Not present in connector meta data",- )?;+ let connector_meta = CoinbaseConnectorMeta::try_from(&item.connector_meta_data)+ .change_context(errors::ConnectorError::InvalidConnectorConfig {+ config: "Merchant connector account metadata",+ })?;let pricing_type = connector_meta.pricing_type;let local_price = get_local_price(item);let redirect_url = item.request.get_return_url()?;diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rsindex 3b3c992f0e..87d50bb68a 100644--- a/crates/router/src/connector/utils.rs+++ b/crates/router/src/connector/utils.rs@@ -1222,23 +1222,6 @@ wherejson.parse_value(std::any::type_name::<T>()).switch()}-pub fn to_connector_meta_from_secret_with_required_field<T>(- connector_meta: Option<Secret<serde_json::Value>>,- error_message: &'static str,-) -> Result<T, Error>-where- T: serde::de::DeserializeOwned,-{- let connector_error = errors::ConnectorError::MissingRequiredField {- field_name: error_message,- };- let parsed_meta = to_connector_meta_from_secret(connector_meta).ok();- match parsed_meta {- Some(meta) => Ok(meta),- _ => Err(connector_error.into()),- }-}-pub fn to_connector_meta_from_secret<T>(connector_meta: Option<Secret<serde_json::Value>>,) -> Result<T, Error>diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex fd4cae3a2b..364c5b9b21 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -1713,9 +1713,9 @@ pub(crate) fn validate_auth_and_metadata_type(checkout::transformers::CheckoutAuthType::try_from(val)?;Ok(())}-api_enums::Connector::Coinbase => {coinbase::transformers::CoinbaseAuthType::try_from(val)?;+ coinbase::transformers::CoinbaseConnectorMeta::try_from(connector_meta_data)?;Ok(())}api_enums::Connector::Cryptopay => {