examples/storefront Public
import { WorkerEntrypoint } from "cloudflare:workers";import type { Charge, Intent, Payments } from "../../../src/payments.ts";import { stripePayments } from "./stripe.ts";import { handleWebhook, type Env } from "./webhook.ts";// What storefront-api calls through its PAYMENTS service binding (entrypoint PaymentsService).// The Stripe secret key never leaves this Worker.export class PaymentsService extends WorkerEntrypoint<Env> implements Payments { createIntent(charge: Charge): Promise<Intent> { return stripePayments(this.env.STRIPE_SECRET_KEY).createIntent(charge); } cancelIntent(intentId: string): Promise<boolean> { return stripePayments(this.env.STRIPE_SECRET_KEY).cancelIntent(intentId); }}// The public side: Stripe's webhook at /stripe/webhook, and nothing else.export default { fetch(req, env) { return handleWebhook(req, env); },} satisfies ExportedHandler<Env>;