Skip to content

Commit

Permalink
fix: make sure internal request can go through
Browse files Browse the repository at this point in the history
  • Loading branch information
jbranchaud authored and kodiakhq[bot] committed Mar 7, 2024
1 parent 15bcfa0 commit 819f88a
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions packages/skill-api/src/core/services/process-stripe-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ export async function receiveInternalStripeWebhooks({
const {
req,
options: {nextAuthOptions},
rawReq,
} = params
if (!rawReq) {
return {
status: 500,
body: `no raw request found for stripe verification, check bodyParser config!`,
}
}

const skillSecret = req.headers['x-skill-secret'] as string

Expand All @@ -63,7 +56,7 @@ export async function receiveInternalStripeWebhooks({
}
const stripe = paymentOptions?.stripeCtx.stripe || defaultStripe

const event: any = req.body
const event: any = req.body.event

return await processStripeWebhook(event, {
nextAuthOptions,
Expand Down Expand Up @@ -150,14 +143,15 @@ export async function receiveStripeWebhooks({
.parse(process.env.TJS_SKILL_SECRET)

const headers = new Headers({
'Content-Type': 'application/json',
'x-skill-secret': skillSecret,
})

// not awaiting the fetch so that endpoint can return 200 right away
fetch(internalStripeWebhookEndpoint, {
await fetch(internalStripeWebhookEndpoint, {
method: 'POST',
headers,
body: JSON.stringify(event),
body: JSON.stringify({event}),
})

return {status: 200, body: `handled by ${targetSiteName}`}
Expand Down

0 comments on commit 819f88a

Please sign in to comment.