mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
feat(billing): integrate Stripe for subscription management and billing access
- Added billing-related fields to the User model in the database. - Implemented functions for managing billing access, including trial periods and subscription statuses. - Created new billing utility functions for Stripe integration. - Updated onboarding page to include billing overview and workspace creation eligibility. - Enhanced route access checks to require billing access for certain actions. - Implemented cleanup scripts for expired billing workspaces and associated media. - Updated header component to conditionally show app navigation based on billing access. - Added new migrations for billing-related database changes.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { auth } from '@/lib/auth';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { db } from '@/lib/db';
|
||||
import { buildBillingAccessWhereInput, getBillingOverview } from '@/lib/billing';
|
||||
import { hasCollaboratorBillingBackedAccess, requireBillingAccessOrRedirect } from '@/lib/route-access';
|
||||
import { WorkspacesClient } from './workspaces-client';
|
||||
|
||||
export default async function WorkspacesPage({
|
||||
@@ -13,19 +15,24 @@ export default async function WorkspacesPage({
|
||||
redirect('/login');
|
||||
}
|
||||
|
||||
const hasCollaboratorAccess = await hasCollaboratorBillingBackedAccess(session.user.id);
|
||||
if (!hasCollaboratorAccess) {
|
||||
await requireBillingAccessOrRedirect({ userId: session.user.id });
|
||||
}
|
||||
|
||||
const resolvedSearchParams = await searchParams;
|
||||
const page = Number(resolvedSearchParams?.page) || 1;
|
||||
const pageSize = 20;
|
||||
const skip = (page - 1) * pageSize;
|
||||
|
||||
const [workspaces, totalWorkspaces] = await Promise.all([
|
||||
const [workspaces, totalWorkspaces, billing] = await Promise.all([
|
||||
db.workspace.findMany({
|
||||
skip,
|
||||
take: pageSize,
|
||||
where: {
|
||||
OR: [
|
||||
{ ownerId: session.user.id },
|
||||
{ members: { some: { userId: session.user.id } } },
|
||||
{ ownerId: session.user.id, owner: buildBillingAccessWhereInput() },
|
||||
{ members: { some: { userId: session.user.id } }, owner: buildBillingAccessWhereInput() },
|
||||
],
|
||||
},
|
||||
include: {
|
||||
@@ -42,11 +49,12 @@ export default async function WorkspacesPage({
|
||||
db.workspace.count({
|
||||
where: {
|
||||
OR: [
|
||||
{ ownerId: session.user.id },
|
||||
{ members: { some: { userId: session.user.id } } },
|
||||
{ ownerId: session.user.id, owner: buildBillingAccessWhereInput() },
|
||||
{ members: { some: { userId: session.user.id } }, owner: buildBillingAccessWhereInput() },
|
||||
],
|
||||
}
|
||||
})
|
||||
}),
|
||||
getBillingOverview(session.user.id),
|
||||
]);
|
||||
|
||||
const totalPages = Math.ceil(totalWorkspaces / pageSize);
|
||||
@@ -60,6 +68,11 @@ export default async function WorkspacesPage({
|
||||
}));
|
||||
|
||||
return (
|
||||
<WorkspacesClient workspaces={serializedWorkspaces} totalPages={totalPages} currentPage={page} />
|
||||
<WorkspacesClient
|
||||
workspaces={serializedWorkspaces}
|
||||
totalPages={totalPages}
|
||||
currentPage={page}
|
||||
workspaceCreation={billing.workspaceCreation}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user