Skip to content

Commit 78db50a

Browse files
authored
feat(plugin-stripe): add full req object to stripe webhook handlers (#6770)
Provides `req` to the webhook handlers in Stripe plugin and fixes type to `PayloadRequest` for req by default.
1 parent f36bf5e commit 78db50a

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

packages/plugin-stripe/src/routes/rest.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { PayloadRequestWithData } from 'payload/types'
1+
import type { PayloadRequest, PayloadRequestWithData } from 'payload/types'
22

3+
import { addDataAndFileToRequest } from '@payloadcms/next/utilities'
34
import { Forbidden } from 'payload/errors'
45

56
import type { StripePluginConfig } from '../types.js'
@@ -8,21 +9,25 @@ import { stripeProxy } from '../utilities/stripeProxy.js'
89

910
export const stripeREST = async (args: {
1011
pluginConfig: StripePluginConfig
11-
req: PayloadRequestWithData
12+
req: PayloadRequest
1213
}): Promise<any> => {
1314
let responseStatus = 200
1415
let responseJSON
1516

1617
const { pluginConfig, req } = args
1718

19+
await addDataAndFileToRequest({ request: req })
20+
21+
const requestWithData = req as PayloadRequestWithData
22+
1823
const {
1924
data: {
2025
stripeArgs, // example: ['cus_MGgt3Tuj3D66f2'] or [{ limit: 100 }, { stripeAccount: 'acct_1J9Z4pKZ4Z4Z4Z4Z' }]
2126
stripeMethod, // example: 'subscriptions.list',
2227
},
2328
payload,
2429
user,
25-
} = req
30+
} = requestWithData
2631

2732
const { stripeSecretKey } = pluginConfig
2833

packages/plugin-stripe/src/routes/webhooks.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Config as PayloadConfig } from 'payload/config'
2-
import type { PayloadRequestWithData } from 'payload/types'
2+
import type { PayloadRequest } from 'payload/types'
33

44
import Stripe from 'stripe'
55

@@ -10,7 +10,7 @@ import { handleWebhooks } from '../webhooks/index.js'
1010
export const stripeWebhooks = async (args: {
1111
config: PayloadConfig
1212
pluginConfig: StripePluginConfig
13-
req: PayloadRequestWithData
13+
req: PayloadRequest
1414
}): Promise<any> => {
1515
const { config, pluginConfig, req } = args
1616
let returnStatus = 200
@@ -47,6 +47,7 @@ export const stripeWebhooks = async (args: {
4747
event,
4848
payload: req.payload,
4949
pluginConfig,
50+
req,
5051
stripe,
5152
})
5253

@@ -57,6 +58,7 @@ export const stripeWebhooks = async (args: {
5758
event,
5859
payload: req.payload,
5960
pluginConfig,
61+
req,
6062
stripe,
6163
})
6264
}
@@ -69,6 +71,7 @@ export const stripeWebhooks = async (args: {
6971
event,
7072
payload: req.payload,
7173
pluginConfig,
74+
req,
7275
stripe,
7376
})
7477
}

packages/plugin-stripe/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import type { Payload } from 'payload'
22
import type { Config as PayloadConfig } from 'payload/config'
3+
import type { PayloadRequest } from 'payload/types'
34
import type Stripe from 'stripe'
45

56
export type StripeWebhookHandler<T = any> = (args: {
67
config: PayloadConfig
78
event: T
89
payload: Payload
910
pluginConfig?: StripePluginConfig
11+
req: PayloadRequest
1012
stripe: Stripe
1113
}) => void
1214

packages/plugin-stripe/src/ui/LinkToDoc.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import type { CustomComponent } from 'payload/config'
33
import type { UIField } from 'payload/types'
44

5+
import { CopyToClipboard } from '@payloadcms/ui/elements/CopyToClipboard'
56
import { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'
6-
// import CopyToClipboard from 'payload/dist/admin/components/elements/CopyToClipboard'
77
import { useFormFields } from '@payloadcms/ui/forms/Form'
88
import React from 'react'
99

@@ -29,7 +29,7 @@ export const LinkToDoc: CustomComponent<UIField> = () => {
2929
>
3030
View in Stripe
3131
</span>
32-
{/* <CopyToClipboard value={href} /> */}
32+
<CopyToClipboard value={href} />
3333
</div>
3434
<div
3535
style={{

packages/plugin-stripe/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
"src/**/*.spec.tsx"
2121
],
2222
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts", "src/**/*.json"],
23-
"references": [{ "path": "../payload" }, { "path": "../ui" }]
23+
"references": [{ "path": "../payload" }, { "path": "../ui" }, { "path": "../next" }]
2424
}

0 commit comments

Comments
 (0)