View as Markdown

Set a spending limit#

The person approves an amount per month once; the SDK keeps the total and refuses what goes over.

Level 1: A person approves with a passkey.
Class write: Something changes and can be undone. The approval can be reused.
routes.append(route("POST", "/orders", "orders:place", cls="write", level=1, resource="order:new",
                    amount_field="/total", summary="Place an order",
                    body={"total": "a decimal string, e.g. 60.00", "currency": "e.g. EUR"}))
templates["orders:place"] = "Order for up to {amount.max} {amount.currency} per {amount.per}"


@app.post("/orders")
def place_order():
    # The SDK keeps the total of the period: an order over the limit the person approved never gets here.
    order = request.json
    return {"ordered": order["total"], "currency": order["currency"]}, 201

What the test proves#

  • the person approves up to 100 EUR per month, and a first order of 60: 201
  • 40.01 more is refused, 40.00 passes without asking, then not one cent more
  • another currency is refused, with room left under the limit
  • over the limit, the agent asks again: a new approval has its own total