feat(cli): support Polar payments with Convex#994
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThis PR removes Convex and frontend-specific restrictions on Polar payments, enabling Polar as a payment option for Convex-backed applications and native-only frontends. It adds Convex Polar backend wiring, environment and dependency generation, web and native UI/payment flows, post-install guidance, and integration tests. ChangesPolar Payments for Convex and Native Frontends
Possibly Related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/template-generator/src/templates.generated.ts (1)
30284-30289: 💤 Low valueStub template is scaffolded but never used.
The
get-payment.tsserver function returnsnulland is not imported anywhere in the TanStack Start dashboard template. The dashboard uses Convex queries (api.polar.getCurrentSubscription,api.polar.listAllProducts) directly instead. This creates a dead file in scaffolded projects that may confuse users.Consider either removing this stub or documenting its intended future purpose with a comment in the generated file.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cf75deeb-3405-4ff7-b9ea-9691e006fa25
📒 Files selected for processing (17)
apps/cli/src/helpers/core/post-installation.tsapps/cli/src/prompts/payments.tsapps/cli/test/auth.test.tsapps/web/src/app/(home)/new/_components/utils.tspackages/template-generator/src/processors/env-vars.tspackages/template-generator/src/processors/payments-deps.tspackages/template-generator/src/template-handlers/payments.tspackages/template-generator/src/templates.generated.tspackages/template-generator/src/utils/add-deps.tspackages/template-generator/templates/auth/better-auth/convex/backend/convex/http.ts.hbspackages/template-generator/templates/auth/better-auth/convex/web/react/next/src/app/dashboard/page.tsx.hbspackages/template-generator/templates/auth/better-auth/convex/web/react/react-router/src/routes/dashboard.tsx.hbspackages/template-generator/templates/auth/better-auth/convex/web/react/tanstack-router/src/routes/dashboard.tsx.hbspackages/template-generator/templates/auth/better-auth/convex/web/react/tanstack-start/src/routes/dashboard.tsx.hbspackages/template-generator/templates/backend/convex/packages/backend/convex/convex.config.ts.hbspackages/template-generator/templates/payments/polar/convex/backend/convex/polar.ts.hbspackages/template-generator/templates/payments/polar/convex/web/react/tanstack-start/src/functions/get-payment.ts.hbs
💤 Files with no reviewable changes (1)
- apps/web/src/app/(home)/new/_components/utils.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/template-generator/src/template-handlers/payments.ts (1)
20-29:⚠️ Potential issue | 🟠 Major | ⚡ Quick winConvex branch returns too early and skips all web payment templates.
Line 28 exits before the web generation block (Line 39+), so Convex projects won’t get payment UI templates. That breaks the Convex+Polar scaffolding flow.
Suggested fix
if (config.backend === "convex") { processTemplatesFromPrefix( vfs, templates, `payments/${config.payments}/convex/backend`, "packages/backend", config, ); - return; } else if (config.backend !== "none") { processTemplatesFromPrefix( vfs, templates, `payments/${config.payments}/server/base`, "packages/auth", config, ); }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 26d02f21-53cd-43f4-9729-6a3799e00f61
📒 Files selected for processing (3)
apps/cli/test/auth.test.tspackages/template-generator/src/template-handlers/payments.tspackages/template-generator/src/templates.generated.ts
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (2)
apps/cli/test/auth.test.ts (2)
414-528: 💤 Low valueConsider extracting a shared test helper to reduce duplication.
The two test loops (lines 417-474 and 477-527) have similar structure: both iterate over
nativePolarFrontends, read the same native files, and check similar patterns. A shared helper function could reduce maintenance burden:async function validateNativePolarIntegration( projectDir: string, frontend: string, backendSpecificChecks: (files: Record<string, string>) => void ) { const nativeIndexFile = await fs.readFile( path.join(projectDir, "apps/native/app/(drawer)/index.tsx"), "utf8" ); // ... read other common files // Common assertions expect(nativeIndexFile).toContain("Upgrade to Pro"); expect(nativeIndexFile).toContain("Manage Subscription"); // Backend-specific assertions backendSpecificChecks({ nativeIndexFile, ... }); }
414-595: ⚡ Quick winAdd negative test case for Polar without Better Auth.
The new tests validate successful Polar integration scenarios, but there's no explicit test confirming that Polar is rejected when Better Auth is not selected. According to the compatibility rules, Polar requires Better Auth.
📋 Suggested test case
it("should fail with Polar payments without Better Auth", async () => { const result = await runTRPCTest({ projectName: "polar-no-better-auth-fail", auth: "clerk", // or "none" payments: "polar", backend: "hono", runtime: "bun", database: "sqlite", orm: "drizzle", api: "trpc", frontend: ["native-bare"], addons: ["turborepo"], examples: ["none"], dbSetup: "none", webDeploy: "none", serverDeploy: "none", install: false, expectError: true, }); expectError(result, "Polar requires Better Auth"); });
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 24e905ac-d7f5-4018-93b6-8bc887639b43
📒 Files selected for processing (20)
apps/cli/src/prompts/payments.tsapps/cli/src/utils/compatibility-rules.tsapps/cli/test/auth.test.tsapps/cli/test/matrix/oracle.tsapps/web/src/app/(home)/new/_components/utils.tsapps/web/test/stack-builder-compatibility.test.tspackages/template-generator/src/processors/env-vars.tspackages/template-generator/src/templates.generated.tspackages/template-generator/templates/auth/better-auth/native/bare/app/(drawer)/index.tsx.hbspackages/template-generator/templates/auth/better-auth/native/base/lib/auth-client.ts.hbspackages/template-generator/templates/auth/better-auth/native/unistyles/app/(drawer)/index.tsx.hbspackages/template-generator/templates/auth/better-auth/native/uniwind/app/(drawer)/index.tsx.hbspackages/template-generator/templates/auth/better-auth/web/astro/src/lib/auth-client.ts.hbspackages/template-generator/templates/auth/better-auth/web/nuxt/app/plugins/auth-client.ts.hbspackages/template-generator/templates/auth/better-auth/web/react/base/src/lib/auth-client.ts.hbspackages/template-generator/templates/auth/better-auth/web/solid/src/lib/auth-client.ts.hbspackages/template-generator/templates/auth/better-auth/web/svelte/src/lib/auth-client.ts.hbspackages/template-generator/templates/frontend/native/bare/app/(drawer)/index.tsx.hbspackages/template-generator/templates/frontend/native/unistyles/app/(drawer)/index.tsx.hbspackages/template-generator/templates/frontend/native/uniwind/app/(drawer)/index.tsx.hbs
💤 Files with no reviewable changes (2)
- apps/cli/test/matrix/oracle.ts
- apps/web/src/app/(home)/new/_components/utils.ts
✅ Files skipped from review due to trivial changes (2)
- packages/template-generator/templates/auth/better-auth/web/nuxt/app/plugins/auth-client.ts.hbs
- packages/template-generator/templates/auth/better-auth/web/react/base/src/lib/auth-client.ts.hbs
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7ef1e7d7-65cf-4212-a451-55da30dd4c09
📒 Files selected for processing (2)
packages/template-generator/src/templates.generated.tspackages/template-generator/templates/payments/polar/convex/backend/convex/polar.ts.hbs
This reverts commit 60084d8.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/template-generator/templates/auth/better-auth/convex/web/react/react-router/src/routes/dashboard.tsx.hbs (1)
33-55:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDecouple portal access from recurring-product availability.
If a user has an active subscription but
productshas no recurring item, the current branch shows “No recurring plans available.” and hidesCustomerPortalLink. That blocks subscription management for active customers.Suggested fix
{products === undefined || subscription === undefined ? ( <p>Loading subscription options...</p> - ) : product ? ( - hasActiveSubscription ? ( - <CustomerPortalLink - polarApi={api.polar} - className={buttonVariants({ variant: "outline" })} - > - Manage Subscription - </CustomerPortalLink> - ) : ( + ) : hasActiveSubscription ? ( + <CustomerPortalLink + polarApi={api.polar} + className={buttonVariants({ variant: "outline" })} + > + Manage Subscription + </CustomerPortalLink> + ) : product ? ( <CheckoutLink polarApi={api.polar} productIds={[product.id]} embed={false} className={buttonVariants({ variant: "default" })} > Upgrade </CheckoutLink> - ) ) : ( <p>No recurring plans available.</p> )}packages/template-generator/src/templates.generated.ts (1)
3623-3655:⚠️ Potential issue | 🟠 Major | ⚡ Quick winKeep the customer portal available when no recurring product is returned.
These branches now gate both CTAs behind
product ? ... : ..., so a user with an existing subscription loses the Manage Subscription path wheneverlistAllProductsreturns no recurring plan. That blocks billing management for current subscribers.Suggested branch order
- {product ? ( - hasActiveSubscription ? ( - <CustomerPortalLink ...> - Manage Subscription - </CustomerPortalLink> - ) : ( - <CheckoutLink ...> - Upgrade to Pro - </CheckoutLink> - ) - ) : ( - <p>No recurring plans available.</p> - )} + {hasActiveSubscription ? ( + <CustomerPortalLink ...> + Manage Subscription + </CustomerPortalLink> + ) : product ? ( + <CheckoutLink ...> + Upgrade to Pro + </CheckoutLink> + ) : ( + <p>No recurring plans available.</p> + )}Also applies to: 4413-4445, 4859-4891, 5320-5352
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4264d531-8ed3-4b1f-9a00-1aa11caf7ee3
📒 Files selected for processing (5)
packages/template-generator/src/templates.generated.tspackages/template-generator/templates/auth/better-auth/convex/web/react/next/src/app/dashboard/page.tsx.hbspackages/template-generator/templates/auth/better-auth/convex/web/react/react-router/src/routes/dashboard.tsx.hbspackages/template-generator/templates/auth/better-auth/convex/web/react/tanstack-router/src/routes/dashboard.tsx.hbspackages/template-generator/templates/auth/better-auth/convex/web/react/tanstack-start/src/routes/dashboard.tsx.hbs
Summary
/polar/successendpoints, then redirect back only to Expo/app schemes for the final WebBrowser deep linkreact-native-screens@4.25.2)/newstack builder for mixed web+native Polar selections, including Convex Better AuthDocs checked
@convex-dev/polar@0.9.1package exports/peers:@convex-dev/polar/convex.config.js,@convex-dev/polar/react,@polar-sh/sdk >=0.45.0,@polar-sh/checkout >=0.1.10@polar-sh/better-auth@1.8.4package exports: server checkout/portal endpoints plus web-only client checkout embedVerification
bun run check/Users/aman/dev/test/my-better-t-app-1/apps/native:npx expo install --checkbun test apps/cli/test/frontend.test.ts apps/cli/test/pnpm-workspace.test.tscd apps/cli && BTS_SKIP_EXTERNAL_COMMANDS=1 BTS_TEST_MODE=1 bun test --bail=5(579 pass, 9 skipped generated install/build samples, 0 fail)BTS_MATRIX_MODE=smoke bun test apps/cli/test/matrix/create-matrix.test.ts(282 pass, 0 fail)bun test apps/web/test/stack-builder-compatibility.test.ts(13 pass, including mixed web+native Polar builder cases)bun test apps/cli/test/auth.test.ts --test-name-pattern Polarbun test apps/cli/test/auth.test.ts(73 pass, 0 fail)cd packages/template-generator && bun run build/Users/aman/dev/test/my-better-t-app-1/packages/backend:bunx convex dev --once --typecheck=enable/Users/aman/dev/test/my-better-t-app-1/apps/web:bun run build/Users/aman/dev/test/my-better-t-app-1:bun run check-types/Users/aman/dev/test/my-better-t-app-2/packages/backend:bunx convex dev --once --typecheck=enable/Users/aman/dev/test/my-better-t-app-2:bunx tsc --noEmit -p apps/native/tsconfig.json/Users/aman/dev/test/my-better-t-app-2: verified Convex/polar/success?returnUrl=exp%3A%2F%2F192.168.1.4%3A8081%2F--%2Freturns302 Location: exp://192.168.1.4:8081/--//Users/aman/dev/test/my-better-t-app-2: verified Convex/polar/success?returnUrl=https%3A%2F%2Fevil.example%2Freturns400Summary by CodeRabbit
New Features
Improvements
Tests