Order Lifecycle
- Customer submits email on pricing page.
/api/checkout validates product and creates pending order in D1. - PayPal approval redirects user to success page with order ID.
/api/paypal/capture captures payment and marks order as paid. - Delivery token is created and stored in D1 with expiration.
- 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.