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

Code before:
                .change_context(errors::ApiErrorResponse::WebhookProcessingFailure)
                .attach_printable("Failed to extract MIT payment data from Chargebee webhook")?
        }
        _ => {
            return Err(errors::ApiErrorResponse::WebhookProcessingFailure)
                .attach_printable("Subscription webhook flow not supported for this connector");
        }
    };

    if mit_payment_data.first_invoice {
        return Ok(WebhookResponseTracker::NoEffect);
    }

    // Find subscription by merchant_id and subscription_id to get payment_method_id
    let subscription = state
        .store
        .find_by_merchant_id_subscription_id(
            merchant_context.get_merchant_account().get_id(),
            mit_payment_data
                .subscription_id
                .get_string_repr()
                .to_string(),
        )
        .await
        .change_context(errors::ApiErrorResponse::InternalServerError)
        .attach_printable("Failed to find subscription by merchant ID and subscription ID")?;

    let payment_method_id = subscription
        .payment_method_id
        .ok_or(errors::ApiErrorResponse::InternalServerError)
        .attach_printable("No payment method found for subscription")?;

    logger::info!("Payment method ID found: {}", payment_method_id);

    // Create tracking data for subscription MIT payment
    let tracking_data =
        api_models::process_tracker::subscription::SubscriptionWorkflowTrackingData {
            merchant_id: merchant_context.get_merchant_account().get_id().clone(),
            profile_id: business_profile.get_id().clone(),
            payment_method_id,
            subscription_id: mit_payment_data.subscription_id,
            invoice_id: mit_payment_data.invoice_id.clone(),
            amount: mit_payment_data.amount_due,
            currency: mit_payment_data.currency_code,
            customer_id: mit_payment_data.customer_id,
            connector_name: connector,
            billing_connector_mca_id: billing_connector_mca_id.clone(),
        };

    // Create process tracker entry for subscription MIT payment
    let process_tracker_entry = diesel_models::ProcessTrackerNew {

Review comment (bug):
```suggestion
        .change_context(errors::ApiErrorResponse::GenericNotFoundError)
        .attach_printable("Failed to find subscription by merchant ID and subscription ID")?;
```

Code after:

    let connector = Connector::from_str(&connector_name)
        .change_context(errors::ConnectorError::InvalidConnectorName)
        .change_context(errors::ApiErrorResponse::IncorrectConnectorNameGiven)
        .attach_printable_lazy(|| format!("unable to parse connector name {connector_name}"))?;

    let mit_payment_data = connector_enum
        .get_subscription_mit_payment_data(request_details)
        .change_context(errors::ApiErrorResponse::WebhookProcessingFailure)
        .attach_printable("Failed to extract MIT payment data from subscription webhook")?;

    if mit_payment_data.first_invoice {
        return Ok(WebhookResponseTracker::NoEffect);
    }

    let profile_id = business_profile.get_id().clone();

    let profile =
        SubscriptionHandler::find_business_profile(&state, &merchant_context, &profile_id)
            .await
            .attach_printable(
                "subscriptions: failed to find business profile in get_subscription",
            )?;

    let handler = SubscriptionHandler::new(&state, &merchant_context);

    let subscription_id = mit_payment_data.subscription_id.clone();

    let subscription_with_handler = handler
        .find_subscription(subscription_id)
        .await
        .attach_printable("subscriptions: failed to get subscription entry in get_subscription")?;

    let invoice_handler = subscription_with_handler.get_invoice_handler(profile);

    let payment_method_id = subscription_with_handler
        .subscription
        .payment_method_id
        .clone()
        .ok_or(errors::ApiErrorResponse::GenericNotFoundError {
            message: "No payment method found for subscription".to_string(),
        })
        .attach_printable("No payment method found for subscription")?;

    logger::info!("Payment method ID found: {}", payment_method_id);

    let _invoice_new = invoice_handler
        .create_invoice_entry(
            &state,
            billing_connector_mca_id.clone(),
            None,