#rezamirzad

1 messages · Page 1 of 1 (latest)

lean hornetBOT
eternal tangle
#

👋 happy to help

#

what are you using as an API framework?

civic axle
#

my code uses the Koa web framework with Koa-Joi-Router to create a REST API endpoint

eternal tangle
#

you need to get the raw body

#

and use the correct STRIPE_ENDPOINT_SECRET generated by the stripe-cli

civic axle
#

how do i find the correct STRIPE_ENDPOINT_SECRET generated by the stripe-cli?

i am giving it the endpoint secret given to me on the webhook dashboard

#

nevermind, i found the secert endpoint of the cli

#

but i still do not know how to get the raw body and which part to pass as which parameter?

eternal tangle
#

how do i find the correct STRIPE_ENDPOINT_SECRET generated by the stripe-cli?
when you run stripe listen --forward-to .... command you will get in your terminal a whsec_xxxx token which is the one you should use

civic axle
#

this part i got

eternal tangle
#

instead of ctxRequestBody

#

you should use ctx.request.rawBody

civic axle
#

ok,
so...

await bodyParser()(ctx, async () => {});
console.log(ctx.request.rawBody);

is still undefined

eternal tangle
#

await bodyParser()(ctx, async () => {});
where did you execute that?

civic axle
#

in the webhook

async webhookPost(ctx: Context): Promise<void> { await bodyParser()(ctx, async () => {}); console.log(ctx.request.rawBody); const sig = ctx.request.header['stripe-signature']; const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY); const endpointSecret = process.env.STRIPE_ENDPOINT_SECRET; let event; event = stripe.webhooks.constructEvent(ctx.request.rawBody, sig, endpointSecret); console.log(event); }

#

import bodyParser from 'koa-bodyparser';

eternal tangle
#

were you using koa-bodyparser in the first place to parse your API requests as JSON?

civic axle
#

not that i am aware of
i just installed the koa-bodyparser

if it can help, i already have
rawHeaders: [ 'Host', 'localhost:8888', 'User-Agent', 'Stripe/1.0 (+https://stripe.com/docs/webhooks)', 'Content-Length', '2195', 'Accept', '*/*; q=0.5, application/xml', 'Cache-Control', 'no-cache', 'Content-Type', 'application/json; charset=utf-8', 'Stripe-Signature', 't=1676457659,v1=a7f71fbc433d24428765ba1e3fc8fcb744aabceef6f97961453f5ddf24db3e3a,v0=75ec2924982b0415bc1e6fd0453e5990a62f42090dee1044c7cbd837611dec52', 'Accept-Encoding', 'gzip' ],

in the ctx.req, even before passing it through the bodyparser

eternal tangle
#

you don't need to pass it through the bodyparser

#

you just need to access the raw unparsed body

civic axle
#

ok, so

event = stripe.webhooks.constructEvent(ctx.req.body, sig, endpointSecret);
?

cause it still fives me the same error:

Error: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?

eternal tangle
#

I'm not really familiar with koa.js and how it works to be honest

#

you need to find a way to get the rawbody without being parsed