Files
payload/packages/plugin-stripe/src/webhooks/index.ts
Alessio Gravili 03291472d6 chore: bump all eslint dependencies, run lint and prettier (#9128)
This fixes a peer dependency error in our monorepo, as
eslint-plugin-jsx-a11y finally supports eslint v9.

Additionally, this officially adds TypeScript 5.6 support for
typescript-eslint.
2024-11-12 10:18:22 -05:00

57 lines
1.4 KiB
TypeScript

import type { StripeWebhookHandler } from '../types.js'
import { handleCreatedOrUpdated } from './handleCreatedOrUpdated.js'
import { handleDeleted } from './handleDeleted.js'
export const handleWebhooks: StripeWebhookHandler = (args) => {
const { event, payload, pluginConfig } = args
if (pluginConfig?.logs) {
payload.logger.info(`🪝 Received Stripe '${event.type}' webhook event with ID: '${event.id}'.`)
}
// could also traverse into event.data.object.object to get the type, but that seems unreliable
// use cli: `stripe resources` to see all available resources
const resourceType = event.type.split('.')[0]
const method = event.type.split('.').pop()
const syncConfig = pluginConfig?.sync?.find(
(sync) => sync.stripeResourceTypeSingular === resourceType,
)
if (syncConfig) {
switch (method) {
case 'created': {
void handleCreatedOrUpdated({
...args,
pluginConfig,
resourceType,
syncConfig,
})
break
}
case 'deleted': {
void handleDeleted({
...args,
pluginConfig,
resourceType,
syncConfig,
})
break
}
case 'updated': {
void handleCreatedOrUpdated({
...args,
pluginConfig,
resourceType,
syncConfig,
})
break
}
default: {
break
}
}
}
}