Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ GEMINI_API_KEY=unused_on_self_host
# sentinels and the AUTH_PROVIDER=password|oidc flow never calls WorkOS. (Set
# real values only if you switch AUTH_PROVIDER=workos.)
#
# [placeholder ok] Hosted billing (Razorpay) is still read at boot — leave the
# dummy values exactly as they are.
RAZORPAY_KEY_ID=unused_on_self_host
RAZORPAY_KEY_SECRET=unused_on_self_host
RAZORPAY_WEBHOOK_SECRET=unused_on_self_host
# The open-core (self-host) edition ships with NO payment/billing layer, so
# no RAZORPAY_* variables are required. Leave them unset. (They are declared
# as optional in config/env.ts only so a hosted deployment that layers billing
# on top of core can supply them.)
1 change: 0 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"pino-pretty": "^13.1.3",
"playwright": "^1.61.1",
"postgres": "^3.4.0",
"razorpay": "^2.9.6",
"resend": "^6.17.1",
"turndown": "^7.2.4",
"turndown-plugin-gfm": "^1.0.2",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/scripts/verify-core-only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cd "$(dirname "$0")/.."
echo "== 1. core → gated static-import scan =="
# Gated module paths. A core file importing any of these (outside src/ee/ and the
# gated modules themselves) is a boundary violation to de-tangle.
VIOLATIONS=$(grep -rnE "from '.*(routes/graph|routes/meetings|routes/org|routes/admin|lib/graph/|queue/graph|tools/graph|tools/meeting-context|meeting-end/worker|graph/worker)" src --include="*.ts" \
VIOLATIONS=$(grep -rnE "from '.*(routes/graph|routes/meetings|routes/org|routes/admin|routes/razorpay|routes/billing|lib/razorpay/|lib/graph/|queue/graph|tools/graph|tools/meeting-context|meeting-end/worker|graph/worker)" src --include="*.ts" \
| grep -v "/ee/" \
| grep -vE "src/(routes/(graph|meetings|org|admin)|mcp/tools/(graph|meeting-context)|lib/graph/|queue/graph|workers/(graph|meeting-end))" \
| grep -v "\.test\.ts" || true)
Expand Down
11 changes: 7 additions & 4 deletions apps/api/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,13 @@ const envSchema = z.object({
RATE_LIMIT_USER_PER_DAY: z.coerce.number().int().positive().default(1000),
RATE_LIMIT_TENANT_DAILY_UNITS: z.coerce.number().int().positive().default(50000),

// Billing — Razorpay
RAZORPAY_KEY_ID: z.string().min(1),
RAZORPAY_KEY_SECRET: z.string().min(1),
RAZORPAY_WEBHOOK_SECRET: z.string().min(1),
// Billing — Razorpay. The open-core (self-host) edition ships with NO
// payment/billing layer, so these are optional and unused. They remain
// declared only so a hosted deployment that layers billing on top of core
// can supply them; on self-host leave them unset.
RAZORPAY_KEY_ID: z.string().min(1).optional(),
RAZORPAY_KEY_SECRET: z.string().min(1).optional(),
RAZORPAY_WEBHOOK_SECRET: z.string().min(1).optional(),
RAZORPAY_ENVIRONMENT: z.enum(['test', 'live']).default('test'),

// Recall.ai workspace verification secret (whsec_…) — signs the participant-events
Expand Down
44 changes: 0 additions & 44 deletions apps/api/src/lib/billing/currency.ts

This file was deleted.

36 changes: 0 additions & 36 deletions apps/api/src/lib/billing/seats.ts

This file was deleted.

64 changes: 13 additions & 51 deletions apps/api/src/lib/billing/sync-seats.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,24 @@
/**
* Seat sync utility.
* Seat sync utility (self-host / open-core edition).
*
* Called after any workspace membership change that could affect the
* billable seat count (member added, removed, role changed).
*
* If the workspace has an active Razorpay subscription, this function
* recounts billable writers and updates the subscription quantity via
* the Razorpay API, then stores the new count in our DB.
*
* No-op if the workspace is on the free plan (no active subscription).
* The open-core (self-host) edition ships with NO payment/billing layer:
* there is no active subscription to reconcile, so this is a no-op. It
* remains an exported function so core callers (routes/members.ts,
* routes/invitations.ts, routes/_internal/accept-invite-pending.ts) keep
* their call sites unchanged. Hosted seat-sync lives outside this repo.
*/

import { and, desc, eq, inArray } from 'drizzle-orm';
import { db } from '../../db/index.js';
import { subscriptions } from '../../db/schema.js';
import { countBillableSeats } from './seats.js';

const ACTIVE_STATUSES = ['active', 'trialing', 'created'] as const;

/**
* Re-count writer seats for the workspace and update the Razorpay
* subscription quantity if one is active.
* Re-count writer seats and update the payment provider's subscription
* quantity when one is active.
*
* Safe to call redundantly — it will silently no-op on free workspaces.
* Self-host: always a no-op (no subscriptions, no payment provider).
* Safe to call redundantly.
*/
export async function syncSubscriptionSeats(workspaceId: string): Promise<void> {
// Find the most recent active subscription
const subRows = await db
.select({
id: subscriptions.id,
razorpaySubscriptionId: subscriptions.razorpaySubscriptionId,
status: subscriptions.status,
})
.from(subscriptions)
.where(
and(
eq(subscriptions.workspaceId, workspaceId),
inArray(subscriptions.status, ACTIVE_STATUSES as unknown as string[]),
),
)
.orderBy(desc(subscriptions.createdAt))
.limit(1);

if (subRows.length === 0) return; // free plan — nothing to sync

const { razorpaySubscriptionId } = subRows[0]!;
const billableSeats = await countBillableSeats(workspaceId);

// Update quantity on Razorpay subscription
const { razorpay } = await import('../razorpay/client.js');
await (razorpay.subscriptions.update(
razorpaySubscriptionId,
{ quantity: billableSeats } as Parameters<typeof razorpay.subscriptions.update>[1],
) as Promise<unknown>);

// Persist updated seat count locally
await db
.update(subscriptions)
.set({ billableSeats, quantity: billableSeats, updatedAt: new Date() })
.where(eq(subscriptions.razorpaySubscriptionId, razorpaySubscriptionId));
export async function syncSubscriptionSeats(_workspaceId: string): Promise<void> {
// No billing layer in the open-core edition — nothing to sync.
return;
}
24 changes: 0 additions & 24 deletions apps/api/src/lib/razorpay/client.ts

This file was deleted.

61 changes: 0 additions & 61 deletions apps/api/src/lib/razorpay/customer.ts

This file was deleted.

28 changes: 0 additions & 28 deletions apps/api/src/lib/razorpay/plan-state.ts

This file was deleted.

Loading
Loading