Documentation
¶
Overview ¶
Package mpp provides a Go SDK for the Machine Payments Protocol (MPP).
MPP is an open standard for inline HTTP payments built on top of the HTTP 402 "Payment Required" status code and the WWW-Authenticate / Authorization header pair (Web Payment Auth, IETF draft-ryan-httpauth-payment).
Quick start — server side ¶
mppServer := server.New(server.WithMethod("tempo", myTempoVerifier))
http.Handle("/api/data", nethttp.Middleware(mppServer)(myHandler))
Quick start — client side ¶
provider := &client.StaticProvider{Method: "tempo", Credential: myCredFn}
httpClient := client.NewHTTPClient(provider)
resp, err := httpClient.Get("https://api.example.com/data")
RFC 9457 error types live in package github.com/deszhou/mpp-go/mperr. They are re-exported here for convenience.
Index ¶
Constants ¶
const ( WWWAuthenticateHeader = protocol.WWWAuthenticateHeader AuthorizationHeader = protocol.AuthorizationHeader PaymentReceiptHeader = protocol.PaymentReceiptHeader PaymentScheme = protocol.PaymentScheme )
Header name constants re-exported for convenience.
const ( CoreProblemTypeBase = mperr.CoreProblemTypeBase SessionProblemTypeBase = mperr.SessionProblemTypeBase )
RFC 9457 base URIs.
const Version = "0.1.0"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MppError ¶
Payment error types (re-exported from mperr).
func NewMppError ¶
func NewMppError(kind MppErrorKind, message string) *MppError
NewMppError creates an MppError (delegates to mperr).
type MppErrorKind ¶
type MppErrorKind = mperr.MppErrorKind
Payment error types (re-exported from mperr).
const ( KindMalformedCredential MppErrorKind = mperr.KindMalformedCredential KindInvalidChallenge MppErrorKind = mperr.KindInvalidChallenge KindVerificationFailed MppErrorKind = mperr.KindVerificationFailed KindPaymentExpired MppErrorKind = mperr.KindPaymentExpired KindPaymentRequired MppErrorKind = mperr.KindPaymentRequired KindInvalidPayload MppErrorKind = mperr.KindInvalidPayload KindBadRequest MppErrorKind = mperr.KindBadRequest KindInsufficientBalance MppErrorKind = mperr.KindInsufficientBalance KindInvalidSignature MppErrorKind = mperr.KindInvalidSignature KindSignerMismatch MppErrorKind = mperr.KindSignerMismatch KindAmountExceedsDeposit MppErrorKind = mperr.KindAmountExceedsDeposit KindDeltaTooSmall MppErrorKind = mperr.KindDeltaTooSmall KindChannelNotFound MppErrorKind = mperr.KindChannelNotFound KindChannelClosed MppErrorKind = mperr.KindChannelClosed KindInternal MppErrorKind = mperr.KindInternal )
Problem kind constants (re-exported from mperr).
type PaymentErrorDetails ¶
type PaymentErrorDetails = mperr.PaymentErrorDetails
Payment error types (re-exported from mperr).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client implements the MPP client-side payment provider and HTTP client.
|
Package client implements the MPP client-side payment provider and HTTP client. |
|
Package digest provides SHA-256 body digest computation and verification.
|
Package digest provides SHA-256 body digest computation and verification. |
|
examples
|
|
|
client
command
Example MPP client that automatically handles HTTP 402 payment challenges.
|
Example MPP client that automatically handles HTTP 402 payment challenges. |
|
server
command
Example MPP server using the standard net/http package and the mock payment method.
|
Example MPP server using the standard net/http package and the mock payment method. |
|
tempo
command
Example: full Tempo payment flow using the mock EVM signer.
|
Example: full Tempo payment flow using the mock EVM signer. |
|
Package expires provides helpers for generating RFC 3339 expiration timestamps.
|
Package expires provides helpers for generating RFC 3339 expiration timestamps. |
|
http
|
|
|
echo
Package echo provides MPP middleware for the Echo web framework.
|
Package echo provides MPP middleware for the Echo web framework. |
|
fiber
Package fiber provides MPP middleware for the Fiber web framework.
|
Package fiber provides MPP middleware for the Fiber web framework. |
|
gin
Package gin provides MPP middleware for the Gin web framework.
|
Package gin provides MPP middleware for the Gin web framework. |
|
nethttp
Package nethttp provides MPP middleware for the standard library net/http package.
|
Package nethttp provides MPP middleware for the standard library net/http package. |
|
Package mcp provides MCP (Model Context Protocol) integration for MPP session payments.
|
Package mcp provides MCP (Model Context Protocol) integration for MPP session payments. |
|
methods
|
|
|
mock
Package mock provides a mock payment method for development and testing.
|
Package mock provides a mock payment method for development and testing. |
|
stripe
Package stripe implements the MPP "stripe" payment method using Stripe Short-Lived Payment Tokens (SPT) and the Stripe Payment Intents API.
|
Package stripe implements the MPP "stripe" payment method using Stripe Short-Lived Payment Tokens (SPT) and the Stripe Payment Intents API. |
|
tempo
Package tempo implements the MPP "tempo" payment method using EVM-compatible on-chain transactions via the Tempo network.
|
Package tempo implements the MPP "tempo" payment method using EVM-compatible on-chain transactions via the Tempo network. |
|
Package mperr defines RFC 9457 problem-details types and kinds for MPP failures.
|
Package mperr defines RFC 9457 problem-details types and kinds for MPP failures. |
|
Package protocol contains the core MPP wire types, header parsing/formatting, and intent definitions.
|
Package protocol contains the core MPP wire types, header parsing/formatting, and intent definitions. |
|
intents
Package intents provides MPP payment intent request types.
|
Package intents provides MPP payment intent request types. |
|
Package server implements the MPP server-side payment challenge and credential verification logic.
|
Package server implements the MPP server-side payment challenge and credential verification logic. |
|
Package sse provides Server-Sent Events utilities for MPP session payments.
|
Package sse provides Server-Sent Events utilities for MPP session payments. |
|
Package store provides challenge-tracking storage for replay protection.
|
Package store provides challenge-tracking storage for replay protection. |