mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
fix(connector): Use ConnectorError::InvalidConnectorConfig for an invalid CoinbaseConnectorMeta (#3168)
Co-authored-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com>
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use common_utils::pii;
|
||||||
|
use error_stack::ResultExt;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -250,6 +252,14 @@ pub struct CoinbaseConnectorMeta {
|
|||||||
pub pricing_type: String,
|
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(
|
fn get_crypto_specific_payment_data(
|
||||||
item: &types::PaymentsAuthorizeRouterData,
|
item: &types::PaymentsAuthorizeRouterData,
|
||||||
) -> Result<CoinbasePaymentsRequest, error_stack::Report<errors::ConnectorError>> {
|
) -> Result<CoinbasePaymentsRequest, error_stack::Report<errors::ConnectorError>> {
|
||||||
@ -260,11 +270,10 @@ fn get_crypto_specific_payment_data(
|
|||||||
let name =
|
let name =
|
||||||
billing_address.and_then(|add| add.get_first_name().ok().map(|name| name.to_owned()));
|
billing_address.and_then(|add| add.get_first_name().ok().map(|name| name.to_owned()));
|
||||||
let description = item.get_description().ok();
|
let description = item.get_description().ok();
|
||||||
let connector_meta: CoinbaseConnectorMeta =
|
let connector_meta = CoinbaseConnectorMeta::try_from(&item.connector_meta_data)
|
||||||
utils::to_connector_meta_from_secret_with_required_field(
|
.change_context(errors::ConnectorError::InvalidConnectorConfig {
|
||||||
item.connector_meta_data.clone(),
|
config: "Merchant connector account metadata",
|
||||||
"Pricing Type Not present in connector meta data",
|
})?;
|
||||||
)?;
|
|
||||||
let pricing_type = connector_meta.pricing_type;
|
let pricing_type = connector_meta.pricing_type;
|
||||||
let local_price = get_local_price(item);
|
let local_price = get_local_price(item);
|
||||||
let redirect_url = item.request.get_return_url()?;
|
let redirect_url = item.request.get_return_url()?;
|
||||||
|
|||||||
@ -1222,23 +1222,6 @@ where
|
|||||||
json.parse_value(std::any::type_name::<T>()).switch()
|
json.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>(
|
pub fn to_connector_meta_from_secret<T>(
|
||||||
connector_meta: Option<Secret<serde_json::Value>>,
|
connector_meta: Option<Secret<serde_json::Value>>,
|
||||||
) -> Result<T, Error>
|
) -> Result<T, Error>
|
||||||
|
|||||||
@ -1713,9 +1713,9 @@ pub(crate) fn validate_auth_and_metadata_type(
|
|||||||
checkout::transformers::CheckoutAuthType::try_from(val)?;
|
checkout::transformers::CheckoutAuthType::try_from(val)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
api_enums::Connector::Coinbase => {
|
api_enums::Connector::Coinbase => {
|
||||||
coinbase::transformers::CoinbaseAuthType::try_from(val)?;
|
coinbase::transformers::CoinbaseAuthType::try_from(val)?;
|
||||||
|
coinbase::transformers::CoinbaseConnectorMeta::try_from(connector_meta_data)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
api_enums::Connector::Cryptopay => {
|
api_enums::Connector::Cryptopay => {
|
||||||
|
|||||||
Reference in New Issue
Block a user