: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(billing): add a contact support action to the payment entry modal (#103175)
Ben Lead5028a673909
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex d5b25329780d..ce2b84cfed98 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -476,6 +476,7 @@ export const FEATURE_FLAGS = {PAGE_REPORTS_AVERAGE_PAGE_VIEW: 'page-reports-average-page-view', // owner: @jordanm-posthog #team-web-analyticsPAGE_REPORTS_RANKED_URL_SEARCH: 'page-reports-ranked-url-search', // owner: @jordanm-posthog #team-web-analyticsPASSWORD_PROTECTED_SHARES: 'password-protected-shares', // owner: @aspicer+ PAYMENT_ENTRY_CONTACT_SUPPORT: 'payment-entry-contact-support', // owner: #team-billing, see `PaymentEntryModal.tsx`PHAI_PLAN_MODE: 'phai-plan-mode', // owner: #team-posthog-aiPHAI_QUILL: 'phai-quill', // owner: #team-posthog-ai, renders the PostHog AI chat thread in quill like PostHog Desktop; on with today-rail-nav tooPHAI_SANDBOX_MODE: 'phai-sandbox-mode', // owner: #team-posthog-aidiff --git a/frontend/src/scenes/billing/PaymentEntryModal.test.tsx b/frontend/src/scenes/billing/PaymentEntryModal.test.tsxnew file mode 100644index 000000000000..952d14853ebd--- /dev/null+++ b/frontend/src/scenes/billing/PaymentEntryModal.test.tsx@@ -0,0 +1,63 @@+/* oxlint-disable react-hooks/rules-of-hooks -- useMocks is a test helper, not a React hook */+import '@testing-library/jest-dom'++import { cleanup, render, screen, waitFor } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { Provider } from 'kea'++import { supportLogic } from 'lib/components/Support/supportLogic'+import { FEATURE_FLAGS } from 'lib/constants'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { paymentEntryLogic } from 'scenes/billing/paymentEntryLogic'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import { PaymentEntryModal } from './PaymentEntryModal'++const BLOCKED_MESSAGE = "You've been blocked from subscribing. Please contact support."++describe('PaymentEntryModal', () => {+ beforeEach(() => {+ useMocks({+ post: {+ 'api/billing/activate/authorize': () => [403, { detail: BLOCKED_MESSAGE }],+ },+ })+ initKeaTests()+ paymentEntryLogic.mount()+ supportLogic.mount()+ })++ afterEach(cleanup)++ it('files a blocked upgrade as a billing issue, which every plan may raise', async () => {+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.PAYMENT_ENTRY_CONTACT_SUPPORT]: true })+ render(+ <Provider>+ <PaymentEntryModal />+ </Provider>+ )+ paymentEntryLogic.actions.showPaymentEntryModal()++ const contactSupport = await screen.findByText('Contact support')+ await userEvent.click(contactSupport)++ await waitFor(() => expect(supportLogic.values.sendSupportRequest.billing_issue).toBe(true))+ expect(supportLogic.values.sendSupportRequest.message).toContain('Failed to initialize payment')+ expect(paymentEntryLogic.values.paymentEntryModalOpen).toBe(false)+ })++ it('hides contact support while the flag is off', async () => {+ featureFlagLogic.actions.setFeatureFlags([], {})+ render(+ <Provider>+ <PaymentEntryModal />+ </Provider>+ )+ paymentEntryLogic.actions.showPaymentEntryModal()++ await screen.findByText('Close')+ expect(document.querySelector('[data-attr="payment-entry-api-error-contact-support"]')).not.toBeInTheDocument()+ })+})diff --git a/frontend/src/scenes/billing/PaymentEntryModal.tsx b/frontend/src/scenes/billing/PaymentEntryModal.tsxindex 1743bcb78366..1dfe310466ec 100644--- a/frontend/src/scenes/billing/PaymentEntryModal.tsx+++ b/frontend/src/scenes/billing/PaymentEntryModal.tsx@@ -5,6 +5,8 @@ import { useEffect, useState } from 'react'import { LemonBanner, LemonButton, LemonModal } from '@posthog/lemon-ui'+import { SupportFormFields, supportLogic } from 'lib/components/Support/supportLogic'+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'import { urls } from 'scenes/urls'import { paymentEntryLogic } from './paymentEntryLogic'@@ -17,10 +19,22 @@ const stripeJs = async (): Promise<typeof import('@stripe/stripe-js')> => awaitconst STRIPE_UNAVAILABLE_MESSAGE ="We couldn't load the payment form. Disable any ad blocker and reload the page. If it keeps failing, contact support."+// The support panel offers a ticket only to plans entitled to one, and a failed upgrade is the case+// where the person cannot buy that entitlement. Billing issues are answered on every plan, so that+// flag is what keeps this path reachable. See `canCreateTicket` in sidepanelTicketsLogic.+const supportRequestForError = (error: string): Partial<SupportFormFields> => ({+ kind: 'support',+ billing_issue: true,+ isEmailFormOpen: true,+ message: `I couldn't complete my upgrade. The error shown was:\n\n${error}`,+})+export const PaymentForm = (): JSX.Element => {const { stripeError, isLoading, redirectPath } = useValues(paymentEntryLogic)const { setStripeError, clearErrors, hidePaymentEntryModal, pollAuthorizationStatus, setLoading } =useActions(paymentEntryLogic)+ const { openSupportForm } = useActions(supportLogic)+ const showContactSupport = useFeatureFlag('PAYMENT_ENTRY_CONTACT_SUPPORT')const stripe = useStripe()const elements = useElements()@@ -68,6 +82,18 @@ export const PaymentForm = (): JSX.Element => {</p>{stripeError && <LemonBanner type="error">{stripeError}</LemonBanner>}<div className="flex justify-end deprecated-space-x-2 mt-2">+ {stripeError && showContactSupport && (+ <LemonButton+ type="secondary"+ onClick={() => {+ hidePaymentEntryModal()+ openSupportForm(supportRequestForError(stripeError))+ }}+ data-attr="payment-entry-stripe-error-contact-support"+ >+ Contact support+ </LemonButton>+ )}<LemonButton disabled={isLoading} type="secondary" onClick={hidePaymentEntryModal}>Cancel</LemonButton>@@ -82,6 +108,8 @@ export const PaymentForm = (): JSX.Element => {export const PaymentEntryModal = (): JSX.Element => {const { clientSecret, paymentEntryModalOpen, apiError } = useValues(paymentEntryLogic)const { hidePaymentEntryModal, initiateAuthorization, setStripeError } = useActions(paymentEntryLogic)+ const { openSupportForm } = useActions(supportLogic)+ const showContactSupport = useFeatureFlag('PAYMENT_ENTRY_CONTACT_SUPPORT')const [stripePromise, setStripePromise] = useState<any>(null)useEffect(() => {@@ -126,10 +154,28 @@ export const PaymentEntryModal = (): JSX.Element => {) : apiError ? (<div className="flex flex-col gap-2 my-2"><p className="text-md">- We could not complete your upgrade at this time. Please review the error below and contact- support if you need help.+ {showContactSupport+ ? 'We could not complete your upgrade at this time. Review the error below, and contact us if you need help. We answer billing questions on every plan.'+ : 'We could not complete your upgrade at this time. Please review the error below and contact support if you need help.'}</p><LemonBanner type="error">{apiError}</LemonBanner>+ <div className="flex justify-end gap-2 mt-2">+ <LemonButton type="secondary" onClick={hidePaymentEntryModal}>+ Close+ </LemonButton>+ {showContactSupport && (+ <LemonButton+ type="primary"+ onClick={() => {+ hidePaymentEntryModal()+ openSupportForm(supportRequestForError(apiError))+ }}+ data-attr="payment-entry-api-error-contact-support"+ >+ Contact support+ </LemonButton>+ )}+ </div></div>) : (<div className="min-h-80 flex flex-col justify-center items-center">