feat(router): add requeue support for payments and fix duplicate entry error in process tracker for requeued payments (#1567)

This commit is contained in:
Sai Harsha Vardhan
2023-07-03 12:56:01 +05:30
committed by GitHub
parent 7489c870d9
commit b967d23251
18 changed files with 133 additions and 22 deletions

View File

@ -40,7 +40,7 @@ use crate::{
services::{self, api::Authenticate},
types::{
self, api, domain,
storage::{self, enums as storage_enums},
storage::{self, enums as storage_enums, ProcessTrackerExt},
},
utils::{Encode, OptionExt, ValueExt},
};
@ -137,7 +137,11 @@ where
if should_add_task_to_process_tracker(&payment_data) {
operation
.to_domain()?
.add_task_to_process_tracker(state, &payment_data.payment_attempt)
.add_task_to_process_tracker(
state,
&payment_data.payment_attempt,
validate_result.requeue,
)
.await
.map_err(|error| logger::error!(process_tracker_error=?error))
.ok();
@ -1234,19 +1238,39 @@ pub async fn add_process_sync_task(
&payment_attempt.attempt_id,
&payment_attempt.merchant_id,
);
let process_tracker_entry =
<storage::ProcessTracker as storage::ProcessTrackerExt>::make_process_tracker_new(
process_tracker_id,
task,
runner,
tracking_data,
schedule_time,
)?;
let process_tracker_entry = <storage::ProcessTracker>::make_process_tracker_new(
process_tracker_id,
task,
runner,
tracking_data,
schedule_time,
)?;
db.insert_process(process_tracker_entry).await?;
Ok(())
}
pub async fn reset_process_sync_task(
db: &dyn StorageInterface,
payment_attempt: &storage::PaymentAttempt,
schedule_time: time::PrimitiveDateTime,
) -> Result<(), errors::ProcessTrackerError> {
let runner = "PAYMENTS_SYNC_WORKFLOW";
let task = "PAYMENTS_SYNC";
let process_tracker_id = pt_utils::get_process_tracker_id(
runner,
task,
&payment_attempt.attempt_id,
&payment_attempt.merchant_id,
);
let psync_process = db
.find_process_by_id(&process_tracker_id)
.await?
.ok_or(errors::ProcessTrackerError::ProcessFetchingFailed)?;
psync_process.reset(db, schedule_time).await?;
Ok(())
}
pub fn update_straight_through_routing<F>(
payment_data: &mut PaymentData<F>,
request_straight_through: serde_json::Value,