feat(core): Implement 3ds decision manger for V2 (#7022)

This commit is contained in:
Swangi Kumari
2025-02-05 19:07:46 +05:30
committed by GitHub
parent 67ea754e38
commit 1900959778
22 changed files with 364 additions and 155 deletions

View File

@ -1,7 +1,11 @@
#[cfg(feature = "v2")]
use api_models::conditional_configs::DecisionManagerRequest;
use api_models::conditional_configs::{
DecisionManager, DecisionManagerRecord, DecisionManagerResponse,
};
use common_utils::ext_traits::StringExt;
#[cfg(feature = "v2")]
use common_utils::types::keymanager::KeyManagerState;
use error_stack::ResultExt;
use crate::{
@ -10,15 +14,57 @@ use crate::{
services::api as service_api,
types::domain,
};
#[cfg(feature = "v2")]
pub async fn upsert_conditional_config(
_state: SessionState,
_key_store: domain::MerchantKeyStore,
_merchant_account: domain::MerchantAccount,
_request: DecisionManager,
) -> RouterResponse<DecisionManagerRecord> {
todo!()
state: SessionState,
key_store: domain::MerchantKeyStore,
request: DecisionManagerRequest,
profile: domain::Profile,
) -> RouterResponse<common_types::payments::DecisionManagerRecord> {
use common_utils::ext_traits::OptionExt;
let key_manager_state: &KeyManagerState = &(&state).into();
let db = &*state.store;
let name = request.name;
let program = request.program;
let timestamp = common_utils::date_time::now_unix_timestamp();
euclid::frontend::ast::lowering::lower_program(program.clone())
.change_context(errors::ApiErrorResponse::InvalidRequestData {
message: "Invalid Request Data".to_string(),
})
.attach_printable("The Request has an Invalid Comparison")?;
let decision_manager_record = common_types::payments::DecisionManagerRecord {
name,
program,
created_at: timestamp,
};
let business_profile_update = domain::ProfileUpdate::DecisionManagerRecordUpdate {
three_ds_decision_manager_config: decision_manager_record,
};
let updated_profile = db
.update_profile_by_profile_id(
key_manager_state,
&key_store,
profile,
business_profile_update,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to update decision manager record in business profile")?;
Ok(service_api::ApplicationResponse::Json(
updated_profile
.three_ds_decision_manager_config
.clone()
.get_required_value("three_ds_decision_manager_config")
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable(
"Failed to get updated decision manager record in business profile",
)?,
))
}
#[cfg(feature = "v1")]
@ -204,6 +250,7 @@ pub async fn delete_conditional_config(
Ok(service_api::ApplicationResponse::StatusOk)
}
#[cfg(feature = "v1")]
pub async fn retrieve_conditional_config(
state: SessionState,
merchant_account: domain::MerchantAccount,
@ -229,3 +276,27 @@ pub async fn retrieve_conditional_config(
};
Ok(service_api::ApplicationResponse::Json(response))
}
#[cfg(feature = "v2")]
pub async fn retrieve_conditional_config(
state: SessionState,
key_store: domain::MerchantKeyStore,
profile: domain::Profile,
) -> RouterResponse<common_types::payments::DecisionManagerResponse> {
let db = state.store.as_ref();
let key_manager_state: &KeyManagerState = &(&state).into();
let profile_id = profile.get_id();
let record = profile
.three_ds_decision_manager_config
.clone()
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable("The Conditional Config Record was not found")?;
let response = common_types::payments::DecisionManagerRecord {
name: record.name,
program: record.program,
created_at: record.created_at,
};
Ok(service_api::ApplicationResponse::Json(response))
}