def chargebee_webhook(request: Request) -> Response:
    """
    Endpoint to handle webhooks from chargebee.

    Payment failure and payment succeeded webhooks are filtered out and processed
    to determine which of our subscriptions are in a dunning state.

    The remaining webhooks are processed if they have subscription data:

     - If subscription is active, check to see if plan has changed and update if so. Always update cancellation date to
       None to ensure that if a subscription is reactivated, it is updated on our end.

     - If subscription is cancelled or not renewing, update subscription on our end to include cancellation date and
       send alert to admin users.
    """
    event_type = request.data.get("event_type")

    if event_type == webhook_event_types.PAYMENT_FAILED:
        return webhook_handlers.payment_failed(request)
    if event_type == webhook_event_types.PAYMENT_SUCCEEDED:
        return webhook_handlers.payment_succeeded(request)
    if event_type in webhook_event_types.CACHE_REBUILD_TYPES:
        return webhook_handlers.cache_rebuild_event(request)

    # Catchall handlers for finding subscription related processing data.
    return webhook_handlers.process_subscription(request)

    Endpoint to handle webhooks from chargebee.

    Payment failure and payment succeeded webhooks are filtered out and processed
    to determine which of our subscriptions are in a dunning state.

    The remaining webhooks are processed if they have subscription data:

     - If subscription is active, check to see if plan has changed and update if so. Always update cancellation date to
       None to ensure that if a subscription is reactivated, it is updated on our end.

     - If subscription is cancelled or not renewing, update subscription on our end to include cancellation date and
       send alert to admin users.
    
api/organisations/views.py