Personalized coffee subscriptions, curated by our Cup of Excellence judge
MG
★★★★★ 2079 reviews
Wake up to the world's best coffeeSupport the top local roasters in the U.S.Enjoy coffee fresh and bursting with flavorCurated from a broad selection of specialty coffeeExclusive member pricing and shipping perksPersonalize every delivery
"
if active == 1:
cards = "".join(f"" for key,label,copy,count in TASTES)
return prefix + f"
What's your ideal coffee tasting experience?
Choose a preparation, then a profile for your plan.
"
if active == 2:
def render_quantity(item: tuple[str, str, str, str]) -> str:
key, label, amount, detail = item
candidate_class = " candidate-only" if key == "trace-six-cup" else ""
candidate_badge = "TRACE COMPATIBILITY" if key == "trace-six-cup" else ""
checked = "checked" if draft["quantity"] == key else ""
return (
f""
)
quantities = "".join(render_quantity(item) for item in QUANTITIES)
cadence = "".join(f"" for week in ("2","3","4","5","6"))
return prefix + f"
How much coffee would you like per delivery?
Choose the amount and schedule that fits your mornings.
"
plan_cards = "".join(f"" for key,label,copy in (("pay-per-delivery","Pay-Per-Delivery","About $17 per 12 oz bag plus $5.45 shipping."),("annual","Annual Plan","About $15 per bag with shipping included.")))
labels = {"whole-bean":"Whole Bean","freshly-ground":"Freshly Ground","curators-choice":"Curator's Choice™"}
amount = business.draft_amount_minor(draft)
return prefix + f"
One last step to better mornings
Review your coffee and choose how you would like to pay.
"
@app.get("/coffee-subscription/configure", include_in_schema=False)
async def configure(request: Request) -> HTMLResponse:
owner = request_owner(request)
with BACKEND.lifecycle.connection() as connection:
draft = business.load_draft(connection, owner)
return page("Bean Box® | Configure Your Coffee Subscription", subscription_body(draft, owner), owner, "subscriptions", cookies=True)
@app.post("/coffee-subscription/configure", include_in_schema=False)
async def configure_post(request: Request) -> Response:
form = await request.form()
try:
owner = submitted_owner(request, form.get("owner"))
except ValueError:
return JSONResponse({"error": "session actor mismatch"}, status_code=403)
action = str(form.get("action") or "")
with BACKEND.lifecycle.connection(transaction=True) as connection:
draft = business.load_draft(connection, owner)
if action == "back-tasting":
draft["step"] = 1
elif action == "back-quantity":
draft["step"] = 2
elif action == "to-quantity":
prep, taste = str(form.get("preparation") or ""), str(form.get("taste") or "")
if prep not in {"whole-bean","freshly-ground"} or taste not in {item[0] for item in TASTES}:
return page("Choose your coffee", subscription_body(draft, owner, "Choose a preparation and tasting experience."), owner, "subscriptions", status=422)
draft.update(preparation=prep, taste=taste, step=2)
elif action == "to-review":
quantity, cadence = str(form.get("quantity") or ""), str(form.get("cadence") or "")
if quantity not in {item[0] for item in QUANTITIES} or cadence not in {"2","3","4","5","6"}:
return page("Choose quantity", subscription_body(draft, owner, "Choose a quantity and delivery frequency."), owner, "subscriptions", status=422)
draft.update(quantity=quantity, cadence=cadence, step=3)
elif action == "checkout":
plan = str(form.get("plan") or "")
if plan not in {"pay-per-delivery","annual"}:
return page("Choose a plan", subscription_body(draft, owner, "Choose Pay-Per-Delivery or Annual Plan."), owner, "subscriptions", status=422)
draft.update(plan=plan, step=3)
business.save_draft(connection, owner, draft)
return RedirectResponse("/checkout", status_code=303)
business.save_draft(connection, owner, draft)
return page("Bean Box® | Configure Your Coffee Subscription", subscription_body(draft, owner), owner, "subscriptions")
def product_card(row) -> str:
colors = ("#d7b77d", "#6f75aa", "#d8c9c0", "#9ca878", "#d6907a", "#b3a08b")
return f"
", owner, "coffee", status=422)
if current_page < 1 or current_page > 1000:
return page("Catalogue | Bean Box®", "
Page must be between 1 and 1000.
", owner, "coffee", status=422)
with BACKEND.lifecycle.connection() as connection:
rows, total = business.list_coffees(connection, q.strip()[:80], roast, current_page)
grid = "".join(product_card(row) for row in rows) if rows else "
"
fields = "".join(f"" for name,label in (("first_name","First name"),("last_name","Last name"),("email","Email fixture"),("address","Address fixture"),("city","City"),("state","State"),("zip","ZIP code")))
options = "".join(f"" for key, label in (("sandbox-approved", "Simulated approval"), ("sandbox-declined", "Simulated decline"), ("sandbox-retry", "Simulated retry")))
form = f""
return f"
Checkout
{form}
"
@app.get("/checkout", include_in_schema=False)
async def checkout_get(request: Request) -> HTMLResponse:
owner = request_owner(request)
with BACKEND.lifecycle.connection() as connection:
draft = business.load_draft(connection, owner)
return page("Checkout | Bean Box®", checkout_body(draft, owner), owner)
@app.post("/checkout", include_in_schema=False)
async def checkout_post(request: Request) -> HTMLResponse:
form = await request.form()
try:
owner = submitted_owner(request, form.get("owner"))
except ValueError:
return JSONResponse({"error": "session actor mismatch"}, status_code=403)
items = [(str(key), str(value)) for key, value in form.multi_items()]
keys = [key for key, _value in items]
if len(keys) != len(set(keys)) or any(len(key) > 80 or len(value) > 500 for key, value in items):
owner = request_owner(request)
with BACKEND.lifecycle.connection() as connection:
draft = business.load_draft(connection, owner)
return page("Checkout rejected | Bean Box®", checkout_body(draft, owner, error="Duplicate or oversized checkout fields are forbidden."), owner, status=422)
fields = dict(items)
with BACKEND.lifecycle.connection(transaction=True) as connection:
draft = business.load_draft(connection, owner)
allowed_fields = set(FIXTURE) | {"owner", "scenario_id", "idempotency_key"}
unknown = set(fields) - allowed_fields
if unknown:
return page("Checkout rejected | Bean Box®", checkout_body(draft, owner, fields, "Only the synthetic shipping fixture and opaque simulation fields are accepted; payment credentials are forbidden."), owner, status=422)
mismatched = [name for name, expected in FIXTURE.items() if fields.get(name) != expected]
if mismatched:
return page("Synthetic fixture required | Bean Box®", checkout_body(draft, owner, fields, "Use the supplied synthetic fixture exactly; real or arbitrary personal data is not accepted."), owner, status=422)
scenario = fields.get("scenario_id", "")
if scenario not in {"sandbox-approved","sandbox-declined","sandbox-retry"}:
return page("Choose payment simulation | Bean Box®", checkout_body(draft, owner, fields, "Choose an approved simulation scenario."), owner, status=422)
idempotency = fields.get("idempotency_key", "")[:200]
existing = connection.execute("SELECT order_id,status FROM bean_box_orders WHERE owner=? AND idempotency_key=?", (owner, idempotency)).fetchone()
if existing:
prior = connection.execute("SELECT amount_minor,snapshot_json FROM bean_box_orders WHERE order_id=?", (existing["order_id"],)).fetchone()
prior_snapshot = json.loads(prior["snapshot_json"])
if int(prior["amount_minor"]) != business.draft_amount_minor(draft) or prior_snapshot.get("draft") != draft:
return page("Checkout conflict | Bean Box®", checkout_body(draft, owner, fields, "This idempotency key is bound to a different order configuration."), owner, status=409)
business.create_subscription(connection, owner, existing["order_id"], draft)
return page("Order recorded | Bean Box®", checkout_body(draft, owner, success={"order_id": existing["order_id"]}), owner)
amount = business.draft_amount_minor(draft)
fingerprint = business.payment_fingerprint(owner, draft, amount)
try:
flow = BACKEND.payments.create_intent(owner=owner, amount_minor=amount, currency="USD", fingerprint=fingerprint, idempotency_key=f"create.{idempotency}", connection=connection)
attempt = BACKEND.payments.attempt(flow_id=flow["flow_id"], owner=owner, amount_minor=amount, currency="USD", fingerprint=fingerprint, scenario_id=scenario, idempotency_key=f"attempt.{idempotency}.{scenario}", connection=connection)
if attempt["status"] != "APPROVED":
message = "The local payment simulation was declined. Choose Simulated approval and retry." if attempt["status"] == "DECLINED" else "The local payment simulation is retryable. Please retry or choose Simulated approval."
status = 402 if attempt["status"] == "DECLINED" else 409
return page("Payment simulation | Bean Box®", checkout_body(draft, owner, fields, message), owner, status=status)
BACKEND.payments.consume_approval(connection, flow_id=flow["flow_id"], owner=owner, amount_minor=amount, currency="USD", fingerprint=fingerprint)
order_id = "BB-" + hashlib.sha256((owner + idempotency).encode()).hexdigest()[:10].upper()
snapshot = {"site_id": SITE_ID, "draft": draft, "shipping_fixture": FIXTURE, "payment": {"adapter": "local-sandbox", "scenario_id": scenario, "is_simulation": True}}
connection.execute("INSERT INTO bean_box_orders(order_id,owner,idempotency_key,payment_flow_id,status,amount_minor,snapshot_json,created_at) VALUES (?,?,?,?,?,?,?,datetime('now'))", (order_id, owner, idempotency, flow["flow_id"], "local-confirmed", amount, json.dumps(snapshot, sort_keys=True)))
business.create_subscription(connection, owner, order_id, draft)
except PaymentError as exc:
connection.rollback()
return page("Payment simulation error | Bean Box®", checkout_body(draft, owner, fields, str(exc)), owner, status=422)
return page("Order recorded | Bean Box®", checkout_body(draft, owner, success={"order_id": order_id}), owner)
@app.get("/api/catalogue/count", include_in_schema=False)
async def catalogue_count() -> JSONResponse:
with BACKEND.lifecycle.connection() as connection:
count = connection.execute("SELECT COUNT(*) FROM bean_box_coffees").fetchone()[0]
return JSONResponse({"site_id": SITE_ID, "coffee_records": count})
@app.post("/api/cart/items", include_in_schema=False)
async def api_cart_add(request: Request) -> JSONResponse:
payload, error = await _json_object(request)
if error is not None:
return error
if not isinstance(payload, dict) or set(payload) - {"coffee_id", "owner"}:
return JSONResponse({"error": "unknown field"}, status_code=422)
owner = request_owner(request)
if payload.get("owner") is not None and payload.get("owner") != owner:
return JSONResponse({"error": "session actor mismatch"}, status_code=403)
coffee_id = payload.get("coffee_id")
if type(coffee_id) is not int or not 1 <= coffee_id <= 240:
return JSONResponse({"error": "coffee_id required"}, status_code=422)
with BACKEND.lifecycle.connection(transaction=True) as connection:
if connection.execute("SELECT 1 FROM bean_box_coffees WHERE id=?", (coffee_id,)).fetchone() is None:
return JSONResponse({"error": "coffee not found"}, status_code=404)
business.add_cart(connection, owner, coffee_id)
count = sum(int(row["quantity"]) for row in business.cart(connection, owner))
return JSONResponse({"site_id": SITE_ID, "cart_count": count}, status_code=201)
@app.get("/api/cart", include_in_schema=False)
async def api_cart(request: Request) -> JSONResponse:
owner = request_owner(request)
supplied = request.query_params.get("owner")
if supplied is not None and supplied != owner:
return JSONResponse({"error": "session actor mismatch"}, status_code=403)
with BACKEND.lifecycle.connection() as connection:
count = sum(int(row["quantity"]) for row in business.cart(connection, owner))
return JSONResponse({"site_id": SITE_ID, "cart_count": count})
@app.post("/api/checkout/validate", include_in_schema=False)
async def api_checkout_validate(request: Request) -> JSONResponse:
payload, error = await _json_object(request)
if error is not None:
return error
if not isinstance(payload, dict) or set(payload) != {"scenario_id"}:
return JSONResponse({"error": "only opaque scenario_id is accepted"}, status_code=422)
scenario = payload.get("scenario_id")
if scenario not in {"sandbox-approved", "sandbox-declined", "sandbox-retry"}:
return JSONResponse({"error": "unknown local-sandbox scenario"}, status_code=422)
return JSONResponse({"site_id": SITE_ID, "adapter": "local-sandbox", "scenario_id": scenario})
@app.get("/coffee-gifts", include_in_schema=False)
async def gifts(request: Request) -> HTMLResponse:
owner = request_owner(request)
body = "Share a better morning
Coffee gifts for every kind of coffee lover
Explore subscription gifts, tasting boxes, pairings and equipment picks.
GIVE A SUBSCRIPTION"
return page("Coffee Gifts | Bean Box®", body, owner, "gifts")
@app.get("/coffee-equipment", include_in_schema=False)
async def gear(request: Request) -> HTMLResponse:
owner = request_owner(request)
body = "Brew it beautifully
Coffee equipment
Thoughtful brewers, kettles, mugs and scales selected for a better home setup.
PAIR WITH COFFEE"
return page("Coffee Equipment | Bean Box®", body, owner, "gear")
@app.get("/faq", include_in_schema=False)
async def faq(request: Request) -> HTMLResponse:
owner = request_owner(request)
questions = (("What is Bean Box?","A curated specialty coffee discovery and subscription experience."),("Can I get ground coffee?","Yes. Choose Freshly Ground during Tasting Experience."),("How often can coffee arrive?","Every 2, 3, 4, 5 or 6 weeks. Four weeks is the monthly option."),("Can I change my plan?","Return to the configurator before confirming."),("Is this a real payment?","No. Checkout accepts only synthetic simulation scenarios and makes zero remote requests."))
body = "
Frequently asked questions
" + "".join(f"{esc(q)}
{esc(a)}
" for q,a in questions) + ""
return page("FAQ | Bean Box®", body, owner)
@app.get("/roasters", include_in_schema=False)
@app.get("/about", include_in_schema=False)
@app.get("/contact", include_in_schema=False)
@app.get("/blog", include_in_schema=False)
@app.get("/resources", include_in_schema=False)
@app.get("/terms", include_in_schema=False)
@app.get("/privacy", include_in_schema=False)
@app.get("/returns", include_in_schema=False)
async def information_page(request: Request) -> HTMLResponse:
owner = request_owner(request)
slug = request.url.path.strip("/")
content = {
"roasters": ("Coffee roasters", "A directory-style view of the independent-roaster catalogue represented by the 240 searchable coffee fixtures."),
"about": ("About this experience", "This experience preserves observed public structure and interactions without claiming source affiliation or redistribution rights."),
"contact": ("Contact", "Contact submission and real email are outside the frozen anonymous scope. No message or address is collected here."),
"blog": ("Coffee stories", "An index for the publicly observed editorial route; source articles were not redistributed."),
"resources": ("Coffee resources", "Explore the working catalogue, configurator and FAQ without any runtime request to the source website."),
"terms": ("Terms of service", "No source legal text is reproduced. This evaluation experience cannot create a real order or subscription."),
"privacy": ("Privacy", "The site uses only a site-bound anonymous session. It rejects real payment data and does not send runtime traffic to the source."),
"returns": ("Returns", "Real fulfillment and returns are unavailable because checkout creates no source order."),
}
title, copy = content[slug]
body = f"Bean Box
{esc(title)}
{esc(copy)}
EXPLORE COFFEE"
return page(f"{title} | Bean Box®", body, owner)
@app.get("/account", include_in_schema=False)
async def account(request: Request) -> HTMLResponse:
owner = request_owner(request)
account_info = authenticated_account(request)
if account_info is None:
body = "