Documentation
¶
Overview ¶
Package fiberadapter provides Fiber middleware for MPP-protected routes.
Index ¶
- func ChargeMiddleware(m *server.Mpp, params server.ChargeParams) fiberfw.Handler
- func ComposeMiddleware(offers ...server.Offer) fiberfw.Handler
- func Credential(c *fiberfw.Ctx) *mpp.Credential
- func Receipt(c *fiberfw.Ctx) *mpp.Receipt
- func WritePaymentResponse(c *fiberfw.Ctx, err error, challenges ...*mpp.Challenge)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChargeMiddleware ¶
ChargeMiddleware protects a Fiber route with the server charge flow. It runs server.Mpp.ChargeRequest with the route's scope unless params.MppxScope is set, writes the payment response when payment is required or rejected, and on success stores the verified Credential and Receipt in the Fiber locals and the user context.
func ComposeMiddleware ¶ added in v0.6.0
ComposeMiddleware protects a Fiber route with several payment offers, like server.ComposeMiddleware: an unpaid request gets every offer, and a Credential is verified against the offer it echoes. Offers without their own Params.MppxScope bind the route's scope. ComposeMiddleware panics when server.ComposeMiddleware would: offers is empty, an Mpp is nil, realms differ, or an offer cannot be built.
func Credential ¶
func Credential(c *fiberfw.Ctx) *mpp.Credential
Credential returns the verified credential stored on the Fiber context.
func WritePaymentResponse ¶ added in v0.5.1
WritePaymentResponse writes the payment response for err and challenges, each challenge as one WWW-Authenticate field value, in order, with its own Realm:
- err nil: the initial 402 Payment Required offering challenges, with a payment-required problem body. Without challenges it is a 500 internal payment error.
- err non-nil: err as RFC 9457 application/problem+json, a non-PaymentError as a 500 internal payment error. Challenges are retry offers, omitted for mpp.ErrPaymentOutcomeUnknown.
This is the Fiber equivalent of server.WritePaymentResponse, except that an initial 402 carries a problem body. Fiber is built on fasthttp and cannot use http.ResponseWriter directly.
Types ¶
This section is empty.