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

Code before:
) -> RouterResult<()> {
    if invoice.status != common_enums::enums::InvoiceStatus::InvoicePaid {
        logger::info!("Invoice not paid, skipping outgoing webhook trigger");
        return Ok(());
    }
    let response = InvoiceSyncHandler::generate_response(subscription, invoice, &payment_response)
        .attach_printable("Subscriptions: Failed to generate response for outgoing webhook")?;

    let platform = domain::Platform::new(
        merchant_account.clone(),
        key_store.clone(),
        merchant_account.clone(),
        key_store.clone(),
    );

    let cloned_state = state.clone();
    let cloned_profile = profile.clone();
    let invoice_id = invoice.id.get_string_repr().to_owned();
    let created_at = subscription.created_at;
    let processor = platform.get_processor().clone();

    tokio::spawn(async move {
        Box::pin(webhooks_core::create_event_and_trigger_outgoing_webhook(
            cloned_state,
            processor,
            cloned_profile,
            common_enums::enums::EventType::InvoicePaid,
            common_enums::enums::EventClass::Subscriptions,
            invoice_id,
            common_enums::EventObjectType::SubscriptionDetails,
            webhooks::OutgoingWebhookContent::SubscriptionDetails(Box::new(response)),
            Some(created_at),
        ))
        .await
    });

    Ok(())
}


Review comment (suggestion):
```suggestion
    let cloned_processor = platform.get_processor().clone();
```

Code after:
    invoice: &hyperswitch_domain_models::invoice::Invoice,
    subscription: &hyperswitch_domain_models::subscription::Subscription,
    merchant_account: &domain::MerchantAccount,
    key_store: &domain::MerchantKeyStore,
    profile: &domain::Profile,
) -> RouterResult<()> {
    if invoice.status != common_enums::enums::InvoiceStatus::InvoicePaid {
        logger::info!("Invoice not paid, skipping outgoing webhook trigger");
        return Ok(());
    }
    let response = InvoiceSyncHandler::generate_response(subscription, invoice, &payment_response)
        .attach_printable("Subscriptions: Failed to generate response for outgoing webhook")?;

    let platform = domain::Platform::new(
        merchant_account.clone(),
        key_store.clone(),
        merchant_account.clone(),
        key_store.clone(),
        None,
    );

    let cloned_state = state.clone();
    let cloned_profile = profile.clone();
    let invoice_id = invoice.id.get_string_repr().to_owned();
    let created_at = subscription.created_at;
    let processor = platform.get_processor().clone();

    tokio::spawn(async move {
        Box::pin(webhooks_core::create_event_and_trigger_outgoing_webhook(
            cloned_state,
            processor,
            cloned_profile,
            common_enums::enums::EventType::InvoicePaid,
            common_enums::enums::EventClass::Subscriptions,
            invoice_id,
            common_enums::EventObjectType::SubscriptionDetails,
            webhooks::OutgoingWebhookContent::SubscriptionDetails(Box::new(response)),
            Some(created_at),
        ))
        .await
    });

    Ok(())
}