fix(router): fix attempt status for techincal failures in psync flow (#2252)

This commit is contained in:
Sai Harsha Vardhan
2023-09-22 15:22:08 +05:30
committed by GitHub
parent aa8d0ddda1
commit 2b8bd03a72
2 changed files with 28 additions and 4 deletions

View File

@ -12,6 +12,7 @@ use crate::{
errors::{self, RouterResult, StorageErrorExt}, errors::{self, RouterResult, StorageErrorExt},
mandate, mandate,
payments::{types::MultipleCaptureData, PaymentData}, payments::{types::MultipleCaptureData, PaymentData},
utils as core_utils,
}, },
db::StorageInterface, db::StorageInterface,
routes::metrics, routes::metrics,
@ -311,10 +312,21 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
(Some((multiple_capture_data, capture_update_list)), None) (Some((multiple_capture_data, capture_update_list)), None)
} }
None => { None => {
let status = match err.status_code { let flow_name = core_utils::get_flow_name::<F>()?;
500..=511 => storage::enums::AttemptStatus::Pending, let status =
_ => storage::enums::AttemptStatus::Failure, // mark previous attempt status for technical failures in PSync flow
}; if flow_name == "PSync" {
match err.status_code {
// marking failure for 2xx because this is genuine payment failure
200..=299 => storage::enums::AttemptStatus::Failure,
_ => payment_data.payment_attempt.status,
}
} else {
match err.status_code {
500..=511 => storage::enums::AttemptStatus::Pending,
_ => storage::enums::AttemptStatus::Failure,
}
};
( (
None, None,
Some(storage::PaymentAttemptUpdate::ErrorUpdate { Some(storage::PaymentAttemptUpdate::ErrorUpdate {

View File

@ -1033,3 +1033,15 @@ pub async fn get_profile_id_from_business_details(
}, },
} }
} }
#[inline]
pub fn get_flow_name<F>() -> RouterResult<String> {
Ok(std::any::type_name::<F>()
.to_string()
.rsplit("::")
.next()
.ok_or(errors::ApiErrorResponse::InternalServerError)
.into_report()
.attach_printable("Flow stringify failed")?
.to_string())
}