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

Code before:

async fn should_update_additional_payment_method_data(
    state: SessionState,
    merchant_context: domain::MerchantContext,
    object_ref_id: api::ObjectReferenceId,
) -> bool {
    let db = state.store.as_ref();

    let payment_attempt = match get_payment_attempt_from_object_reference_id(
        &state,
        object_ref_id,
        &merchant_context,
    )
    .await
    {
        Ok(pa) => pa,
        Err(_) => return false,
    };

    let payment_method_id = match payment_attempt.payment_method_id.clone() {
        Some(id) => id,
        None => return false,
    };

    let pm = match db
        .find_payment_method(
            &((&state).into()),
            merchant_context.get_merchant_key_store(),
            &payment_method_id,
            merchant_context.get_merchant_account().storage_scheme,
        )
        .await
    {
        Ok(pm) => pm,
        Err(_) => return false,
    };

    if pm.locker_id.is_some() {
        return false;
    }

    true
}

async fn update_additional_payment_method_data(
    state: &SessionState,
    merchant_context: &domain::MerchantContext,
    object_ref_id: api::ObjectReferenceId,
    connector: &ConnectorEnum,
    request_details: &IncomingWebhookRequestDetails<'_>,
) -> CustomResult<(), errors::ApiErrorResponse> {

Review comment (suggestion):
Also fetching records from DB only for condition checking is not recommended. 
Try to have these checks in `fn update_customer_payment_method` handler only.

Code after:
            &merchant_context.get_merchant_account().organization_id,
            &payment_attempt,
            dispute_status,
            &business_profile,
            connector.id(),
        )
        .await?;
        let disputes_response = Box::new(dispute_object.clone().foreign_into());
        let event_type: enums::EventType = dispute_object.dispute_status.into();

        Box::pin(super::create_event_and_trigger_outgoing_webhook(
            state,
            merchant_context,
            business_profile,
            event_type,
            enums::EventClass::Disputes,
            dispute_object.dispute_id.clone(),
            enums::EventObjectType::DisputeDetails,
            api::OutgoingWebhookContent::DisputeDetails(disputes_response),
            Some(dispute_object.created_at),
        ))
        .await?;
        metrics::INCOMING_DISPUTE_WEBHOOK_MERCHANT_NOTIFIED_METRIC.add(1, &[]);
        Ok(WebhookResponseTracker::Dispute {
            dispute_id: dispute_object.dispute_id,
            payment_id: dispute_object.payment_id,
            status: dispute_object.dispute_status,
        })
    } else {
        metrics::INCOMING_DISPUTE_WEBHOOK_SIGNATURE_FAILURE_METRIC.add(1, &[]);
        Err(report!(
            errors::ApiErrorResponse::WebhookAuthenticationFailed
        ))
    }
}

#[instrument(skip_all)]
async fn bank_transfer_webhook_flow(
    state: SessionState,
    req_state: ReqState,
    merchant_context: domain::MerchantContext,
    business_profile: domain::Profile,
    webhook_details: api::IncomingWebhookDetails,
    source_verified: bool,
) -> CustomResult<WebhookResponseTracker, errors::ApiErrorResponse> {
    let response = if source_verified {
        let payment_attempt = get_payment_attempt_from_object_reference_id(
            &state,
            webhook_details.object_reference_id,
            &merchant_context,
        )