mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +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 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()?;
|
||||
|
||||
@ -1222,23 +1222,6 @@ where
|
||||
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>(
|
||||
connector_meta: Option<Secret<serde_json::Value>>,
|
||||
) -> Result<T, Error>
|
||||
|
||||
@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user