Repository: juspay/hyperswitch
File: crates/router/src/core/refunds.rs (Rust)

Code before:
                        }
                    }
                }
            }
        }
        //  [#255]: This is not allowed to be otherwise or all
        _ => Ok((refund, None)),
    })?;
    Ok(result)
}

#[instrument(skip_all)]
pub async fn sync_refund_with_gateway_workflow(
    state: &SessionState,
    refund_tracker: &storage::ProcessTracker,
) -> Result<(), errors::ProcessTrackerError> {
    // Generate a unique request_id for this RSync execution if not already present
    let request_id = state.request_id.clone().or_else(|| {
        // UUID v7 string is always valid
        router_env::RequestId::try_from(uuid::Uuid::now_v7().to_string()).ok()
    });

    logger::info!(rsync_request_id = ?request_id, process_tracker_id = %refund_tracker.id, "Request ID for RSync task");

    let mut state_with_request_id = state.clone();
    state_with_request_id.request_id = request_id;

    let refund_core = serde_json::from_value::<diesel_refund::RefundCoreWorkflow>(
        refund_tracker.tracking_data.clone(),
    )
    .change_context(errors::ApiErrorResponse::InternalServerError)
    .attach_printable_lazy(|| {
        format!(
            "unable to convert into refund_core {:?}",
            refund_tracker.tracking_data
        )
    })?;

    let key_store = state_with_request_id
        .store
        .get_merchant_key_store_by_merchant_id(
            &refund_core.merchant_id,
            &state_with_request_id.store.get_master_key().to_vec().into(),
        )
        .await?;

    let merchant_account = state_with_request_id
        .store
        .find_merchant_account_by_merchant_id(&refund_core.merchant_id, &key_store)
        .await?;
    let platform = domain::Platform::new(

Review comment (suggestion):
```suggestion
    state_with_request_id.add_request_id(request_id);
```

Code after:
                    }
                }
            }
        }
        //  [#255]: This is not allowed to be otherwise or all
        _ => Ok((refund, None)),
    })?;
    Ok(result)
}

#[instrument(skip_all)]
pub async fn sync_refund_with_gateway_workflow(
    state: &SessionState,
    refund_tracker: &storage::ProcessTracker,
) -> Result<(), errors::ProcessTrackerError> {
    let refund_core = serde_json::from_value::<diesel_refund::RefundCoreWorkflow>(
        refund_tracker.tracking_data.clone(),
    )
    .change_context(errors::ApiErrorResponse::InternalServerError)
    .attach_printable_lazy(|| {
        format!(
            "unable to convert into refund_core {:?}",
            refund_tracker.tracking_data
        )
    })?;

    let key_store = state
        .store
        .get_merchant_key_store_by_merchant_id(
            &refund_core.merchant_id,
            &state.store.get_master_key().to_vec().into(),
        )
        .await?;

    let merchant_account = state
        .store
        .find_merchant_account_by_merchant_id(&refund_core.merchant_id, &key_store)
        .await?;
    let platform = domain::Platform::new(
        merchant_account.clone(),
        key_store.clone(),
        merchant_account.clone(),
        key_store.clone(),
        None,
    );
    let response = Box::pin(refund_retrieve_core_with_internal_reference_id(
        state.clone(),
        platform,
        None,
        refund_core.refund_internal_reference_id,
        Some(true),