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 pydantic import BaseModel
from utils.constants import MODEL_ACCESS_TIERS, MODEL_NAME_ALIASES
import os
# Initialize Stripe
stripe.api_key = config.STRIPE_SECRET_KEY
@ -37,6 +39,7 @@ class CreateCheckoutSessionRequest(BaseModel):
price_id: str
success_url: str
cancel_url: str
tolt_referral: Optional[str] = None
class CreatePortalSessionRequest(BaseModel):
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)}")
raise HTTPException(status_code=500, detail=f"Error updating subscription: {str(e)}")
else:
# --- Create New Subscription via Checkout Session ---
session = stripe.checkout.Session.create(
customer=customer_id,
payment_method_types=['card'],
@ -552,7 +554,8 @@ async def create_checkout_session(
cancel_url=request.cancel_url,
metadata={
'user_id': current_user_id,
'product_id': product_id
'product_id': product_id,
'tolt_referral': request.tolt_referral
},
allow_promotion_codes=True
)

View File

@ -3,6 +3,7 @@
import { Separator } from '@/components/ui/separator';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import Script from 'next/script';
export default function PersonalAccountSettingsPage({
children,
@ -16,6 +17,7 @@ export default function PersonalAccountSettingsPage({
{ name: 'Billing', href: '/settings/billing' },
];
return (
<>
<div className="space-y-6 w-full">
<Separator className="border-subtle dark:border-white/10" />
<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">
@ -25,11 +27,9 @@ export default function PersonalAccountSettingsPage({
<Link
key={item.href}
href={item.href}
className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${
pathname === item.href
className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${pathname === item.href
? '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}
</Link>
@ -41,5 +41,6 @@ export default function PersonalAccountSettingsPage({
</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);
})(window,document,'script','dataLayer','GTM-PCHSN4M2');`}
</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>
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased font-sans bg-background`}
>
{/* Google Tag Manager (noscript) */}
<noscript>
<iframe
src="https://www.googletagmanager.com/ns.html?id=GTM-PCHSN4M2"

View File

@ -1500,6 +1500,7 @@ export interface CreateCheckoutSessionRequest {
price_id: string;
success_url: string;
cancel_url: string;
referral_id?: string;
}
export interface CreatePortalSessionRequest {
@ -1589,13 +1590,17 @@ export const createCheckoutSession = async (
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`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${session.access_token}`,
},
body: JSON.stringify(request),
body: JSON.stringify(requestBody),
});
if (!response.ok) {