Plug adapter for the bare JSON-RPC payment transport.
Mount on a POST route (or forward) with the same endpoint options as
MPP.Plug, plus a :handler that receives the verified JSON-RPC request
map and returns a result or JSON-RPC response:
forward "/rpc",
to: MPP.Transports.JsonRpc.Plug,
init_opts: [
handler: &MyApp.Rpc.dispatch/1,
secret_key: secret,
realm: "rpc.example.com",
method: MyMethod,
amount: "1000",
currency: "usd"
]Payment-required and verification failures are JSON-RPC errors (-32042 /
-32602 / -32043) on HTTP 200, matching JSON-RPC-over-HTTP convention
and the MPP transport spec's error.data.httpStatus: 402 field. Payment-gated
notifications (JSON-RPC requests with no id) are dropped with HTTP 204.
Summary
Types
@type state() :: %{config: MPP.Plug.Config.t(), handler: (map() -> term())}