Checkout Per Listing
Charge the buyer the listing's price using an imperative, dynamic-price paywall.
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
skuper listing keys the entitlement. require()returns a redirect or None โ check and act.- In dev the keyless mock provider completes checkout with no account.