refactor(router): remove unnecessary function from Refunds Validate Flow (#2609)

Co-authored-by: Aaron Jackson <aaronjackson@Aarons-MBP.attlocal.net>
This commit is contained in:
Aaron Jackson
2023-10-18 03:35:05 -07:00
committed by GitHub
parent 2f9a3557f6
commit 3399328ae7
2 changed files with 69 additions and 127 deletions

View File

@ -541,27 +541,11 @@ pub async fn validate_and_create_refund(
.attach_printable("invalid merchant_id in request"))
})?;
let refund = match validator::validate_uniqueness_of_refund_id_against_merchant_id(
db,
&payment_intent.payment_id,
&merchant_account.merchant_id,
&refund_id,
merchant_account.storage_scheme,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable_lazy(|| {
format!(
"Unique violation while checking refund_id: {} against merchant_id: {}",
refund_id, merchant_account.merchant_id
)
})? {
Some(refund) => refund,
None => {
let connecter_transaction_id = payment_attempt.clone().connector_transaction_id.ok_or_else(|| {
report!(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Transaction in invalid. Missing field \"connector_transaction_id\" in payment_attempt.")
})?;
all_refunds = db
.find_refund_by_merchant_id_connector_transaction_id(
&merchant_account.merchant_id,
@ -574,10 +558,7 @@ pub async fn validate_and_create_refund(
currency = payment_attempt.currency.get_required_value("currency")?;
//[#249]: Add Connector Based Validation here.
validator::validate_payment_order_age(
&payment_intent.created_at,
state.conf.refund.max_age,
)
validator::validate_payment_order_age(&payment_intent.created_at, state.conf.refund.max_age)
.change_context(errors::ApiErrorResponse::InvalidDataFormat {
field_name: "created_at".to_string(),
expected_format: format!(
@ -630,7 +611,7 @@ pub async fn validate_and_create_refund(
schedule_refund_execution(
state,
refund,
refund.clone(),
refund_type,
merchant_account,
key_store,
@ -638,9 +619,7 @@ pub async fn validate_and_create_refund(
payment_intent,
creds_identifier,
)
.await?
}
};
.await?;
Ok(refund.foreign_into())
}

View File

@ -4,8 +4,6 @@ use time::PrimitiveDateTime;
use crate::{
core::errors::{self, CustomResult, RouterResult},
db::StorageInterface,
logger,
types::storage::{self, enums},
utils::{self, OptionExt},
};
@ -92,41 +90,6 @@ pub fn validate_maximum_refund_against_payment_attempt(
})
}
#[instrument(skip(db))]
pub async fn validate_uniqueness_of_refund_id_against_merchant_id(
db: &dyn StorageInterface,
payment_id: &str,
merchant_id: &str,
refund_id: &str,
storage_scheme: enums::MerchantStorageScheme,
) -> RouterResult<Option<storage::Refund>> {
let refund = db
.find_refund_by_merchant_id_refund_id(merchant_id, refund_id, storage_scheme)
.await;
logger::debug!(?refund);
match refund {
Err(err) => {
if err.current_context().is_db_not_found() {
// Empty vec should be returned by query in case of no results, this check exists just
// to be on the safer side. Fixed this, now vector is not returned but should check the flow in detail later.
Ok(None)
} else {
Err(err
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while finding refund, database error"))
}
}
Ok(refund) => {
if refund.payment_id == payment_id {
Ok(Some(refund))
} else {
Ok(None)
}
}
}
}
pub fn validate_refund_list(limit: Option<i64>) -> CustomResult<i64, errors::ApiErrorResponse> {
match limit {
Some(limit_val) => {