Skip to content

Conversation

@rhijjawi
Copy link

Addresses the following issue: #2100

Why?

Stripe Docs - The linked doc does not work on App Router, so I decided to fix it

What?

  • Adds file: examples/webhook-signing/nextjs/app/api/webhooks/route.ts
  • I tried to maintain the formatting of the Pages router equivalent file.

See Also

None.

@rhijjawi rhijjawi requested a review from a team as a code owner December 26, 2024 19:52
@rhijjawi rhijjawi requested review from helenye-stripe and removed request for a team December 26, 2024 19:52
@cla-assistant
Copy link

cla-assistant bot commented Dec 26, 2024

CLA assistant check
All committers have signed the CLA.

@jar-stripe jar-stripe self-assigned this Jan 14, 2025
@jar-stripe
Copy link
Contributor

jar-stripe commented Jan 14, 2025

Hi @rhijjawi , very sorry for the delay here, and thank you for contributing! We'll review and get back to you with any questions we may have.

One quick q out of the gate: can you help me understand what about the linked Stripe Docs example doesn't work on App Router?

@rhijjawi
Copy link
Author

Heyo @jar-stripe!
Thanks for taking a look at this PR.

There's not a huge difference, just a different implementation because the Pages Router example of Buffer did not work as expected.
This PR just creates a new example file as proposed by you here.

Accidentally left in a personal library reference in the code that would cause the example to fail.
throw new Error("Invalid Signature")
}
try {
const body = Uint8Array.from(await buffer(req)) as Buffer<ArrayBufferLike>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this buffer have to be Uint8Array? Why can't we have something similar to https://github.com/stripe/stripe-node/blob/master/examples/webhook-signing/nextjs/pages/api/webhooks.ts#L56-L70

@xavdid-stripe
Copy link
Member

Hey @rhijjawi, thanks for the patience here! we're doing some final checks to match some other Next.js examples we have and then I'll get this merged this week!

@jsteele-stripe
Copy link
Contributor

@rhijjawi Thank you for your contribution, we appreciate it. Closing this out as a duplicate of a newer PR that is closer to Next.js primitives – #2258

@xavdid-stripe
Copy link
Member

Echoing what Jonathan said - thank you for opening this PR and spurring us to take a closer look at our examples. We'll hopefully get that mereged. Apologies for the runaround here. 😅

If it's useful, we've also got an example in the Next.js repo itself: vercel/next.js | examples/with-stripe-typescript/.../route.ts.

Between those two, we'll hopefully have enough examples to go on.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants