Stripe.Webhook reference
consumeEvents
Section titled “consumeEvents”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.
consumeEvents: Handling events
Section titled “consumeEvents: Handling events”yield* Stripe.consumeEvents("Events", { events: [Stripe.CustomerCreated, Stripe.InvoicePaid],}, Effect.fn(function* (event) { // event: CustomerCreated | InvoicePaid yield* Effect.log(event.type);}));ConsumeEventsLive
Section titled “ConsumeEventsLive”Source:
packages/stripe/src/ConsumeEventsLive.tsKind: 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.
RetrieveWebhookEndpoint
Section titled “RetrieveWebhookEndpoint”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();RetrieveWebhookEndpointHttp
Section titled “RetrieveWebhookEndpointHttp”Source:
packages/stripe/src/RetrieveWebhookEndpointHttp.tsKind: Layer · Provides:Stripe.RetrieveWebhookEndpoint
HTTP implementation of RetrieveWebhookEndpoint. Provide it on the
Function or Worker Effect.
WebhookEndpoint
Section titled “WebhookEndpoint”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.
WebhookEndpoint: Creating an endpoint
Section titled “WebhookEndpoint: Creating an 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" },});WebhookEndpoint: Disabling an endpoint
Section titled “WebhookEndpoint: Disabling an endpoint”const webhook = yield* Stripe.WebhookEndpoint("Charges", { url: "https://example.com/alchemy-stripe-webhook", enabledEvents: ["charge.succeeded"], disabled: true,});