Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.2 KB
Raw Blame
import { useValues } from 'kea'

import { LemonButton } from '@posthog/lemon-ui'

import { billingLogic } from 'lib/logic/billing/billingLogic'

export const StripePortalButton = (): JSX.Element | null => {
    const { billing, isExternallyBilled, isBillingManagedByPartner } = useValues(billingLogic)

    if (!billing || isBillingManagedByPartner || (!isExternallyBilled && !billing.customer_id)) {
        return null
    }

    const billingUrl = isExternallyBilled ? billing.external_billing_provider_invoices_url : billing.stripe_portal_url

    if (!billingUrl) {
        return null
    }

    return (
        <div className="w-fit mt-4">
            <LemonButton
                type="primary"
                htmlType="submit"
                to={billingUrl}
                disableClientSideRouting
                targetBlank
                center
                data-attr="manage-billing"
            >
                {isExternallyBilled
                    ? 'View invoices in Vercel'
                    : billing.has_active_subscription
                      ? 'Manage card details and invoices'
                      : 'View past invoices'}
            </LemonButton>
        </div>
    )
}