Creates a webhook verification object for validating Stripe event signatures and constructing events from raw payloads, ensuring secure webhook handling.
export function createWebhooks(
platformFunctions: PlatformFunctions
): WebhookObject {
function buildEvent(jsonPayload: Record<string, unknown>): Event {
if (jsonPayload && jsonPayload.object === 'v2.core.event') {
throw new Error(
'You passed a thin event notification to a function that expects a webhook. Use the corresponding EventNotification method instead.'
);
}
return (jsonPayload as unknown) as Event;
}
const Webhook: WebhookObject = {
DEFAULT_TOLERANCE: 300, // 5 minutes
signature: null,
constructEvent(
payload: WebhookPayload,
header: WebhookHeader,
secret: string,
tolerance?: number,
cryptoProvider?: CryptoProvider,
receivedAt?: number
): Event {
try {
if (!this.signature)
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key