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

Code before:
fn should_update_connector_mandate_details(
    source_verified: bool,
    event_type: webhooks::IncomingWebhookEvent,
) -> bool {
    source_verified && event_type == webhooks::IncomingWebhookEvent::PaymentIntentSuccess
}

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(

Review comment (suggestion):
If `payment_method_id` is the only value required, you can get it in payment_response from fn payments_core.
No need for this fetching attempt from DB.

Code after:

        let dispute_object = get_or_update_dispute_object(
            state.clone(),
            option_dispute,
            dispute_details,
            merchant_context.get_merchant_account().get_id(),
            &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> {