#mh_webhooks

1 messages ยท Page 1 of 1 (latest)

ashen fogBOT
#

๐Ÿ‘‹ 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.

wraith mauve
#

๐Ÿ‘‹ happy to help

languid heron
#

can we open zoom together?

wraith mauve
#

500 internal server errors means that your code is failing at processing the event that was received

languid heron
#

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?

wraith mauve
#

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

languid heron
#

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

wraith mauve
languid heron
#

so the bug in the fulfillment part?

wraith mauve
#

it seems so

languid heron
#

i dont have a fulfillment part. only the session create and the webhook underit

wraith mauve
#

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

languid heron
#

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

wraith mauve
#

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?

languid heron
#

axios
.post(${url}/stripe/create-checkout-session, {
cartItems,
userId: user._id,
})

wraith mauve
#

it seems in your frontend user._id is empty

languid heron
#

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.

wraith mauve
#

I can't help you debug your code unfortunately

languid heron
#

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

GitHub

Node.js library for the Stripe API. . Contribute to stripe/stripe-node development by creating an account on GitHub.

#

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?

wraith mauve
#

you need to pass this app.post('/webhook', express.raw({type: 'application/json'}), (request, response) => {

languid heron
#

its already like this .

wraith mauve
#

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())

languid heron
#

so i should put the sebhook in another route, and above the app.use(express.json()); .right?

wraith mauve
#

yes

#

and you can simply create a new app and use it only for webhooks

languid heron
#

i will try it now. hopefully will work'

wraith mauve
#

that would be even better

languid heron
#

great idea. i will try it now.

ashen fogBOT
languid heron
#

hey tarzan

#

it worked great

#

thanks for your help . have a great day further ๐Ÿ‘