From 946da7ce60d3e305ed2067b7fad28f90a870c971 Mon Sep 17 00:00:00 2001 From: Ashad Qureshi Date: Mon, 30 Jun 2025 11:06:15 +0500 Subject: [PATCH] Stripe api version changed --- .../app/api/checkout-sessions/route.ts | 2 +- .../app/api/coupon-details/route.ts | 2 +- .../app/api/create-checkout-session/route.ts | 2 +- .../app/api/debug/sync-subscription/route.ts | 6 ++-- .../app/api/payment-details/route.ts | 2 +- .../app/api/trial/cancel/route.ts | 10 +++---- .../app/api/trial/start/route.ts | 4 +-- .../app/api/update-credits/route.ts | 2 +- .../app/api/user/cancel-subscription/route.ts | 2 +- .../app/api/webhooks/route.ts | 10 +++---- auto-analyst-frontend/package-lock.json | 28 +++++++++++++++---- auto-analyst-frontend/package.json | 3 +- 12 files changed, 46 insertions(+), 27 deletions(-) diff --git a/auto-analyst-frontend/app/api/checkout-sessions/route.ts b/auto-analyst-frontend/app/api/checkout-sessions/route.ts index 1bc9cadb..cd569969 100644 --- a/auto-analyst-frontend/app/api/checkout-sessions/route.ts +++ b/auto-analyst-frontend/app/api/checkout-sessions/route.ts @@ -7,7 +7,7 @@ export const dynamic = 'force-dynamic' // Initialize Stripe only if the secret key exists const stripe = process.env.STRIPE_SECRET_KEY ? new Stripe(process.env.STRIPE_SECRET_KEY, { - apiVersion: '2025-02-24.acacia', + apiVersion: '2025-05-28.basil', }) : null diff --git a/auto-analyst-frontend/app/api/coupon-details/route.ts b/auto-analyst-frontend/app/api/coupon-details/route.ts index 730fcaf5..fbb7df73 100644 --- a/auto-analyst-frontend/app/api/coupon-details/route.ts +++ b/auto-analyst-frontend/app/api/coupon-details/route.ts @@ -5,7 +5,7 @@ export const dynamic = 'force-dynamic' const stripe = process.env.STRIPE_SECRET_KEY ? new Stripe(process.env.STRIPE_SECRET_KEY, { - apiVersion: '2025-02-24.acacia', + apiVersion: '2025-05-28.basil', }) : null diff --git a/auto-analyst-frontend/app/api/create-checkout-session/route.ts b/auto-analyst-frontend/app/api/create-checkout-session/route.ts index 32d10560..e3221cc1 100644 --- a/auto-analyst-frontend/app/api/create-checkout-session/route.ts +++ b/auto-analyst-frontend/app/api/create-checkout-session/route.ts @@ -7,7 +7,7 @@ export const dynamic = 'force-dynamic' // Initialize Stripe only if the secret key exists const stripe = process.env.STRIPE_SECRET_KEY ? new Stripe(process.env.STRIPE_SECRET_KEY, { - apiVersion: '2025-02-24.acacia', + apiVersion: '2025-05-28.basil', }) : null diff --git a/auto-analyst-frontend/app/api/debug/sync-subscription/route.ts b/auto-analyst-frontend/app/api/debug/sync-subscription/route.ts index aeb7d51b..e0f94a80 100644 --- a/auto-analyst-frontend/app/api/debug/sync-subscription/route.ts +++ b/auto-analyst-frontend/app/api/debug/sync-subscription/route.ts @@ -8,7 +8,7 @@ export const dynamic = 'force-dynamic' // Initialize Stripe const stripe = process.env.STRIPE_SECRET_KEY ? new Stripe(process.env.STRIPE_SECRET_KEY, { - apiVersion: '2025-02-24.acacia', + apiVersion: '2025-05-28.basil', }) : null @@ -58,8 +58,8 @@ export async function POST(request: NextRequest) { // Handle cancel_at_period_end flag if (subscription.cancel_at_period_end) { updateData.cancel_at_period_end = 'true' - updateData.willCancelAt = subscription.current_period_end - ? new Date(subscription.current_period_end * 1000).toISOString() + updateData.willCancelAt = subscription.items?.data[0]?.current_period_end + ? new Date(subscription.items.data[0].current_period_end * 1000).toISOString() : new Date().toISOString() // Override status display for UI purposes diff --git a/auto-analyst-frontend/app/api/payment-details/route.ts b/auto-analyst-frontend/app/api/payment-details/route.ts index 43109067..824f3dc5 100644 --- a/auto-analyst-frontend/app/api/payment-details/route.ts +++ b/auto-analyst-frontend/app/api/payment-details/route.ts @@ -6,7 +6,7 @@ export const dynamic = 'force-dynamic' // Initialize Stripe only if the secret key exists const stripe = process.env.STRIPE_SECRET_KEY ? new Stripe(process.env.STRIPE_SECRET_KEY, { - apiVersion: '2025-02-24.acacia', + apiVersion: '2025-05-28.basil', }) : null diff --git a/auto-analyst-frontend/app/api/trial/cancel/route.ts b/auto-analyst-frontend/app/api/trial/cancel/route.ts index 23150540..a6389187 100644 --- a/auto-analyst-frontend/app/api/trial/cancel/route.ts +++ b/auto-analyst-frontend/app/api/trial/cancel/route.ts @@ -8,7 +8,7 @@ export const dynamic = 'force-dynamic' // Initialize Stripe const stripe = process.env.STRIPE_SECRET_KEY ? new Stripe(process.env.STRIPE_SECRET_KEY, { - apiVersion: '2025-02-24.acacia', + apiVersion: '2025-05-28.basil', }) : null @@ -126,8 +126,8 @@ export async function POST(request: NextRequest) { canceledAt: now.toISOString(), lastUpdated: now.toISOString(), subscriptionCanceled: 'true', - willCancelAt: stripeSubscription?.current_period_end - ? new Date(stripeSubscription.current_period_end * 1000).toISOString() + willCancelAt: stripeSubscription?.items?.data[0]?.current_period_end + ? new Date(stripeSubscription.items.data[0].current_period_end * 1000).toISOString() : now.toISOString() }) @@ -151,8 +151,8 @@ export async function POST(request: NextRequest) { remaining: Math.max(0, parseInt(subscriptionData.total as string || '0') - parseInt(subscriptionData.used as string || '0')) }, stripeStatus: stripeSubscription?.status || (isLegacyUser ? 'legacy' : 'unknown'), - willCancelAt: !(isTrial || isLegacyActive) && stripeSubscription?.current_period_end - ? new Date(stripeSubscription.current_period_end * 1000).toISOString() + willCancelAt: !(isTrial || isLegacyActive) && stripeSubscription?.items?.data[0]?.current_period_end + ? new Date(stripeSubscription.items.data[0].current_period_end * 1000).toISOString() : undefined }) diff --git a/auto-analyst-frontend/app/api/trial/start/route.ts b/auto-analyst-frontend/app/api/trial/start/route.ts index 9d7801c8..c6717fc0 100644 --- a/auto-analyst-frontend/app/api/trial/start/route.ts +++ b/auto-analyst-frontend/app/api/trial/start/route.ts @@ -9,7 +9,7 @@ export const dynamic = 'force-dynamic' // Initialize Stripe const stripe = process.env.STRIPE_SECRET_KEY ? new Stripe(process.env.STRIPE_SECRET_KEY, { - apiVersion: '2025-02-24.acacia', + apiVersion: '2025-05-28.basil', }) : null @@ -114,7 +114,7 @@ export async function POST(request: NextRequest) { // Apply discount if coupon is valid if (couponId) { - subscriptionParams.coupon = couponId + subscriptionParams.discounts = [{ coupon: couponId }] } // Create subscription with trial diff --git a/auto-analyst-frontend/app/api/update-credits/route.ts b/auto-analyst-frontend/app/api/update-credits/route.ts index b8eddc08..bc3722b4 100644 --- a/auto-analyst-frontend/app/api/update-credits/route.ts +++ b/auto-analyst-frontend/app/api/update-credits/route.ts @@ -9,7 +9,7 @@ export const dynamic = 'force-dynamic' // Initialize Stripe only if the secret key exists const stripe = process.env.STRIPE_SECRET_KEY ? new Stripe(process.env.STRIPE_SECRET_KEY, { - apiVersion: '2025-02-24.acacia', + apiVersion: '2025-05-28.basil', }) : null diff --git a/auto-analyst-frontend/app/api/user/cancel-subscription/route.ts b/auto-analyst-frontend/app/api/user/cancel-subscription/route.ts index 66ae3737..213daba3 100644 --- a/auto-analyst-frontend/app/api/user/cancel-subscription/route.ts +++ b/auto-analyst-frontend/app/api/user/cancel-subscription/route.ts @@ -7,7 +7,7 @@ import { CreditConfig } from '@/lib/credits-config' // Initialize Stripe const stripe = process.env.STRIPE_SECRET_KEY ? new Stripe(process.env.STRIPE_SECRET_KEY, { - apiVersion: '2025-02-24.acacia', + apiVersion: '2025-05-28.basil', }) : null diff --git a/auto-analyst-frontend/app/api/webhooks/route.ts b/auto-analyst-frontend/app/api/webhooks/route.ts index 0360f306..9f245789 100644 --- a/auto-analyst-frontend/app/api/webhooks/route.ts +++ b/auto-analyst-frontend/app/api/webhooks/route.ts @@ -13,7 +13,7 @@ export const dynamic = 'force-dynamic' // Initialize Stripe only if the secret key exists const stripe = process.env.STRIPE_SECRET_KEY ? new Stripe(process.env.STRIPE_SECRET_KEY, { - apiVersion: '2025-02-24.acacia', + apiVersion: '2025-05-28.basil', }) : null @@ -225,8 +225,8 @@ export async function POST(request: NextRequest) { const invoice = event.data.object as Stripe.Invoice // Check if this is for a subscription payment - if (invoice.subscription) { - const subscription = await stripe.subscriptions.retrieve(invoice.subscription as string) + if ((invoice as any).subscription_id) { + const subscription = await stripe.subscriptions.retrieve((invoice as any).subscription_id as string) // Get customer and user info const customerId = subscription.customer as string @@ -284,8 +284,8 @@ export async function POST(request: NextRequest) { const invoice = event.data.object as Stripe.Invoice // Handle failed payment after trial - if (invoice.subscription && invoice.billing_reason === 'subscription_cycle') { - const subscription = await stripe.subscriptions.retrieve(invoice.subscription as string) + if ((invoice as any).subscription_id && invoice.billing_reason === 'subscription_cycle') { + const subscription = await stripe.subscriptions.retrieve((invoice as any).subscription_id as string) // Get customer and user info const customerId = subscription.customer as string diff --git a/auto-analyst-frontend/package-lock.json b/auto-analyst-frontend/package-lock.json index 4e832bbb..87a4a407 100644 --- a/auto-analyst-frontend/package-lock.json +++ b/auto-analyst-frontend/package-lock.json @@ -42,6 +42,7 @@ "@types/nodemailer": "^6.4.17", "@types/react-plotly.js": "^2.6.3", "@types/react-syntax-highlighter": "^15.5.13", + "@types/stripe": "^8.0.417", "@upstash/redis": "^1.34.5", "axios": "^1.7.9", "class-variance-authority": "^0.7.1", @@ -73,7 +74,7 @@ "rehype-raw": "^7.0.0", "remark-gfm": "^4.0.0", "shadcn-ui": "^0.9.5", - "stripe": "^17.7.0", + "stripe": "^18.2.1", "tailwind-merge": "^2.6.0", "tailwindcss-animate": "^1.0.7", "uuid": "^11.1.0", @@ -5207,6 +5208,16 @@ "@types/node": "*" } }, + "node_modules/@types/stripe": { + "version": "8.0.417", + "resolved": "https://registry.npmjs.org/@types/stripe/-/stripe-8.0.417.tgz", + "integrity": "sha512-PTuqskh9YKNENnOHGVJBm4sM0zE8B1jZw1JIskuGAPkMB+OH236QeN8scclhYGPA4nG6zTtPXgwpXdp+HPDTVw==", + "deprecated": "This is a stub types definition. stripe provides its own type definitions, so you do not need this installed.", + "license": "MIT", + "dependencies": { + "stripe": "*" + } + }, "node_modules/@types/stylus": { "version": "0.48.43", "resolved": "https://registry.npmjs.org/@types/stylus/-/stylus-0.48.43.tgz", @@ -16259,16 +16270,23 @@ } }, "node_modules/stripe": { - "version": "17.7.0", - "resolved": "https://registry.npmjs.org/stripe/-/stripe-17.7.0.tgz", - "integrity": "sha512-aT2BU9KkizY9SATf14WhhYVv2uOapBWX0OFWF4xvcj1mPaNotlSc2CsxpS4DS46ZueSppmCF5BX1sNYBtwBvfw==", + "version": "18.2.1", + "resolved": "https://registry.npmjs.org/stripe/-/stripe-18.2.1.tgz", + "integrity": "sha512-GwB1B7WSwEBzW4dilgyJruUYhbGMscrwuyHsPUmSRKrGHZ5poSh2oU9XKdii5BFVJzXHn35geRvGJ6R8bYcp8w==", "license": "MIT", "dependencies": { - "@types/node": ">=8.1.0", "qs": "^6.11.0" }, "engines": { "node": ">=12.*" + }, + "peerDependencies": { + "@types/node": ">=12.x.x" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } } }, "node_modules/strongly-connected-components": { diff --git a/auto-analyst-frontend/package.json b/auto-analyst-frontend/package.json index 6866132b..c2423fff 100644 --- a/auto-analyst-frontend/package.json +++ b/auto-analyst-frontend/package.json @@ -43,6 +43,7 @@ "@types/nodemailer": "^6.4.17", "@types/react-plotly.js": "^2.6.3", "@types/react-syntax-highlighter": "^15.5.13", + "@types/stripe": "^8.0.417", "@upstash/redis": "^1.34.5", "axios": "^1.7.9", "class-variance-authority": "^0.7.1", @@ -74,7 +75,7 @@ "rehype-raw": "^7.0.0", "remark-gfm": "^4.0.0", "shadcn-ui": "^0.9.5", - "stripe": "^17.7.0", + "stripe": "^18.2.1", "tailwind-merge": "^2.6.0", "tailwindcss-animate": "^1.0.7", "uuid": "^11.1.0",