Commerce Flow

Order Lifecycle

  1. Customer submits email on pricing page.
  2. /api/checkout validates product and creates pending order in D1.
  3. PayPal approval redirects user to success page with order ID.
  4. /api/paypal/capture captures payment and marks order as paid.
  5. Delivery token is created and stored in D1 with expiration.
  6. Optional delivery email is sent with secure download URL.

Delivery and Access Control

  • Download endpoint requires valid token.
  • Expired tokens return expiration response.
  • R2 object retrieval is server-side only.
  • Download counters and timestamps are persisted in D1.

Failure Handling

  • Missing email or order data: request validation errors.
  • PayPal non-completed status: capture endpoint returns payment-state error.
  • Missing R2 object: download endpoint returns not-found response.
  • Email delivery disabled: order flow still succeeds; email send is optional.