@@ -14,20 +14,24 @@ type PriceDetails = {
1414} ;
1515
1616export type CachedPrices = {
17- monthlyPrice : PriceDetails | null ;
18- yearlyPrice : PriceDetails | null ;
17+ managedMonthlyPrice : PriceDetails | null ;
18+ managedYearlyPrice : PriceDetails | null ;
19+ starterMonthlyPrice : PriceDetails | null ;
20+ starterYearlyPrice : PriceDetails | null ;
1921 fetchedAt : number ;
2022} ;
2123
2224const CACHE_DURATION = 30 * 60 ; // 30 minutes in seconds
2325
2426export async function fetchStripePriceDetails ( ) : Promise < CachedPrices > {
2527 // Fetch from Stripe
26- const monthlyPriceId = env . NEXT_PUBLIC_STRIPE_SUBSCRIPTION_MANAGED_MONTHLY_PRICE_ID ;
27- const yearlyPriceId = env . NEXT_PUBLIC_STRIPE_SUBSCRIPTION_MANAGED_YEARLY_PRICE_ID ;
28+ const managedMonthlyPriceId = env . NEXT_PUBLIC_STRIPE_SUBSCRIPTION_MANAGED_MONTHLY_PRICE_ID ;
29+ const managedYearlyPriceId = env . NEXT_PUBLIC_STRIPE_SUBSCRIPTION_MANAGED_YEARLY_PRICE_ID ;
30+ const starterMonthlyPriceId = env . NEXT_PUBLIC_STRIPE_SUBSCRIPTION_STARTER_MONTHLY_PRICE_ID ;
31+ const starterYearlyPriceId = env . NEXT_PUBLIC_STRIPE_SUBSCRIPTION_STARTER_YEARLY_PRICE_ID ;
2832
2933 // Create a unique cache key that includes the price IDs
30- const cacheKey = `stripe:managed -prices:${ monthlyPriceId || 'none' } :${ yearlyPriceId || 'none' } ` ;
34+ const cacheKey = `stripe:all -prices:${ managedMonthlyPriceId || 'none' } :${ managedYearlyPriceId || 'none' } : ${ starterMonthlyPriceId || 'none' } : ${ starterYearlyPriceId || 'none' } ` ;
3135
3236 try {
3337 // Check cache first
@@ -39,17 +43,19 @@ export async function fetchStripePriceDetails(): Promise<CachedPrices> {
3943 console . error ( '[STRIPE] Error reading from cache:' , error ) ;
4044 }
4145
42- let monthlyPrice : PriceDetails | null = null ;
43- let yearlyPrice : PriceDetails | null = null ;
46+ let managedMonthlyPrice : PriceDetails | null = null ;
47+ let managedYearlyPrice : PriceDetails | null = null ;
48+ let starterMonthlyPrice : PriceDetails | null = null ;
49+ let starterYearlyPrice : PriceDetails | null = null ;
4450
4551 try {
46- // Fetch monthly price if ID exists
47- if ( monthlyPriceId ) {
48- const price = await stripe . prices . retrieve ( monthlyPriceId , {
52+ // Fetch managed monthly price if ID exists
53+ if ( managedMonthlyPriceId ) {
54+ const price = await stripe . prices . retrieve ( managedMonthlyPriceId , {
4955 expand : [ 'product' ] ,
5056 } ) ;
5157
52- monthlyPrice = {
58+ managedMonthlyPrice = {
5359 id : price . id ,
5460 unitAmount : price . unit_amount ,
5561 currency : price . currency ,
@@ -61,13 +67,49 @@ export async function fetchStripePriceDetails(): Promise<CachedPrices> {
6167 } ;
6268 }
6369
64- // Fetch yearly price if ID exists
65- if ( yearlyPriceId ) {
66- const price = await stripe . prices . retrieve ( yearlyPriceId , {
70+ // Fetch managed yearly price if ID exists
71+ if ( managedYearlyPriceId ) {
72+ const price = await stripe . prices . retrieve ( managedYearlyPriceId , {
6773 expand : [ 'product' ] ,
6874 } ) ;
6975
70- yearlyPrice = {
76+ managedYearlyPrice = {
77+ id : price . id ,
78+ unitAmount : price . unit_amount ,
79+ currency : price . currency ,
80+ interval : price . recurring ?. interval ?? null ,
81+ productName :
82+ price . product && typeof price . product === 'object' && ! price . product . deleted
83+ ? price . product . name
84+ : null ,
85+ } ;
86+ }
87+
88+ // Fetch starter monthly price if ID exists
89+ if ( starterMonthlyPriceId ) {
90+ const price = await stripe . prices . retrieve ( starterMonthlyPriceId , {
91+ expand : [ 'product' ] ,
92+ } ) ;
93+
94+ starterMonthlyPrice = {
95+ id : price . id ,
96+ unitAmount : price . unit_amount ,
97+ currency : price . currency ,
98+ interval : price . recurring ?. interval ?? null ,
99+ productName :
100+ price . product && typeof price . product === 'object' && ! price . product . deleted
101+ ? price . product . name
102+ : null ,
103+ } ;
104+ }
105+
106+ // Fetch starter yearly price if ID exists
107+ if ( starterYearlyPriceId ) {
108+ const price = await stripe . prices . retrieve ( starterYearlyPriceId , {
109+ expand : [ 'product' ] ,
110+ } ) ;
111+
112+ starterYearlyPrice = {
71113 id : price . id ,
72114 unitAmount : price . unit_amount ,
73115 currency : price . currency ,
@@ -83,8 +125,10 @@ export async function fetchStripePriceDetails(): Promise<CachedPrices> {
83125 }
84126
85127 const priceData : CachedPrices = {
86- monthlyPrice,
87- yearlyPrice,
128+ managedMonthlyPrice,
129+ managedYearlyPrice,
130+ starterMonthlyPrice,
131+ starterYearlyPrice,
88132 fetchedAt : Date . now ( ) ,
89133 } ;
90134
0 commit comments