mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +08:00
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:
33
crates/router/src/core/pm_auth/helpers.rs
Normal file
33
crates/router/src/core/pm_auth/helpers.rs
Normal 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")
|
||||
}
|
||||
18
crates/router/src/core/pm_auth/transformers.rs
Normal file
18
crates/router/src/core/pm_auth/transformers.rs
Normal 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user