Karim Ahmed
Karim Ahmed
Explore posts from servers
CDCloudflare Developers
Created by Karim Ahmed on 7/11/2024 in #workers-help
Issue Integrating Stripe with Cloudflare Workers: Script will never generate a response
I’m encountering an issue while integrating Stripe into my Workers project. Everything works perfectly in my local environment, where I can create Stripe checkout sessions and access the billing portal through an API endpoint that returns the URL for Stripe checkout. However, upon deployment to Cloudflare, sometimes I receive an internal server error with the message that the script never generates a response and sometimes it just works. I’ve tried using both the Stripe SDK for Node.js and direct API calls, but both approaches result in the same error. Here are the code snippets I’ve used: Direct API Call:
const response = await fetch('https://api.stripe.com/v1/billing_portal/sessions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.STRIPE_SECRET_KEY}`,
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
customer: stripeId,
return_url: returnUrl
})
});
const response = await fetch('https://api.stripe.com/v1/billing_portal/sessions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.STRIPE_SECRET_KEY}`,
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
customer: stripeId,
return_url: returnUrl
})
});
Stripe SDK
await stripe.billingPortal.sessions.create({
customer: stripeId,
return_url: fullUrl,
});
await stripe.billingPortal.sessions.create({
customer: stripeId,
return_url: fullUrl,
});
The same issue occurs when creating a checkout session. Has anyone faced a similar issue or have any ideas on how to resolve this? Any help would be greatly appreciated!
4 replies