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.Errors— RFC 9457 Problem Detail error typesMPP.Method— Behaviour for pluggable payment methodsMPP.Methods.Stripe— Stripe SPT payment verificationMPP.Methods.Tempo— Tempo on-chain TIP-20 payment verificationMPP.Methods.EVM— Generic EVM on-chain payment verification (any EVM chain)MPP.Intents.Charge— Charge intent request schemaMPP.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.Client.PaymentProvider— Behaviour for client-side payment providersMPP.Client.MultiProvider— Multi-provider dispatch (first-match routing)MPP.Client.AcceptPolicy— GateAccept-Paymentheader injection by URL
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).
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).
Return Level 3 function detail (or nil if not found).