Issue with stripe webhook in production

I was trying to test subscriptions in production (worked in local). When i did purchase transaction was successful but it didnt change subscription details in the database ( default ones i didnt touch them). Probably there is some issue related with webhooks but i double checked my stripe keys.
No description
44 Replies
kapa.ai
kapa.ai6mo ago
Hi @Atasoy. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information from the knowledge sources, it seems like you might be facing an issue similar to what Community Member 43 experienced. They found that the Stripe CLI, which is referenced in the Open-Saas Docs, is related to local development. Once you deploy to a production environment like Fly.io, you need to change the webhook secret in the Stripe -> Dev -> Webhooks section. Here are the steps they followed to resolve the issue: 1. Create a new webhook by URL pointing to your server url/stripe-webhook endpoint in the Stripe dashboard. 2. Add the Webhook Secret found on the stripe dashboard to your .env settings. This change is necessary because the webhook URL and secret used in the local development environment will not work in the production environment. If you're still facing issues, it might be helpful to check the API version you're using with Stripe. In one of the threads, a user faced issues due to using a newer API version (2023-10-16) instead of the one used in the template. You can find more details in the source thread (https://discord.com/channels/686873244791210014/1220115828012351529). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Atasoy, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Atasoy
AtasoyOP6mo ago
here is my stripe webhooks dashboard
No description
Atasoy
AtasoyOP6mo ago
@kapa.ai i did some research it might be about my webhook api version. It dosent match with documentation and code. What do you think
kapa.ai
kapa.ai6mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Yes, you're correct. The API version mismatch could indeed be causing the issue. In one of the Discord threads, a user faced a similar problem due to using a newer API version (2023-10-16) instead of the one used in the template. It's important to ensure that the API version you're using with Stripe matches the one used in the Wasp template. If they don't match, it could lead to unexpected behavior or errors. You can check the API version in your Stripe Dashboard and compare it with the one used in the Wasp template. If they don't match, you might need to adjust your code or change the API version in your Stripe Dashboard to match the one used in the Wasp template. You can find more details in the source thread (https://discord.com/channels/686873244791210014/1215945587841831033). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Atasoy, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Atasoy
AtasoyOP6mo ago
@kapa.ai updating my api version didnt help
MEE6
MEE66mo ago
Wohooo @Atasoy, you just became a Waspeteer level 1!
kapa.ai
kapa.ai6mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- I'm sorry to hear that updating your API version didn't resolve the issue. Based on the provided knowledge sources, there isn't enough information to diagnose the exact problem you're facing with the Stripe webhook in production. However, here are a few general troubleshooting steps you can take: 1. Double-check your webhook setup in Stripe Dashboard. Make sure the endpoint URL is correct and the events you want to listen to are selected. 2. Check the logs in your Stripe Dashboard for any failed webhook events. This can give you clues about what's going wrong. 3. Make sure your server is correctly processing the webhook events. You can add logging to your webhook handling code to confirm this. 4. Ensure that your server is publicly accessible and that Stripe can reach your webhook URL. If your server is behind a firewall or in a private network, Stripe won't be able to send webhook events to it. If you're still having trouble, I recommend reaching out to the Wasp community or Stripe support for more specific assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Atasoy, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Vinny (@Wasp)
Vinny (@Wasp)6mo ago
It looks like your webhook signing is failing. First of all, make sure the webhook api versions match. If the webhook works in development it will work in production as long as the configuration is correct, e.g. make sure you’ve entered the correct server url and env variables, such as signing secret, product ids, etc
Atasoy
AtasoyOP6mo ago
Yes you are right for some reason webhook in development is also not working. I am gettin same error. My api version on stripe dashboard is 2024-04-10. I couldnt find a way to downgrade it to 2022-11-15 as used in stripe.ts.
Vinny (@Wasp)
Vinny (@Wasp)6mo ago
const stripe = new Stripe(process.env.STRIPE_KEY!, {
apiVersion: '2022-11-15',
});
const stripe = new Stripe(process.env.STRIPE_KEY!, {
apiVersion: '2022-11-15',
});
on lines 4-5 in app/src/server/payments/stripeUtils.ts
martinsos
martinsos6mo ago
We did have people successfully use it just a day or so ago however, so it sounds to me based on that like webhook versino shouldn't be an issue (although I am not sure). Hm those error messages do sound like there is a mismatch between the versions, one format is expected and another is recieved
Atasoy
AtasoyOP6mo ago
I made sure my secrets are correct so i also think it might be webhook api version problem.
Vinny (@Wasp)
Vinny (@Wasp)6mo ago
from Stripe docs:
When you send requests to Stripe, you may specify an API version with the Stripe-Version header. If you don’t specify an API version, Stripe uses your account’s default API version..
so by setting the version in the Stripe config (above) you're telling it use that version when the webhook events are sent and it will ignore whatever default you have in the dashboard
martinsos
martinsos6mo ago
@Vinny (@Wasp) but we don't in docs tell people to explicitly choose a version, right? Meaning it works with defaults. So if it works for others, why would it now not work for @Atasoy ? @Vinny (@Wasp) aha you are saying that we are, in OpenSaas code, with those lines above, explicitly stating which version to use, so version should not be a problem?
Vinny (@Wasp)
Vinny (@Wasp)6mo ago
yep exactly
martinsos
martinsos6mo ago
@Atasoy you first said it worked locally but not in production, then you said it doesn't work both locally and in production. How is that? Probably because you were changing the version? In that case, let's first get back to the state where it was working at least locally (so probably revert the changes you did to that version). Then from there we can figure out why it works locally but not in production.
Vinny (@Wasp)
Vinny (@Wasp)6mo ago
for example, OpenSaaS.sh is using this webhook with a different default API version in the dashboard, but because it's set in the config of the STRIPE SDK as apiVersion: '2022-11-15', it sends all events according to that version
No description
Atasoy
AtasoyOP6mo ago
My default api version was 2020-08-27. Then i upgrade to 2024-04-10. I just tried downgrading back and followed steps in https://docs.opensaas.sh/guides/stripe-integration/ just to make sure but still i am getting same error.
OpenSaaS.sh
Stripe Integration
Open SaaS is a free, open-source, full-stack SaaS starter kit for React + NodeJS.
Atasoy
AtasoyOP6mo ago
I will try integrating webhooks in fresh open saas template to understand problem clearly. On fresh open saas template everything is working fine (with the same .env file) UPDATE: so i thought that it may be about module conflicts but it is not i check with my node modules. Problem is either with .wasp file or my sever and client codes
martinsos
martinsos6mo ago
Hm it is good to know that it works when you go from scratch! I wonder what caused the issue in your code then. If you figure it out let us know. Btw, you can also try doing wasp clean, this will clear out any cached stuff (node modules, generated code, ...).
Atasoy
AtasoyOP5mo ago
Hey, so i really narrowed down the error and found very wierd stuff. When i dont use crud functionalities webhook is working but when i uncomment them it is breaking. What is you opinion on this ?
Vinny (@Wasp)
Vinny (@Wasp)5mo ago
what do you mean? can you share the code?
Atasoy
AtasoyOP5mo ago
Webhook error
No description
Atasoy
AtasoyOP5mo ago
No webhook error
No description
Atasoy
AtasoyOP5mo ago
You can produce same error by opening fresh saas template. Setting up and doing stripe integration. Creating a crud for any entity. Then move crud file (here tasks.js to server/crud). From that point it starts giving this error.
MEE6
MEE65mo ago
Wohooo @Atasoy, you just became a Waspeteer level 2!
Vinny (@Wasp)
Vinny (@Wasp)5mo ago
Are you defining crud Tasks when there is a Task entity already? Also, we haven’t tested CRUD with Webhooks before. It would probably be best to implement each operation manually if this is causing your error. cc: @miho
Atasoy
AtasoyOP5mo ago
Yes there is Task entity. For now it seems that CRUD is causing Webhook issues. I guess implementing them in my own is the only solution for now
Vinny (@Wasp)
Vinny (@Wasp)5mo ago
Are there other operations that depend on the task entity that you’re running side by side with the Task CRUD? But yeah, I’d implement them manually for now.
Atasoy
AtasoyOP5mo ago
That scenario was just to explain to you. In my original website CRUDs are Student and Club entity and yes there is other operations depends on CRUD functionality in front-end.
martinsos
martinsos5mo ago
Thanks @Atasoy for nailing this down! CRUD is a bit experimental still, so maybe this is problem indeed. @miho is authority both for Auth and for CRUD so let's see what he says on this.
miho
miho5mo ago
If I understood correctly, you used the CRUD feature to receive webhooks? If so, did you use the POST method or the GET method for the webhook?
Atasoy
AtasoyOP5mo ago
No, basically when i use CRUD feature for any of my entities it breaks the Stripe Webhook
miho
miho5mo ago
So, you made a custom api for the webhook and it breaks when you add a crud declaration for some entity? That's how I'm reading this 😄 Just to be sure to understand 🙂
Atasoy
AtasoyOP5mo ago
I am using SAAS template. When i declare CRUD for some entity it breaks the stripe WEBHOOK. I did not make custom API for the WEBHOOK.
miho
miho5mo ago
Okay, so, you are just using Open SaaS as-is and then when you add a crud declaration, things stop working? @Vinny (@Wasp) could test this theory out?
Vinny (@Wasp)
Vinny (@Wasp)5mo ago
yeah let me give it a go right now ok interesting. If I have the crud Tests defined at the end of the file (after the job calculatedDailyStates definition), the webhook endpoint returns 400. If I have it defined in the middle of the file (before the job), it gives the signing secret error:
[ Server ] Webhook payload must be provided as a string or a Buffer (https://nodejs.org/api/buffer.html) instance representing the _raw_ request body.Payload was provided as a parsed JavaScript object instead.
[ Server ] Signature verification is impossible without access to the original signed material.
[ Server ] Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing
[ Server ] Webhook payload must be provided as a string or a Buffer (https://nodejs.org/api/buffer.html) instance representing the _raw_ request body.Payload was provided as a parsed JavaScript object instead.
[ Server ] Signature verification is impossible without access to the original signed material.
[ Server ] Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing
so definitely something is affecting the endpoint / middleware somehow
miho
miho5mo ago
@Vinny (@Wasp) could you explain to me how to cause these errors in more detail? I'm doing this:
curl -X POST http://localhost:3001/stripe-webhook -d 'Hello there, 10' -H 'stripe-signature: XXX'
Webhook Error: Unable to extract timestamp and signatures from header%
curl -X POST http://localhost:3001/stripe-webhook -d 'Hello there, 10' -H 'stripe-signature: XXX'
Webhook Error: Unable to extract timestamp and signatures from header%
But the error seems fine since the stripe-signature is wrong? I get the message you mentioned even without the crud declaration? OK, I was missing the signing secret Ok I found it 👍 The way we define CRUD router and the apis router is conflicting.
router.use('/', middleware, rootCrudRouter)
router.use(apis)
router.use('/', middleware, rootCrudRouter)
router.use(apis)
The router.use('/', middleware, ...) code sets the middleware for all the routes under / which is all routes 😄 We have a bug with CRUD it seems and it cannot be used with apis, but the fix could be easy and I'll create an issue for this to be handled for the next release 👍 @Atasoy sorry about this
miho
miho5mo ago
GitHub
Enabling CRUD feature sets the default middleware globally (breakin...
The way we define CRUD router and the apis router is conflicting. router.use('/', middleware, rootCrudRouter) router.use(apis) The router.use('/', middleware, ...) code sets the mid...
Atasoy
AtasoyOP5mo ago
I am happy you help you guys.
martinsos
martinsos5mo ago
Awesome, thank you!
Atasoy
AtasoyOP4mo ago
Hello! Is this fixed? How i can migrate changes to my existing project? My saas is basically done but i have to fix this last.
MEE6
MEE64mo ago
Wohooo @Atasoy, you just became a Waspeteer level 3!
miho
miho4mo ago
Hey, we fixed this in 0.14.0, yep 🙂
Want results from more Discord servers?
Add your server