Skip to content

Stripe.Webhook reference

Source: packages/stripe/src/ConsumeEvents.ts

Subscribe to Stripe webhook events on the host.

consumeEvents provisions the WebhookEndpoint itself: it derives the delivery URL from the host’s url, enables the selected event types, and binds the endpoint’s minted signing secret onto the host so deliveries are verified. No separate endpoint declaration is needed.

Provide Stripe.ConsumeEventsLive on the host’s Effect, e.g. a Cloudflare Worker.

yield* Stripe.consumeEvents("Events", {
events: [Stripe.CustomerCreated, Stripe.InvoicePaid],
}, Effect.fn(function* (event) {
// event: CustomerCreated | InvoicePaid
yield* Effect.log(event.type);
}));

Source: packages/stripe/src/ConsumeEventsLive.ts Kind: Layer · Provides: Stripe.EventSource

consumeEvents on any WebhookHost.

Deploy-time: provisions a WebhookEndpoint pointing at the host (at the subscribed path) and binds its minted signing secret so deliveries can be verified. Under alchemy dev the host is not publicly reachable, so no endpoint is provisioned. Runtime: claims requests on that path, verifies Stripe-Signature, and runs the handler once per event.

Every Cloudflare Worker is a WebhookHost, so this is the only layer to provide.

Source: packages/stripe/src/RetrieveWebhookEndpoint.ts

Retrieve a bound Stripe Webhook Endpoint over HTTP.

RetrieveWebhookEndpoint: Reading a Webhook Endpoint

Section titled “RetrieveWebhookEndpoint: Reading a Webhook Endpoint”
const retrieve = yield* Stripe.RetrieveWebhookEndpoint(hook);
const live = yield* retrieve();

Source: packages/stripe/src/RetrieveWebhookEndpointHttp.ts Kind: Layer · Provides: Stripe.RetrieveWebhookEndpoint

HTTP implementation of RetrieveWebhookEndpoint. Provide it on the Function or Worker Effect.

Source: packages/stripe/src/WebhookEndpoint.ts

A Stripe webhook endpoint — the HTTPS destination Stripe POSTs event payloads to. URL, enabled events, description, disabled, and metadata update in place. The signing secret is returned only on create and is stored as Redacted. Deleting the resource deletes the endpoint.

Charge events

const webhook = yield* Stripe.WebhookEndpoint("Charges", {
url: "https://example.com/alchemy-stripe-webhook",
enabledEvents: ["charge.succeeded", "charge.failed"],
});

Event classes, for a Worker URL you already have

const webhook = yield* Stripe.WebhookEndpoint("Events", {
url: Output.interpolate`${api.url}/webhooks/stripe`,
enabledEvents: [Stripe.CustomerCreated, Stripe.InvoicePaid],
});
yield* Stripe.bindWebhookSecret(api, webhook.secret);

On a Worker, prefer consumeEvents — it provisions this endpoint and binds the secret for you.

Description, metadata, and all events

const webhook = yield* Stripe.WebhookEndpoint("AllEvents", {
url: "https://example.com/alchemy-stripe-webhook",
enabledEvents: ["*"],
description: "Alchemy test webhook",
metadata: { purpose: "billing" },
});
const webhook = yield* Stripe.WebhookEndpoint("Charges", {
url: "https://example.com/alchemy-stripe-webhook",
enabledEvents: ["charge.succeeded"],
disabled: true,
});