New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs[snippets]: add stripe webhook integration #347
Conversation
Awesome! I've left one comment. Please check it. |
Thank you @yusukebe -san! |
snippets/stripe-webhook.md
Outdated
|
||
app.post("/webhook", async (context) => { | ||
const stripe = new Stripe(context.env.STRIPE_API_KEY); | ||
- const event = await context.req.json(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use this "Colored Diffs in Code Blocks"?
https://vitepress.dev/guide/markdown#colored-diffs-in-code-blocks
snippets/stripe-webhook.md
Outdated
|
||
### Deploying to Cloudflare ( Workers / Pages ) | ||
|
||
When processing Stripe webhook events on Cloudflare Workers or Cloudflare Pages functions, the raw request body can be obtained from `context.req.text()`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both Cloudflare and Node.js can use the same code because the API for accessing the request body is the same according to Web Standard APIs. So, both can use context.req.text()
or context.req.arrayBuffer()
.
snippets/stripe-webhook.md
Outdated
const app = new Hono(); | ||
|
||
app.post("/webhook", async (context) => { | ||
const stripe = new Stripe(context.env.STRIPE_API_KEY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want it to support multi runtimes, it would be good to use env()
in hono/adapter
:
https://hono.dev/helpers/adapter
Hello @yusukebe -san, Please feel free to provide your comments about this update. |
Then, are both codes necessary? Perhaps it can be one code example? |
snippets/stripe-webhook.md
Outdated
|
||
The API that processes webhook events is publicly accessible. | ||
|
||
```javascript |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using ts
is better than javascript
or js
.
@yusukebe |
snippets/stripe-webhook.md
Outdated
const stripe = new Stripe(STRIPE_SECRET_API_KEY); | ||
const event = await context.req.json(); // [!code --] | ||
const signature = context.req.header('stripe-signature'); // [!code ++] | ||
try { // [!code ++] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove the blocks like the following!
// [!code ++]
Thanks! I've left one more comment. Check it. |
@yusukebe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks! Let's ship it. |
I added a page introducing how to create an API using Hono to handle Stripe Webhook events.
Context
https://github.com/orgs/honojs/discussions/2518#discussioncomment-9170675
To add protection processing for the API endpoint, Stripe Webhooks require the raw request body. I created an article with sample code explaining how to obtain this for both Node.js and Cloudflare.
By adding this article, users using Stripe with Hono will find it easier to understand the integration method, and it will be easier to provide support in case of issues or discussions.