Skip to content

Enhance payment system #3112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set check_function_bodies = off;

CREATE OR REPLACE FUNCTION public.check_ws_creator(ws_id uuid)
RETURNS boolean
LANGUAGE plpgsql
AS $function$BEGIN
RETURN (
(SELECT creator_id FROM public.workspaces WHERE id = ws_id) = auth.uid()
AND
NOT EXISTS (
SELECT 1 FROM public.workspace_subscription
WHERE public.workspace_subscription.ws_id = ws_id
)
);
END;$function$
;


Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
create table "public"."workspace_subscription_products" (
"id" uuid not null,
"created_at" timestamp with time zone not null default now(),
"name" text,
"description" text,
"price" real,
"recurring_interval" text default 'month'::text
);


alter table "public"."workspace_subscription" add column "product_id" uuid;

CREATE UNIQUE INDEX workspace_subscription_products_pkey ON public.workspace_subscription_products USING btree (id);

alter table "public"."workspace_subscription_products" add constraint "workspace_subscription_products_pkey" PRIMARY KEY using index "workspace_subscription_products_pkey";

alter table "public"."workspace_subscription" add constraint "workspace_subscription_product_id_fkey" FOREIGN KEY (product_id) REFERENCES workspace_subscription_products(id) not valid;

alter table "public"."workspace_subscription" validate constraint "workspace_subscription_product_id_fkey";

grant delete on table "public"."workspace_subscription_products" to "anon";

grant insert on table "public"."workspace_subscription_products" to "anon";

grant references on table "public"."workspace_subscription_products" to "anon";

grant select on table "public"."workspace_subscription_products" to "anon";

grant trigger on table "public"."workspace_subscription_products" to "anon";

grant truncate on table "public"."workspace_subscription_products" to "anon";

grant update on table "public"."workspace_subscription_products" to "anon";

grant delete on table "public"."workspace_subscription_products" to "authenticated";

grant insert on table "public"."workspace_subscription_products" to "authenticated";

grant references on table "public"."workspace_subscription_products" to "authenticated";

grant select on table "public"."workspace_subscription_products" to "authenticated";

grant trigger on table "public"."workspace_subscription_products" to "authenticated";

grant truncate on table "public"."workspace_subscription_products" to "authenticated";

grant update on table "public"."workspace_subscription_products" to "authenticated";

grant delete on table "public"."workspace_subscription_products" to "service_role";

grant insert on table "public"."workspace_subscription_products" to "service_role";

grant references on table "public"."workspace_subscription_products" to "service_role";

grant select on table "public"."workspace_subscription_products" to "service_role";

grant trigger on table "public"."workspace_subscription_products" to "service_role";

grant truncate on table "public"."workspace_subscription_products" to "service_role";

grant update on table "public"."workspace_subscription_products" to "service_role";


13 changes: 13 additions & 0 deletions apps/db/supabase/migrations/20250618082551_new_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
drop policy "only allow owner of the user to buy subscription" on "public"."workspace_subscription";

create policy "only allow owner of the user to buy subscription"
on "public"."workspace_subscription"
as permissive
for insert
to authenticated
with check ((auth.uid() = ( SELECT workspaces.creator_id
FROM workspaces
WHERE (workspaces.id = workspace_subscription.ws_id))));



13 changes: 13 additions & 0 deletions apps/db/supabase/migrations/20250618083711_new_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
drop policy "only allow owner of the user to buy subscription" on "public"."workspace_subscription";

create policy "only allow owner of the user to buy subscription"
on "public"."workspace_subscription"
as permissive
for insert
to authenticated
with check ((EXISTS ( SELECT 1
FROM workspaces
WHERE ((workspaces.id = workspace_subscription.ws_id) AND (workspaces.creator_id = auth.uid())))));



19 changes: 19 additions & 0 deletions apps/db/supabase/migrations/20250618085435_new_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set check_function_bodies = off;

CREATE OR REPLACE FUNCTION public.check_ws_creator(ws_id uuid)
RETURNS boolean
LANGUAGE plpgsql
AS $function$BEGIN
RETURN (
(SELECT creator_id FROM public.workspaces WHERE id = ws_id)
= auth.uid()
AND
NOT EXISTS (
SELECT 1 FROM public.workspace_subscription
WHERE public.workspace_subscription.ws_id = ws_id
)
);
END;$function$
;


19 changes: 19 additions & 0 deletions apps/db/supabase/migrations/20250618085749_new_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set check_function_bodies = off;

CREATE OR REPLACE FUNCTION public.check_ws_creator(ws_id uuid)
RETURNS boolean
LANGUAGE plpgsql
AS $function$BEGIN
RETURN (
(
SELECT creator_id FROM public.workspaces WHERE id = check_ws_creator.ws_id
) = auth.uid()
AND NOT EXISTS (
SELECT 1 FROM public.workspace_subscription
WHERE public.workspace_subscription.ws_id = check_ws_creator.ws_id
)
);
END;$function$
;


13 changes: 13 additions & 0 deletions apps/db/supabase/migrations/20250618090740_new_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
drop policy "allow select for users that are in the workspace" on "public"."workspace_subscription";

create policy "allow select for users that are in the workspace"
on "public"."workspace_subscription"
as permissive
for select
to authenticated
using ((EXISTS ( SELECT 1
FROM workspace_members wm
WHERE ((wm.user_id = auth.uid()) AND (wm.ws_id = workspace_subscription.ws_id)))));



Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import PurchaseLink from './data-polar-checkout';
import { Button } from '@tuturuuu/ui/button';
import { ArrowUpCircle, CheckCircle, CreditCard } from 'lucide-react';
import { ArrowUpCircle, CheckCircle } from 'lucide-react';
import { useState } from 'react';

// Define types for the props we're passing from the server component
Expand Down Expand Up @@ -65,8 +65,8 @@ export function BillingClient({
</div>
</div>

<div className="grid grid-cols-1 gap-8 md:grid-cols-3">
<div className="col-span-2">
<div className="grid grid-cols-1 gap-8">
<div>
<div className="mb-6">
<h3 className="mb-1 text-xl font-bold text-card-foreground">
{currentPlan.name}
Expand All @@ -79,7 +79,7 @@ export function BillingClient({
</p>
</div>

<div className="mb-6 grid grid-cols-2 gap-4">
<div className="mb-6 grid grid-cols-2 gap-6 md:grid-cols-4">
<div>
<p className="text-sm text-muted-foreground">Start Date</p>
<p className="font-medium text-card-foreground">
Expand All @@ -96,61 +96,38 @@ export function BillingClient({
</div>
</div>

<div className="mb-6">
<h4 className="mb-2 font-medium text-card-foreground">
Features:
<div className="mb-8">
<h4 className="mb-4 font-medium text-card-foreground">
Plan Features:
</h4>
<ul className="grid grid-cols-1 gap-2 md:grid-cols-2">
<ul className="grid grid-cols-1 gap-3 md:grid-cols-2 lg:grid-cols-3">
{currentPlan.features?.map((feature, index) => (
<li
key={index}
className="flex items-center text-card-foreground"
>
<CheckCircle className="mr-2 h-5 w-5 text-primary" />
{feature}
<CheckCircle className="mr-3 h-5 w-5 flex-shrink-0 text-primary" />
<span className="text-sm">{feature}</span>
</li>
))}
</ul>
</div>

<div className="mt-6 flex flex-wrap gap-3">
<div className="flex flex-wrap gap-3">
<Button
disabled={!isCreator}
onClick={() => setShowUpgradeOptions(!showUpgradeOptions)}
className="flex items-center"
size="lg"
>
<ArrowUpCircle className="mr-1 h-5 w-5" />
{showUpgradeOptions ? 'Hide Options' : 'Upgrade Plan'}
<ArrowUpCircle className="mr-2 h-5 w-5" />
{showUpgradeOptions ? 'Hide Upgrade Options' : 'Upgrade Plan'}
</Button>
<Button variant="outline" className="border-border">
<Button variant="outline" size="lg" className="border-border">
Cancel Subscription
</Button>
</div>
</div>

<div className="rounded-lg border border-border bg-accent/30 p-6">
<h3 className="mb-4 text-lg font-semibold text-card-foreground">
Payment Method
</h3>
<div className="mb-4 flex items-center">
<CreditCard className="mr-3 h-8 w-8 text-muted-foreground" />
<div>
<p className="font-medium text-card-foreground">
Visa ending in 4242
</p>
<p className="text-sm text-muted-foreground">Expires 05/2025</p>
</div>
</div>
<div className="mt-6">
<Button
variant="outline"
size="sm"
className="text-sm font-medium"
>
Update payment method
</Button>
</div>
</div>
</div>
</div>

Expand Down
Loading