-
Notifications
You must be signed in to change notification settings - Fork 858
Closed
Labels
Description
Describe the bug
I'm running a nextJS app project on Cloudflare workers. Using the latest Stripe node sdk version 20.
On the production server when I try to create a checkout session from my api route, I see this error.
An error occurred with our connection to Stripe. Request was retried 2 times.
On localhost the exact same code is working perfectly fine.
I double checked my env vars to make sure they're properly passed and correct in production, yet i'm still getting the error.
For now what I did is omit the SDK and just use a raw fetch request and it works in production.
To Reproduce
npm create cloudflare@latest -- my-next-app --framework=nexthttps://developers.cloudflare.com/workers/framework-guides/web-apps/nextjs/npm i stripe --save- Create an api route like "/api/stripe-checkout" that uses the sdk like this
const session = await stripe.checkout.sessions.create({ ... })This will cause the error - Deploy to Cloudflare workers
- Call the endpoint
Expected behavior
The Stripe Checkout page should open the same way it does when I'm doing it from localhost.
Code snippets
import { createClient } from '@/lib/supabase/server';
import { NextResponse } from 'next/server';
import { Stripe } from 'stripe';
export async function POST(request) {
try {
const supabase = await createClient();
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
const {
data: { user },
error: getUserError,
} = await supabase.auth.getUser();
if (getUserError) throw getUserError;
const session = await stripe.checkout.sessions.create({
client_reference_id: user.id,
customer_email: user.email,
metadata: {
plan_id: "pro",
email: user.email,
},
line_items: [
{
price: "xxxxxxxxxx", //replace with your price id
quantity: 1,
},
],
mode: 'subscription',
success_url: `${process.env.NEXT_PUBLIC_HOST_URL}/premium`,
cancel_url: `${process.env.NEXT_PUBLIC_HOST_URL}/premium`,
});
return NextResponse.json(
{ url: session.url },
{ status: 200 }
);
} catch (e) {
console.log('Some errr', e);
return NextResponse.json(
{ message: e.message },
{
status: 500,
}
);
}
}OS
macos
Node version
21
Library version
20.0.0
API version
2025-11-17.clover
Additional context
No response