Raxol.Payments.Confirm (Raxol Payments v0.2.0)

Copy Markdown View Source

Built-in confirmation callbacks for Raxol.Payments.Req.AutoPay's :on_confirm option.

Agents handling payments above policy.require_confirmation_above need a way to escalate to a human. This module provides ready-made callbacks for the common surfaces. All have the shape (amount, domain) -> :approve | :deny so they slot straight into AutoPay.attach/2.

Terminal prompt

AutoPay.attach(req,
  wallet: MyWallet,
  policy: policy,
  ledger: ledger,
  on_confirm: Raxol.Payments.Confirm.terminal()
)

When the gate fires, the agent process blocks on IO.gets/1 until you type y or n. Only use this when there is a real interactive TTY on the agent's process group leader.

Auto-approve / auto-deny (testing only)

Raxol.Payments.Confirm.always(:approve)
Raxol.Payments.Confirm.always(:deny)

Useful in tests and rehearsals where you want to exercise the callback path without a human in the loop.

Summary

Functions

Always returns the same decision. For tests and rehearsals.

Build a callback that prompts on stdin and reads the answer with IO.gets/1.

Types

callback()

@type callback() :: (Decimal.t(), String.t() -> decision())

decision()

@type decision() :: :approve | :deny

Functions

always(decision)

@spec always(decision()) :: callback()

Always returns the same decision. For tests and rehearsals.

terminal(opts \\ [])

@spec terminal(keyword()) :: callback()

Build a callback that prompts on stdin and reads the answer with IO.gets/1.

Treats anything starting with y (case-insensitive) as :approve, everything else (including an empty answer or EOF) as :deny.

Options

  • :device -- IO device, default :stdio.
  • :timeout_ms -- max time to wait for an answer, default 60_000. On timeout the callback denies. Pass :infinity to wait forever (the old behavior); only safe when you know there's a real human on a real TTY.