: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
fix(billing): wait for stripe before enabling payment submission (#118366)
Pawel Cebula549d21cbe24c
diff --git a/frontend/src/scenes/billing/PaymentEntryModal.test.tsx b/frontend/src/scenes/billing/PaymentEntryModal.test.tsxindex 018bdd029938..661c2f364a2a 100644--- a/frontend/src/scenes/billing/PaymentEntryModal.test.tsx+++ b/frontend/src/scenes/billing/PaymentEntryModal.test.tsx@@ -17,17 +17,21 @@ import { paymentEntryLogic } from './paymentEntryLogic'import { PaymentEntryModal, PaymentForm } from './PaymentEntryModal'const mockConfirmPayment = jest.fn((_: { confirmParams: { return_url: string } }) => new Promise(() => {}))+let mockStripeReady = true+let mockElementsReady = truejest.mock('@stripe/react-stripe-js', () => ({PaymentElement: () => null,- useStripe: () => ({ confirmPayment: mockConfirmPayment }),- useElements: () => ({}),+ useStripe: () => (mockStripeReady ? { confirmPayment: mockConfirmPayment } : null),+ useElements: () => (mockElementsReady ? {} : null),}))const BLOCKED_MESSAGE = "You've been blocked from subscribing. Please contact support."describe('PaymentForm', () => {beforeEach(() => {+ mockStripeReady = true+ mockElementsReady = trueinitKeaTests()paymentEntryLogic.mount()})@@ -37,14 +41,33 @@ describe('PaymentForm', () => {paymentEntryLogic.unmount()})- it('returns from Stripe to the paying organization', async () => {+ it.each([+ { waitingFor: 'Stripe', stripeReady: false, elementsReady: true },+ { waitingFor: 'Elements', stripeReady: true, elementsReady: false },+ { waitingFor: 'Stripe and Elements', stripeReady: false, elementsReady: false },+ ])('waits for $waitingFor before confirming payment', async ({ stripeReady, elementsReady }) => {const organizationId = organizationLogic.values.currentOrganization!.idpaymentEntryLogic.actions.beginPaymentFlow(organizationId, '/project/1/replay')- render(+ mockStripeReady = stripeReady+ mockElementsReady = elementsReady+ const { rerender } = render(+ <Provider>+ <PaymentForm />+ </Provider>+ )+ expect(screen.getByText('Submit').closest('button')).toHaveAttribute('aria-disabled', 'true')+ fireEvent.click(screen.getByText('Submit'))+ expect(mockConfirmPayment).not.toHaveBeenCalled()+ expect(paymentEntryLogic.values.stripeError).toBeNull()++ mockStripeReady = true+ mockElementsReady = true+ rerender(<Provider><PaymentForm /></Provider>)+ expect(screen.getByText('Submit').closest('button')).toHaveAttribute('aria-disabled', 'false')fireEvent.click(screen.getByText('Submit'))await waitFor(() => expect(mockConfirmPayment).toHaveBeenCalledTimes(1))const returnUrl = new URL(mockConfirmPayment.mock.calls[0][0].confirmParams.return_url)diff --git a/frontend/src/scenes/billing/PaymentEntryModal.tsx b/frontend/src/scenes/billing/PaymentEntryModal.tsxindex a3f83dd3a7ad..d831940dddb1 100644--- a/frontend/src/scenes/billing/PaymentEntryModal.tsx+++ b/frontend/src/scenes/billing/PaymentEntryModal.tsx@@ -80,7 +80,7 @@ export const PaymentForm = (): JSX.Element => {<LemonButton disabled={isLoading} type="secondary" onClick={hidePaymentEntryModal}>Cancel</LemonButton>- <LemonButton loading={isLoading} type="primary" onClick={handleSubmit}>+ <LemonButton loading={isLoading || !stripe || !elements} type="primary" onClick={handleSubmit}>Submit</LemonButton></div>