Skip to content

Commit 677596c

Browse files
authored
templates: fix ecommerce webhooks url and update docs on using stripe webhooks (#15681)
Updates docs on how to use Stripe's CLI and Webhooks and fixes the URL to the right one in package.json. Also bumps the timeout to the new limit of 300 for seed script - will fix some marginal errors.
1 parent e26df27 commit 677596c

3 files changed

Lines changed: 46 additions & 6 deletions

File tree

docs/ecommerce/payments.mdx

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,49 @@ export default buildConfig({
114114
})
115115
```
116116

117-
To use webhooks you also need to have them configured in your Stripe Dashboard.
117+
To use webhooks you also need to have them configured in your Stripe Dashboard or use the Stripe CLI for local development.
118118

119-
You can use the [Stripe CLI](https://stripe.com/docs/stripe-cli) to forward webhooks to your local development environment.
119+
#### Local Development with Stripe CLI
120+
121+
You can use the [Stripe CLI](https://stripe.com/docs/stripe-cli) to forward webhooks to your local development environment:
122+
123+
1. **Install and authenticate the Stripe CLI:**
124+
125+
```bash
126+
stripe login
127+
```
128+
129+
2. **Start listening for webhooks** (note the correct endpoint path):
130+
131+
```bash
132+
stripe listen --forward-to localhost:3000/api/payments/stripe/webhooks
133+
```
134+
135+
3. **Copy the webhook signing secret** that is displayed when you start listening. It will look like:
136+
137+
```
138+
Ready! Your webhook signing secret is whsec_abc123xyz...
139+
```
140+
141+
4. **Add the secret to your `.env` file** - copy the secret exactly as shown (do not add an extra `whsec_` prefix):
142+
143+
```bash
144+
STRIPE_WEBHOOKS_SIGNING_SECRET=whsec_abc123xyz...
145+
```
146+
147+
5. **Restart your Next.js dev server** to pick up the new environment variable.
148+
149+
6. **Trigger a test webhook** to verify your setup:
150+
151+
```bash
152+
stripe trigger payment_intent.succeeded
153+
```
154+
155+
<Banner type="warning">
156+
The webhook signing secret from `stripe listen` is ephemeral and can change
157+
each time you restart the CLI. Make sure to update your `.env` file and
158+
restart your dev server when you restart `stripe listen`.
159+
</Banner>
120160

121161
### Frontend usage
122162

@@ -405,8 +445,8 @@ The client side adapter should implement the `PaymentAdapterClient` interface:
405445
406446
And for the args use the `PaymentAdapterClientArgs` type:
407447
408-
| Property | Type | Description |
409-
| -------- | -------- | ----------------------------------------------------------------- |
448+
| Property | Type | Description |
449+
| -------- | -------- | ------------------------------------------------------------------ |
410450
| `label` | `string` | (Optional) Allow overriding the default UI label for this adapter. |
411451
412452
## Best Practices

templates/ecommerce/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"payload": "cross-env NODE_OPTIONS=--no-deprecation payload",
1717
"reinstall": "cross-env NODE_OPTIONS=--no-deprecation rm -rf node_modules && rm pnpm-lock.yaml && pnpm --ignore-workspace install",
1818
"start": "cross-env NODE_OPTIONS=--no-deprecation next start",
19-
"stripe-webhooks": "stripe listen --forward-to localhost:3000/api/stripe/webhooks",
19+
"stripe-webhooks": "stripe listen --forward-to localhost:3000/api/payments/stripe/webhooks",
2020
"test": "pnpm run test:int && pnpm run test:e2e",
2121
"test:e2e": "cross-env NODE_OPTIONS=\"--no-deprecation --import=tsx/esm\" playwright test --config=playwright.config.ts",
2222
"test:int": "cross-env NODE_OPTIONS=--no-deprecation vitest run --config ./vitest.config.mts"

templates/ecommerce/src/app/(app)/next/seed/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { seed } from '@/endpoints/seed'
33
import config from '@payload-config'
44
import { headers } from 'next/headers'
55

6-
export const maxDuration = 60 // This function can run for a maximum of 60 seconds
6+
export const maxDuration = 300 // This function can run for a maximum of 300 seconds
77

88
export async function POST(): Promise<Response> {
99
const payload = await getPayload({ config })

0 commit comments

Comments
 (0)