Elixir implementation of the Machine Payments Protocol (MPP).
MPP enables machine-to-machine payments via HTTP 402. This library provides Plug middleware that adds pay-per-call billing to any Phoenix or Plug application.
How it works
- Client requests a protected resource
- Server responds with
402 Payment Requiredand a payment challenge - Client fulfills payment (Stripe, stablecoins, or on-chain)
- Client retries with payment credential in
Authorization: Paymentheader - Server verifies payment and returns the resource with a
Payment-Receiptheader
No user accounts. No API keys. No signup flow. Payment is authentication.
Protocol
Built on the MPP specification — an IETF draft co-developed by Stripe and Tempo Labs. Also supports x402 for on-chain payments.
Modules
MPP.Plug— Plug middleware implementing the 402 payment handshakeMPP.Challenge— HMAC-SHA256 bound challenge creation and verificationMPP.Credential— Payment credential encoding/decodingMPP.Receipt— Proof-of-payment receipt serializationMPP.Headers— WWW-Authenticate, Authorization, Payment-Receipt header formattingMPP.AcceptPayment— Accept-Payment client-preference header parse/format/rankMPP.Errors— RFC 9457 Problem Detail error typesMPP.Method— Behaviour for pluggable payment methodsMPP.Methods.Stripe— Stripe SPT payment verificationMPP.Methods.Stripe.Subscription— Stripe fixed-price subscription activationMPP.Methods.Tempo— Tempo on-chain TIP-20 payment verificationMPP.Methods.Tempo.Subscription— Tempo access-key subscription activation and renewalMPP.Methods.EVM— Generic EVM on-chain payment verification (any EVM chain)MPP.Methods.Solana— Solana native SOL and SPL token charge verificationMPP.Methods.NearIntents— NEAR Intents hash-credential charge verification via 1Click + origin RPCMPP.Intents.Charge— Charge intent request schemaMPP.Intents.Session— Session intent request schema (pay-as-you-go / metered)MPP.Intents.Subscription— Shared recurring-subscription intent schemaMPP.Session.Channel— Session channel state, balance, and action wire mappingMPP.Session.Voucher— EIP-712 voucher typed data and signature verificationMPP.Session.Payload— Session credential payload schema (open/voucher/topUp/close)MPP.Session.Actions— Session credential action handlers and per-channel balance trackingMPP.Session.Method—usewrapper that dispatchesverify/2through session actionsMPP.Session.Store— Pluggable session-channel persistenceMPP.Session.ETSStore— ETS-backed default session storeMPP.Subscription.Store— Pluggable recurring-subscription persistenceMPP.Subscription.ETSStore— Application-started single-node subscription storeMPP.BodyDigest— SHA-256 body digest computation and verificationMPP.Amount— Amount/decimals helpers (parse_units, dollar parsing)MPP.Expires— Expiration timestamp helpers (duration offsets, assert!)MPP.DID— DID helpers for EVM credential sourcesMPP.JCS— RFC 8785 JSON Canonicalization Scheme for HMAC interopMPP.Verifier— Transport-neutral payment credential verificationMPP.Mcp— MCP (JSON-RPC) transport constants and helpersMPP.Transports.JsonRpc— Bare JSON-RPC transport (root-level_meta, Plug adapter)MPP.Transports.WebSocket— WebSocket adapter: handshake challenge, credential/receipt frames, JSON-RPCmessageframesMPP.Client.PaymentProvider— Behaviour for client-side payment providersMPP.Client.MultiProvider— Multi-provider dispatch (first-match routing)MPP.Client.Providers.Tempo— Built-in Tempo charge provider (chain-pinned, attribution-bound, machine-token route when advertised)MPP.Client.Providers.Stripe— Built-in Stripe charge provider (Shared Payment Tokens)MPP.Client.SelectionPolicy— Transport-neutral challenge selection/orderingMPP.Client.Req— Payment-aware Req plugin (402 detect, pay, retry)MPP.Client.MCP— Payment-aware MCP client (select, approve, pay, retry once)MPP.Client.Transport.WebSocket— WebSocket transport:challengeframes,Paymentcredential frames, retry/backoffMPP.Client.AcceptPolicy— GateAccept-Paymentheader injection by URLMPP.Discovery.OpenApi— OpenAPI 3.1.0 payment discovery generationMPP.Discovery.PaymentInfo— x-payment-info parsing and normalization
Discovery
Use MPP.describe/0-2 for progressive API discovery:
MPP.describe() # Level 1: all modules
MPP.describe(:challenge) # Level 2: functions in Challenge
MPP.describe(:challenge, :create) # Level 3: full contract for create/2
Summary
Functions
Return the list of modules registered with this library.
Return a Level 1 overview of all modules in this library.
Return Level 2 function list for a module (by full atom, or short name as string or atom).
Return Level 3 function detail (or nil if not found).
Functions
@spec __descripex_modules__() :: [module()]
Return the list of modules registered with this library.
@spec describe() :: [map()]
Return a Level 1 overview of all modules in this library.
Return Level 2 function list for a module (by full atom, or short name as string or atom).
Return Level 3 function detail (or nil if not found).