Runtime & API

Runtime Contract

  • Execution environment: Cloudflare Pages Functions (Workers runtime).
  • D1 binding: d1_jb
  • R2 binding: r2_jb
  • Compatibility flags: nodejs_compat

Required Environment Variables

  • PAYPAL_CLIENT_ID
  • PAYPAL_CLIENT_SECRET

Optional: PAYPAL_MODE, PUBLIC_BASE_URL, RESEND_API_KEY, RESEND_FROM_EMAIL, PRODUCT_ID.

Endpoint Semantics

  • POST /api/checkout: creates PayPal order and pending D1 order row.
  • POST /api/paypal/capture: captures payment, updates paid state, creates delivery token.
  • POST /api/orders: returns order history filtered by customer email.
  • GET /api/download?token=...: validates token, streams R2 object, updates download metrics.

Data Model (Operational)

  • products: active sellable package metadata.
  • orders: payment state and transaction references.
  • deliveries: tokenized secure delivery records and download audit.