mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
refactor: remove configs/pg_agnostic_mit api as it will not be used (#4486)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -299,13 +299,6 @@ impl From<RoutableConnectorChoice> for ast::ConnectorChoice {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
|
||||
pub struct DetailedConnectorChoice {
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
||||
impl common_utils::events::ApiEventMetric for DetailedConnectorChoice {}
|
||||
|
||||
#[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize, strum::Display, ToSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
|
||||
@ -314,6 +314,7 @@ where
|
||||
&merchant_account,
|
||||
&key_store,
|
||||
&mut payment_data,
|
||||
&business_profile,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -415,6 +416,7 @@ where
|
||||
&merchant_account,
|
||||
&key_store,
|
||||
&mut payment_data,
|
||||
&business_profile,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -3320,6 +3322,7 @@ where
|
||||
routing_data,
|
||||
connector_data,
|
||||
mandate_type,
|
||||
business_profile.is_connector_agnostic_mit_enabled,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@ -3377,6 +3380,7 @@ where
|
||||
routing_data,
|
||||
connector_data,
|
||||
mandate_type,
|
||||
business_profile.is_connector_agnostic_mit_enabled,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@ -3400,6 +3404,7 @@ pub async fn decide_multiplex_connector_for_normal_or_recurring_payment<F: Clone
|
||||
routing_data: &mut storage::RoutingData,
|
||||
connectors: Vec<api::ConnectorData>,
|
||||
mandate_type: Option<api::MandateTransactionType>,
|
||||
is_connector_agnostic_mit_enabled: Option<bool>,
|
||||
) -> RouterResult<ConnectorCallType> {
|
||||
match (
|
||||
payment_data.payment_intent.setup_future_usage,
|
||||
@ -3442,22 +3447,6 @@ pub async fn decide_multiplex_connector_for_normal_or_recurring_payment<F: Clone
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("unable to deserialize connector mandate details")?;
|
||||
|
||||
let profile_id = payment_data
|
||||
.payment_intent
|
||||
.profile_id
|
||||
.as_ref()
|
||||
.ok_or(errors::ApiErrorResponse::ResourceIdNotFound)?;
|
||||
|
||||
let pg_agnostic = state
|
||||
.store
|
||||
.find_config_by_key_unwrap_or(
|
||||
&format!("pg_agnostic_mandate_{}", profile_id),
|
||||
Some("false".to_string()),
|
||||
)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("The pg_agnostic config was not found in the DB")?;
|
||||
|
||||
let mut connector_choice = None;
|
||||
|
||||
for connector_data in connectors {
|
||||
@ -3468,7 +3457,7 @@ pub async fn decide_multiplex_connector_for_normal_or_recurring_payment<F: Clone
|
||||
|
||||
if is_network_transaction_id_flow(
|
||||
state,
|
||||
&pg_agnostic.config,
|
||||
is_connector_agnostic_mit_enabled,
|
||||
connector_data.connector_name,
|
||||
payment_method_info,
|
||||
) {
|
||||
@ -3588,7 +3577,7 @@ pub async fn decide_multiplex_connector_for_normal_or_recurring_payment<F: Clone
|
||||
|
||||
pub fn is_network_transaction_id_flow(
|
||||
state: &AppState,
|
||||
pg_agnostic: &String,
|
||||
is_connector_agnostic_mit_enabled: Option<bool>,
|
||||
connector: enums::Connector,
|
||||
payment_method_info: &storage::PaymentMethod,
|
||||
) -> bool {
|
||||
@ -3597,7 +3586,7 @@ pub fn is_network_transaction_id_flow(
|
||||
.network_transaction_id_supported_connectors
|
||||
.connector_list;
|
||||
|
||||
pg_agnostic == "true"
|
||||
is_connector_agnostic_mit_enabled == Some(true)
|
||||
&& payment_method_info.payment_method == Some(storage_enums::PaymentMethod::Card)
|
||||
&& ntid_supported_connectors.contains(&connector)
|
||||
&& payment_method_info.network_transaction_id.is_some()
|
||||
@ -3827,6 +3816,7 @@ where
|
||||
routing_data,
|
||||
connector_data,
|
||||
mandate_type,
|
||||
business_profile.is_connector_agnostic_mit_enabled,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@ -241,6 +241,7 @@ pub trait PostUpdateTracker<F, D, R: Send>: Send {
|
||||
_merchant_account: &domain::MerchantAccount,
|
||||
_key_store: &domain::MerchantKeyStore,
|
||||
_payment_data: &mut PaymentData<F>,
|
||||
_business_profile: &storage::business_profile::BusinessProfile,
|
||||
) -> CustomResult<(), errors::ApiErrorResponse>
|
||||
where
|
||||
F: 'b + Clone + Send + Sync,
|
||||
|
||||
@ -89,13 +89,13 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
key_store: &domain::MerchantKeyStore,
|
||||
payment_data: &mut PaymentData<F>,
|
||||
business_profile: &storage::business_profile::BusinessProfile,
|
||||
) -> CustomResult<(), errors::ApiErrorResponse>
|
||||
where
|
||||
F: 'b + Clone + Send + Sync,
|
||||
{
|
||||
let customer_id = payment_data.payment_intent.customer_id.clone();
|
||||
let save_payment_data = tokenization::SavePaymentMethodData::from(resp);
|
||||
let profile_id = payment_data.payment_intent.profile_id.clone();
|
||||
|
||||
let connector_name = payment_data
|
||||
.payment_attempt
|
||||
@ -125,8 +125,8 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
|
||||
key_store,
|
||||
Some(resp.request.amount),
|
||||
Some(resp.request.currency),
|
||||
profile_id,
|
||||
billing_name.clone(),
|
||||
business_profile,
|
||||
));
|
||||
|
||||
let is_connector_mandate = resp.request.customer_acceptance.is_some()
|
||||
@ -169,11 +169,12 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
|
||||
let key_store = key_store.clone();
|
||||
let state = state.clone();
|
||||
let customer_id = payment_data.payment_intent.customer_id.clone();
|
||||
let profile_id = payment_data.payment_intent.profile_id.clone();
|
||||
|
||||
let merchant_connector_id = payment_data.payment_attempt.merchant_connector_id.clone();
|
||||
let payment_attempt = payment_data.payment_attempt.clone();
|
||||
|
||||
let business_profile = business_profile.clone();
|
||||
|
||||
let amount = resp.request.amount;
|
||||
let currency = resp.request.currency;
|
||||
let payment_method_type = resp.request.payment_method_type;
|
||||
@ -195,8 +196,8 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
|
||||
&key_store,
|
||||
Some(amount),
|
||||
Some(currency),
|
||||
profile_id,
|
||||
billing_name,
|
||||
&business_profile,
|
||||
))
|
||||
.await;
|
||||
|
||||
@ -388,6 +389,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsSyncData> for
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
_key_store: &domain::MerchantKeyStore,
|
||||
payment_data: &mut PaymentData<F>,
|
||||
business_profile: &storage::business_profile::BusinessProfile,
|
||||
) -> CustomResult<(), errors::ApiErrorResponse>
|
||||
where
|
||||
F: 'b + Clone + Send + Sync,
|
||||
@ -398,6 +400,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsSyncData> for
|
||||
resp.status,
|
||||
resp.response.clone(),
|
||||
merchant_account.storage_scheme,
|
||||
business_profile.is_connector_agnostic_mit_enabled,
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
@ -587,6 +590,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::SetupMandateRequestDa
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
key_store: &domain::MerchantKeyStore,
|
||||
payment_data: &mut PaymentData<F>,
|
||||
business_profile: &storage::business_profile::BusinessProfile,
|
||||
) -> CustomResult<(), errors::ApiErrorResponse>
|
||||
where
|
||||
F: 'b + Clone + Send + Sync,
|
||||
@ -598,7 +602,6 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::SetupMandateRequestDa
|
||||
.and_then(|address| address.get_optional_full_name());
|
||||
let save_payment_data = tokenization::SavePaymentMethodData::from(resp);
|
||||
let customer_id = payment_data.payment_intent.customer_id.clone();
|
||||
let profile_id = payment_data.payment_intent.profile_id.clone();
|
||||
let connector_name = payment_data
|
||||
.payment_attempt
|
||||
.connector
|
||||
@ -622,8 +625,8 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::SetupMandateRequestDa
|
||||
key_store,
|
||||
resp.request.amount,
|
||||
Some(resp.request.currency),
|
||||
profile_id,
|
||||
billing_name,
|
||||
business_profile,
|
||||
))
|
||||
.await?;
|
||||
|
||||
@ -674,6 +677,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::CompleteAuthorizeData
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
_key_store: &domain::MerchantKeyStore,
|
||||
payment_data: &mut PaymentData<F>,
|
||||
business_profile: &storage::business_profile::BusinessProfile,
|
||||
) -> CustomResult<(), errors::ApiErrorResponse>
|
||||
where
|
||||
F: 'b + Clone + Send + Sync,
|
||||
@ -684,6 +688,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::CompleteAuthorizeData
|
||||
resp.status,
|
||||
resp.response.clone(),
|
||||
merchant_account.storage_scheme,
|
||||
business_profile.is_connector_agnostic_mit_enabled,
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
@ -1224,6 +1229,7 @@ async fn update_payment_method_status_and_ntid<F: Clone>(
|
||||
attempt_status: common_enums::AttemptStatus,
|
||||
payment_response: Result<types::PaymentsResponseData, ErrorResponse>,
|
||||
storage_scheme: enums::MerchantStorageScheme,
|
||||
is_connector_agnostic_mit_enabled: Option<bool>,
|
||||
) -> RouterResult<()> {
|
||||
if let Some(id) = &payment_data.payment_attempt.payment_method_id {
|
||||
let pm = state
|
||||
@ -1244,23 +1250,7 @@ async fn update_payment_method_status_and_ntid<F: Clone>(
|
||||
|
||||
let network_transaction_id =
|
||||
if let Some(network_transaction_id) = pm_resp_network_transaction_id {
|
||||
let profile_id = payment_data
|
||||
.payment_intent
|
||||
.profile_id
|
||||
.as_ref()
|
||||
.ok_or(errors::ApiErrorResponse::ResourceIdNotFound)?;
|
||||
|
||||
let pg_agnostic = state
|
||||
.store
|
||||
.find_config_by_key_unwrap_or(
|
||||
&format!("pg_agnostic_mandate_{}", profile_id),
|
||||
Some("false".to_string()),
|
||||
)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("The pg_agnostic config was not found in the DB")?;
|
||||
|
||||
if &pg_agnostic.config == "true"
|
||||
if is_connector_agnostic_mit_enabled == Some(true)
|
||||
&& payment_data.payment_intent.setup_future_usage
|
||||
== Some(diesel_models::enums::FutureUsage::OffSession)
|
||||
{
|
||||
|
||||
@ -64,8 +64,8 @@ pub async fn save_payment_method<FData>(
|
||||
key_store: &domain::MerchantKeyStore,
|
||||
amount: Option<i64>,
|
||||
currency: Option<storage_enums::Currency>,
|
||||
profile_id: Option<String>,
|
||||
billing_name: Option<masking::Secret<String>>,
|
||||
business_profile: &storage::business_profile::BusinessProfile,
|
||||
) -> RouterResult<(Option<String>, Option<common_enums::PaymentMethodStatus>)>
|
||||
where
|
||||
FData: mandate::MandateBehaviour + Clone,
|
||||
@ -91,21 +91,7 @@ where
|
||||
|
||||
let network_transaction_id =
|
||||
if let Some(network_transaction_id) = network_transaction_id {
|
||||
let profile_id = profile_id
|
||||
.as_ref()
|
||||
.ok_or(errors::ApiErrorResponse::ResourceIdNotFound)?;
|
||||
|
||||
let pg_agnostic = state
|
||||
.store
|
||||
.find_config_by_key_unwrap_or(
|
||||
&format!("pg_agnostic_mandate_{}", profile_id),
|
||||
Some("false".to_string()),
|
||||
)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("The pg_agnostic config was not found in the DB")?;
|
||||
|
||||
if &pg_agnostic.config == "true"
|
||||
if business_profile.is_connector_agnostic_mit_enabled == Some(true)
|
||||
&& save_payment_method_data.request.get_setup_future_usage()
|
||||
== Some(storage_enums::FutureUsage::OffSession)
|
||||
{
|
||||
|
||||
@ -9,6 +9,7 @@ use api_models::{
|
||||
};
|
||||
#[cfg(not(feature = "business_profile_routing"))]
|
||||
use common_utils::ext_traits::{Encode, StringExt};
|
||||
#[cfg(not(feature = "business_profile_routing"))]
|
||||
use diesel_models::configs;
|
||||
#[cfg(feature = "business_profile_routing")]
|
||||
use diesel_models::routing_algorithm::RoutingAlgorithm;
|
||||
@ -806,37 +807,6 @@ pub async fn retrieve_linked_routing_config(
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn upsert_connector_agnostic_mandate_config(
|
||||
state: AppState,
|
||||
business_profile_id: &str,
|
||||
mandate_config: routing_types::DetailedConnectorChoice,
|
||||
) -> RouterResponse<routing_types::DetailedConnectorChoice> {
|
||||
let key = helpers::get_pg_agnostic_mandate_config_key(business_profile_id);
|
||||
|
||||
let mandate_config_str = mandate_config.enabled.to_string();
|
||||
|
||||
let find_config = state
|
||||
.store
|
||||
.find_config_by_key_unwrap_or(&key, Some(mandate_config_str.clone()))
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("error saving pg agnostic mandate config to db")?;
|
||||
|
||||
if find_config.config != mandate_config_str {
|
||||
let config_update = configs::ConfigUpdate::Update {
|
||||
config: Some(mandate_config_str),
|
||||
};
|
||||
state
|
||||
.store
|
||||
.update_config_by_key(&key, config_update)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("error saving pg agnostic mandate config to db")?;
|
||||
}
|
||||
|
||||
Ok(service_api::ApplicationResponse::Json(mandate_config))
|
||||
}
|
||||
|
||||
pub async fn retrieve_default_routing_config_for_profiles(
|
||||
state: AppState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
|
||||
@ -272,47 +272,6 @@ pub async fn update_business_profile_active_algorithm_ref(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_merchant_connector_agnostic_mandate_config(
|
||||
db: &dyn StorageInterface,
|
||||
business_profile_id: &str,
|
||||
) -> RouterResult<Vec<routing_types::DetailedConnectorChoice>> {
|
||||
let key = get_pg_agnostic_mandate_config_key(business_profile_id);
|
||||
let maybe_config = db.find_config_by_key(&key).await;
|
||||
|
||||
match maybe_config {
|
||||
Ok(config) => config
|
||||
.config
|
||||
.parse_struct("Vec<DetailedConnectorChoice>")
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("pg agnostic mandate config has invalid structure"),
|
||||
|
||||
Err(e) if e.current_context().is_db_not_found() => {
|
||||
let new_mandate_config: Vec<routing_types::DetailedConnectorChoice> = Vec::new();
|
||||
|
||||
let serialized = new_mandate_config
|
||||
.encode_to_string_of_json()
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("error serializing newly created pg agnostic mandate config")?;
|
||||
|
||||
let new_config = configs::ConfigNew {
|
||||
key,
|
||||
config: serialized,
|
||||
};
|
||||
|
||||
db.insert_config(new_config)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("error inserting new pg agnostic mandate config in db")?;
|
||||
|
||||
Ok(new_mandate_config)
|
||||
}
|
||||
|
||||
Err(e) => Err(e)
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("error fetching pg agnostic mandate config for merchant from db"),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn validate_connectors_in_routing_config(
|
||||
db: &dyn StorageInterface,
|
||||
key_store: &domain::MerchantKeyStore,
|
||||
@ -441,12 +400,6 @@ pub fn get_routing_dictionary_key(merchant_id: &str) -> String {
|
||||
format!("routing_dict_{merchant_id}")
|
||||
}
|
||||
|
||||
/// Provides the identifier for the specific merchant's agnostic_mandate_config
|
||||
#[inline(always)]
|
||||
pub fn get_pg_agnostic_mandate_config_key(business_profile_id: &str) -> String {
|
||||
format!("pg_agnostic_mandate_{business_profile_id}")
|
||||
}
|
||||
|
||||
/// Provides the identifier for the specific merchant's default_config
|
||||
#[inline(always)]
|
||||
pub fn get_default_config_key(
|
||||
|
||||
@ -466,10 +466,6 @@ impl Routing {
|
||||
)
|
||||
})),
|
||||
)
|
||||
.service(
|
||||
web::resource("/business_profile/{business_profile_id}/configs/pg_agnostic_mit")
|
||||
.route(web::post().to(cloud_routing::upsert_connector_agnostic_mandate_config)),
|
||||
)
|
||||
.service(
|
||||
web::resource("/default")
|
||||
.route(web::get().to(|state, req| {
|
||||
|
||||
@ -231,7 +231,6 @@ impl From<Flow> for ApiIdentifier {
|
||||
| Flow::ReconTokenRequest
|
||||
| Flow::ReconServiceRequest
|
||||
| Flow::ReconVerifyToken => Self::Recon,
|
||||
Flow::CreateConnectorAgnosticMandateConfig => Self::Routing,
|
||||
|
||||
Flow::RetrievePollStatus => Self::Poll,
|
||||
}
|
||||
|
||||
@ -566,41 +566,6 @@ pub async fn routing_retrieve_linked_config(
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "olap")]
|
||||
#[instrument(skip_all)]
|
||||
pub async fn upsert_connector_agnostic_mandate_config(
|
||||
state: web::Data<AppState>,
|
||||
req: HttpRequest,
|
||||
json_payload: web::Json<routing_types::DetailedConnectorChoice>,
|
||||
path: web::Path<String>,
|
||||
) -> impl Responder {
|
||||
use crate::services::authentication::AuthenticationData;
|
||||
|
||||
let flow = Flow::CreateConnectorAgnosticMandateConfig;
|
||||
let business_profile_id = path.into_inner();
|
||||
|
||||
Box::pin(oss_api::server_wrap(
|
||||
flow,
|
||||
state,
|
||||
&req,
|
||||
json_payload.into_inner(),
|
||||
|state, _auth: AuthenticationData, mandate_config, _| {
|
||||
Box::pin(routing::upsert_connector_agnostic_mandate_config(
|
||||
state,
|
||||
&business_profile_id,
|
||||
mandate_config,
|
||||
))
|
||||
},
|
||||
auth::auth_type(
|
||||
&auth::ApiKeyAuth,
|
||||
&auth::JWTAuth(Permission::RoutingWrite),
|
||||
req.headers(),
|
||||
),
|
||||
api_locking::LockAction::NotApplicable,
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(feature = "olap")]
|
||||
#[instrument(skip_all)]
|
||||
pub async fn routing_retrieve_default_config_for_profiles(
|
||||
|
||||
@ -3,9 +3,9 @@ pub use api_models::routing::RoutableChoiceKind;
|
||||
pub use api_models::{
|
||||
enums as api_enums,
|
||||
routing::{
|
||||
ConnectorVolumeSplit, DetailedConnectorChoice, RoutableConnectorChoice, RoutingAlgorithm,
|
||||
RoutingAlgorithmKind, RoutingAlgorithmRef, RoutingConfigRequest, RoutingDictionary,
|
||||
RoutingDictionaryRecord, StraightThroughAlgorithm,
|
||||
ConnectorVolumeSplit, RoutableConnectorChoice, RoutingAlgorithm, RoutingAlgorithmKind,
|
||||
RoutingAlgorithmRef, RoutingConfigRequest, RoutingDictionary, RoutingDictionaryRecord,
|
||||
StraightThroughAlgorithm,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@ -210,8 +210,6 @@ pub enum Flow {
|
||||
RoutingRetrieveConfig,
|
||||
/// Routing retrieve active config
|
||||
RoutingRetrieveActiveConfig,
|
||||
/// Update connector agnostic mandate config
|
||||
CreateConnectorAgnosticMandateConfig,
|
||||
/// Routing retrieve default config
|
||||
RoutingRetrieveDefaultConfig,
|
||||
/// Routing retrieve dictionary
|
||||
|
||||
Reference in New Issue
Block a user