Merge pull request #747 from escapade-mckv/tolt

Tolt
This commit is contained in:
Bobbie 2025-06-16 17:26:11 +05:30 committed by GitHub
commit edc2181e02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 37 additions and 29 deletions

View File

@ -14,6 +14,8 @@ from services.supabase import DBConnection
from utils.auth_utils import get_current_user_id_from_jwt from utils.auth_utils import get_current_user_id_from_jwt
from pydantic import BaseModel from pydantic import BaseModel
from utils.constants import MODEL_ACCESS_TIERS, MODEL_NAME_ALIASES from utils.constants import MODEL_ACCESS_TIERS, MODEL_NAME_ALIASES
import os
# Initialize Stripe # Initialize Stripe
stripe.api_key = config.STRIPE_SECRET_KEY stripe.api_key = config.STRIPE_SECRET_KEY
@ -37,6 +39,7 @@ class CreateCheckoutSessionRequest(BaseModel):
price_id: str price_id: str
success_url: str success_url: str
cancel_url: str cancel_url: str
tolt_referral: Optional[str] = None
class CreatePortalSessionRequest(BaseModel): class CreatePortalSessionRequest(BaseModel):
return_url: str return_url: str
@ -542,7 +545,6 @@ async def create_checkout_session(
logger.exception(f"Error updating subscription {existing_subscription.get('id') if existing_subscription else 'N/A'}: {str(e)}") logger.exception(f"Error updating subscription {existing_subscription.get('id') if existing_subscription else 'N/A'}: {str(e)}")
raise HTTPException(status_code=500, detail=f"Error updating subscription: {str(e)}") raise HTTPException(status_code=500, detail=f"Error updating subscription: {str(e)}")
else: else:
# --- Create New Subscription via Checkout Session ---
session = stripe.checkout.Session.create( session = stripe.checkout.Session.create(
customer=customer_id, customer=customer_id,
payment_method_types=['card'], payment_method_types=['card'],
@ -552,7 +554,8 @@ async def create_checkout_session(
cancel_url=request.cancel_url, cancel_url=request.cancel_url,
metadata={ metadata={
'user_id': current_user_id, 'user_id': current_user_id,
'product_id': product_id 'product_id': product_id,
'tolt_referral': request.tolt_referral
}, },
allow_promotion_codes=True allow_promotion_codes=True
) )

View File

@ -3,6 +3,7 @@
import { Separator } from '@/components/ui/separator'; import { Separator } from '@/components/ui/separator';
import Link from 'next/link'; import Link from 'next/link';
import { usePathname } from 'next/navigation'; import { usePathname } from 'next/navigation';
import Script from 'next/script';
export default function PersonalAccountSettingsPage({ export default function PersonalAccountSettingsPage({
children, children,
@ -16,30 +17,30 @@ export default function PersonalAccountSettingsPage({
{ name: 'Billing', href: '/settings/billing' }, { name: 'Billing', href: '/settings/billing' },
]; ];
return ( return (
<div className="space-y-6 w-full"> <>
<Separator className="border-subtle dark:border-white/10" /> <div className="space-y-6 w-full">
<div className="flex flex-col space-y-8 lg:flex-row lg:space-x-12 lg:space-y-0 w-full max-w-6xl mx-auto px-4"> <Separator className="border-subtle dark:border-white/10" />
<aside className="lg:w-1/4 p-1"> <div className="flex flex-col space-y-8 lg:flex-row lg:space-x-12 lg:space-y-0 w-full max-w-6xl mx-auto px-4">
<nav className="flex flex-col space-y-1"> <aside className="lg:w-1/4 p-1">
{items.map((item) => ( <nav className="flex flex-col space-y-1">
<Link {items.map((item) => (
key={item.href} <Link
href={item.href} key={item.href}
className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${ href={item.href}
pathname === item.href className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${pathname === item.href
? 'bg-accent text-accent-foreground' ? 'bg-accent text-accent-foreground'
: 'text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground' : 'text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground'}`}
}`} >
> {item.name}
{item.name} </Link>
</Link> ))}
))} </nav>
</nav> </aside>
</aside> <div className="flex-1 bg-card-bg dark:bg-background-secondary p-6 rounded-2xl border border-subtle dark:border-white/10 shadow-custom">
<div className="flex-1 bg-card-bg dark:bg-background-secondary p-6 rounded-2xl border border-subtle dark:border-white/10 shadow-custom"> {children}
{children} </div>
</div> </div>
</div> </div>
</div> </>
); );
} }

View File

@ -123,13 +123,12 @@ export default function RootLayout({
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-PCHSN4M2');`} })(window,document,'script','dataLayer','GTM-PCHSN4M2');`}
</Script> </Script>
{/* End Google Tag Manager */} <Script async src="https://cdn.tolt.io/tolt.js" data-tolt={process.env.NEXT_PUBLIC_TOLT_REFERRAL_ID}></Script>
</head> </head>
<body <body
className={`${geistSans.variable} ${geistMono.variable} antialiased font-sans bg-background`} className={`${geistSans.variable} ${geistMono.variable} antialiased font-sans bg-background`}
> >
{/* Google Tag Manager (noscript) */}
<noscript> <noscript>
<iframe <iframe
src="https://www.googletagmanager.com/ns.html?id=GTM-PCHSN4M2" src="https://www.googletagmanager.com/ns.html?id=GTM-PCHSN4M2"

View File

@ -1500,6 +1500,7 @@ export interface CreateCheckoutSessionRequest {
price_id: string; price_id: string;
success_url: string; success_url: string;
cancel_url: string; cancel_url: string;
referral_id?: string;
} }
export interface CreatePortalSessionRequest { export interface CreatePortalSessionRequest {
@ -1588,14 +1589,18 @@ export const createCheckoutSession = async (
if (!session?.access_token) { if (!session?.access_token) {
throw new NoAccessTokenAvailableError(); throw new NoAccessTokenAvailableError();
} }
const requestBody = { ...request, tolt_referral: window.tolt_referral };
console.log('Tolt Referral ID:', requestBody.tolt_referral);
const response = await fetch(`${API_URL}/billing/create-checkout-session`, { const response = await fetch(`${API_URL}/billing/create-checkout-session`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
Authorization: `Bearer ${session.access_token}`, Authorization: `Bearer ${session.access_token}`,
}, },
body: JSON.stringify(request), body: JSON.stringify(requestBody),
}); });
if (!response.ok) { if (!response.ok) {