feat(pm_auth): pm_auth service migration (#3047)

Co-authored-by: Sarthak Soni <76486416+Sarthak1799@users.noreply.github.com>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sarthak Soni <sarthak.soni@juspay.in>
This commit is contained in:
Chethan Rao
2023-12-06 20:48:41 +05:30
committed by GitHub
parent 294b04bcdd
commit 9c1c44a706
40 changed files with 2492 additions and 25 deletions

View File

@ -0,0 +1,33 @@
use common_utils::ext_traits::ValueExt;
use error_stack::{IntoReport, ResultExt};
use pm_auth::types::{self as pm_auth_types, api::BoxedPaymentAuthConnector};
use crate::{
core::errors::{self, ApiErrorResponse},
types::{self, domain, transformers::ForeignTryFrom},
};
pub trait PaymentAuthConnectorDataExt {
fn get_connector_by_name(name: &str) -> errors::CustomResult<Self, ApiErrorResponse>
where
Self: Sized;
fn convert_connector(
connector_name: pm_auth_types::PaymentMethodAuthConnectors,
) -> errors::CustomResult<BoxedPaymentAuthConnector, ApiErrorResponse>;
}
pub fn get_connector_auth_type(
merchant_connector_account: domain::MerchantConnectorAccount,
) -> errors::CustomResult<pm_auth_types::ConnectorAuthType, ApiErrorResponse> {
let auth_type: types::ConnectorAuthType = merchant_connector_account
.connector_account_details
.parse_value("ConnectorAuthType")
.change_context(ApiErrorResponse::MerchantConnectorAccountNotFound {
id: "ConnectorAuthType".to_string(),
})?;
pm_auth_types::ConnectorAuthType::foreign_try_from(auth_type)
.into_report()
.change_context(ApiErrorResponse::InternalServerError)
.attach_printable("Failed while converting ConnectorAuthType")
}

View File

@ -0,0 +1,18 @@
use pm_auth::types::{self as pm_auth_types};
use crate::{core::errors, types, types::transformers::ForeignTryFrom};
impl ForeignTryFrom<types::ConnectorAuthType> for pm_auth_types::ConnectorAuthType {
type Error = errors::ConnectorError;
fn foreign_try_from(auth_type: types::ConnectorAuthType) -> Result<Self, Self::Error> {
match auth_type {
types::ConnectorAuthType::BodyKey { api_key, key1 } => {
Ok::<Self, errors::ConnectorError>(Self::BodyKey {
client_id: api_key.to_owned(),
secret: key1.to_owned(),
})
}
_ => Err(errors::ConnectorError::FailedToObtainAuthType),
}
}
}