๐Ÿ› Software ยท LARZ-401 · Session 4 of 8

Checkout Per Listing

Charge the buyer the listing's price using an imperative, dynamic-price paywall.

⏱ 11 min read📅 Updated 2026-07-25📊 Code examples throughout

The price isn't known until request time

import larz.money as money; money.enable(app, base_url="http://127.0.0.1:8000")

@app.get("/buy/<id:int>")
def buy(req):
    lst = Listing.get(req.params["id"])
    sku = "listing:%d" % lst.id
    gate = app.money.require(req, sku=sku, cents=lst.price_cents,
                             success_path="/bought/%d" % lst.id)
    if gate: return gate            # -> checkout
    return Response.redirect("/bought/%d" % lst.id)

A fixed @app.paid("$9") can't price a whole catalog. app.money.require(...) is the imperative version: it returns a checkout redirect if the caller hasn't paid for that sku, or None if they have โ€” so you can price each item at request time.

Takeaways

  • One sku per listing keys the entitlement.
  • require() returns a redirect or None โ€” check and act.
  • In dev the keyless mock provider completes checkout with no account.

More in this course

Course home → · Browse all courses →