#mh_webhooks
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1285162374906511451
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
๐ happy to help
can we open zoom together?
500 internal server errors means that your code is failing at processing the event that was received
the paymnt is completed .put the cemplete event is catching this error .what can i do
s cart: JSON.stringify(req.body.cartItems),
^^^^
SyntaxError: Unexpected identifier 'cart'. and also the user._id from the front end seems to be not reaching the backend.right?
yes because this request isn't sent by your frontend
this is a request that is sent by Stripe
that doesn't contain your context
so what should i do .
i will send you the code
just a minute
these are the index and the stripe file .which has all the needed backend code .
and this is the front end code
i have been seaching for the bug for days
@languid heron please read this https://docs.stripe.com/checkout/fulfillment
so the bug in the fulfillment part?
it seems so
i dont have a fulfillment part. only the session create and the webhook underit
what I suggest is logging the error message as the body response to your webhook endpoint code, and then when you receive an event you can check the error message on your stripe dashboard
the fulfillment = webhooks
Checkout Session was completed! cs_test_a1mSVCDiBfWInYYoJwcUdFDZsB6Ool0OgXbAUtIhHF10A4CQxVSbDynxAo
Session metadata: {}
Error saving order to database: Order validation failed: userId: Path userId is required.
and this from the events page HTTP status code
500 (Internal Server Error)
Internal Server Error
and the starange tehat there is a userId path. iam really confused
line 130 in stripe.js.
i first tried to take it from the req.body
but i had the same error . so i moved to customer.metadata.userId; . and its the same
it seems that your customer.metadata.userId is not being set...
is the userId saved in the session? or how are you passing it from your frontend?
axios
.post(${url}/stripe/create-checkout-session, {
cartItems,
userId: user._id,
})
it seems in your frontend user._id is empty
with the request
i consoleloged it . its in the component before the request is made
i tried to change it to 12345 for debugging. but i faced the same error
pls take a look at my code an check if there is any bug.
I can't help you debug your code unfortunately
Received userId: testUserId123
Webhook signature verification failed. 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.
Signature verification is impossible without access to the original signed material.
Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing
app.use(express.json()); // Parse JSON request bodies
app.use("/api/stripe", stripeRoutes);
here is the bug. when butting app.use("/api/stripe", stripeRoutes); under app.use(express.json()); // Parse JSON request bodies .the checkout page appears.
but in this case the webhook will not work
beacuse express.raw({ type: 'application/json' }),.
so how to fix this?
you need to pass this app.post('/webhook', express.raw({type: 'application/json'}), (request, response) => {
its already like this .
but don't put it in the same router as /api/stripe
it shouldn't be part of your API
it should be a separate service
that is declared before app.use(express.json())
so i should put the sebhook in another route, and above the app.use(express.json()); .right?
i will try it now. hopefully will work'
that would be even better
great idea. i will try it now.