#rezamirzad
1 messages · Page 1 of 1 (latest)
my code uses the Koa web framework with Koa-Joi-Router to create a REST API endpoint
you need to get the raw body
and use the correct STRIPE_ENDPOINT_SECRET generated by the stripe-cli
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?
how do i find the correct STRIPE_ENDPOINT_SECRET generated by the stripe-cli?
when you runstripe listen --forward-to ....command you will get in your terminal awhsec_xxxxtoken which is the one you should use
this part i got
instead of ctxRequestBody
you should use ctx.request.rawBody
ok,
so...
await bodyParser()(ctx, async () => {});
console.log(ctx.request.rawBody);
is still undefined
await bodyParser()(ctx, async () => {});
where did you execute that?
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';
were you using koa-bodyparser in the first place to parse your API requests as JSON?
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
you don't need to pass it through the bodyparser
you just need to access the raw unparsed body
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?