File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { freemius } from '@/lib/freemius';
33import { headers } from 'next/headers' ;
44import { redirect } from 'next/navigation' ;
55import { CustomerPortal } from '@/react-starter/components/customer-portal' ;
6- import FSCheckoutProvider from '@/components/fs -checkout' ;
6+ import AppCheckoutProvider from '@/components/app -checkout-provider ' ;
77import AppMain , { AppContent } from '@/components/app-main' ;
88
99export default async function Billing ( ) {
@@ -23,9 +23,9 @@ export default async function Billing() {
2323 return (
2424 < AppMain title = "Billing" isLoggedIn = { true } >
2525 < AppContent >
26- < FSCheckoutProvider checkout = { checkout . serialize ( ) } >
26+ < AppCheckoutProvider checkout = { checkout . serialize ( ) } >
2727 < CustomerPortal endpoint = { process . env . NEXT_PUBLIC_APP_URL ! + '/api/portal' } />
28- </ FSCheckoutProvider >
28+ </ AppCheckoutProvider >
2929 </ AppContent >
3030 </ AppMain >
3131 ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { headers } from 'next/headers';
44import { examples } from '@/lib/ai' ;
55import AiApp from './ai-app' ;
66import { freemius } from '@/lib/freemius' ;
7- import FSCheckoutProvider from '@/components/fs -checkout' ;
7+ import AppCheckoutProvider from '@/components/app -checkout-provider ' ;
88
99export default async function Dashboard ( ) {
1010 const session = await auth . api . getSession ( {
@@ -18,9 +18,9 @@ export default async function Dashboard() {
1818
1919 return (
2020 < AppMain title = "New Chat" isLoggedIn = { ! ! session } >
21- < FSCheckoutProvider checkout = { checkout . serialize ( ) } >
21+ < AppCheckoutProvider checkout = { checkout . serialize ( ) } >
2222 < AiApp examples = { examples } />
23- </ FSCheckoutProvider >
23+ </ AppCheckoutProvider >
2424 </ AppMain >
2525 ) ;
2626}
Original file line number Diff line number Diff line change 11'use client' ;
22
33import { Subscribe } from '@/react-starter/components/subscribe' ;
4- import { Topup } from '@/react-starter/components/topup' ;
54import { formatNumber } from '@/react-starter/utils/formatter' ;
65
76export default function Credits ( props : { credits ?: number ; hasSubscription : boolean } ) {
@@ -14,9 +13,5 @@ export default function Credits(props: { credits?: number; hasSubscription: bool
1413 </ div >
1514 ) ;
1615
17- if ( hasSubscription ) {
18- return < Topup > { info } </ Topup > ;
19- }
20-
2116 return < Subscribe > { info } </ Subscribe > ;
2217}
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { redirect } from 'next/navigation';
66import { ErrorBoundary } from '@/components/error' ;
77import Credits from './credits' ;
88import { freemius } from '@/lib/freemius' ;
9- import FSCheckoutProvider from '@/components/fs -checkout' ;
9+ import AppCheckoutProvider from '@/components/app -checkout-provider ' ;
1010
1111export default async function CreditsPage ( ) {
1212 const session = await auth . api . getSession ( {
@@ -29,9 +29,9 @@ export default async function CreditsPage() {
2929 < AppMain title = "Credits & Topups" isLoggedIn = { true } >
3030 < AppContent >
3131 < ErrorBoundary >
32- < FSCheckoutProvider checkout = { checkout . serialize ( ) } >
32+ < AppCheckoutProvider checkout = { checkout . serialize ( ) } >
3333 < Credits credits = { credits } hasSubscription = { ! ! entitlement } />
34- </ FSCheckoutProvider >
34+ </ AppCheckoutProvider >
3535 </ ErrorBoundary >
3636 </ AppContent >
3737 </ AppMain >
Original file line number Diff line number Diff line change 11import { freemius } from '@/lib/freemius' ;
22import { deleteEntitlement , renewCreditsFromWebhook , syncEntitlementFromWebhook } from '@/lib/user-entitlement' ;
3+ import { WebhookEventType } from '@freemius/sdk' ;
34
45const listener = freemius . webhook . createListener ( ) ;
56
6- listener . on (
7- [
8- 'license.created' ,
9- 'license.extended' ,
10- 'license.shortened' ,
11- 'license.updated' ,
12- 'license.cancelled' ,
13- 'license.expired' ,
14- 'license.plan.changed' ,
15- ] ,
16- async ( { objects : { license } } ) => {
17- if ( license && license . id ) {
18- await syncEntitlementFromWebhook ( license . id ) ;
19- }
7+ const licenseEvents : WebhookEventType [ ] = [
8+ 'license.created' ,
9+ 'license.extended' ,
10+ 'license.shortened' ,
11+ 'license.updated' ,
12+ 'license.cancelled' ,
13+ 'license.expired' ,
14+ 'license.plan.changed' ,
15+ ] ;
16+
17+ listener . on ( licenseEvents , async ( { objects : { license } } ) => {
18+ if ( license && license . id ) {
19+ await syncEntitlementFromWebhook ( license . id ) ;
2020 }
21- ) ;
21+ } ) ;
2222
2323listener . on ( 'license.deleted' , async ( { data } ) => {
2424 await deleteEntitlement ( data . license_id ) ;
Original file line number Diff line number Diff line change 22
33import { CheckoutProvider } from '@/react-starter/components/checkout-provider' ;
44import { CheckoutSerialized } from '@freemius/sdk' ;
5- import { IconCircleCheck } from '@tabler/icons-react' ;
65import * as React from 'react' ;
76import { toast } from 'sonner' ;
87import { useRouter } from 'next/navigation' ;
98
10- const handlePurchase = ( ) => {
11- toast . success ( `Purchase successful` , {
12- icon : < IconCircleCheck className = "w-6 h-6 text-grow" /> ,
13- description : 'You can now use the feature you just purchased.' ,
14- } ) ;
15- } ;
16-
17- export default function FSCheckoutProvider ( props : { children : React . ReactNode ; checkout : CheckoutSerialized } ) {
9+ export default function AppCheckoutProvider ( props : { children : React . ReactNode ; checkout : CheckoutSerialized } ) {
1810 const router = useRouter ( ) ;
1911
2012 const onAfterSync = React . useCallback ( ( ) => {
21- handlePurchase ( ) ;
13+ toast . success ( `Successfully updated your subscription! Now you can continue using the app.` ) ;
2214 router . refresh ( ) ;
2315 } , [ router ] ) ;
2416
You can’t perform that action at this time.
0 commit comments