Skip to content

feat: add decorator/HOF API for server-side payment configuration#4

Merged
Hades-Ye merged 1 commit intodev/v2from
feat/decorator-api
Mar 10, 2026
Merged

feat: add decorator/HOF API for server-side payment configuration#4
Hades-Ye merged 1 commit intodev/v2from
feat/decorator-api

Conversation

@Hades-Ye
Copy link
Copy Markdown
Contributor

@Hades-Ye Hades-Ye commented Mar 10, 2026

Summary

  • TypeScript: Add withPayment() HOF for Express, Hono, and Next.js — wraps PaymentOption | PaymentOption[] into framework middleware with a single function call
  • Python: Add @x402_app.pay() decorator for Flask and FastAPI — attaches payment config to route handlers, init_app() scans decorated routes and builds middleware automatically
  • Bug fix: Forward assets field from PaymentOption through to ResourceConfig in buildPaymentRequirementsFromOptions (both TS and Python)

Changes

Area Files Description
Bug fix x402ResourceServer.ts, x402_http_server.py Pass assets to ResourceConfig
TS HOF express/withPayment.ts, hono/withPayment.ts, next/withPayment.ts withPayment() for each framework
Python decorators decorators/flask.py, decorators/fastapi.py x402_app class with @pay() decorator
Tests 7 new test files, 1 modified Unit tests for all new functionality

Test plan

  • TypeScript: pnpm lint / pnpm build / pnpm test — all green (40/40 tasks)
  • Python: pytest — 730 passed, ruff check / ruff format --check clean
  • CI pipeline passes on this PR

Add simplified decorator and higher-order function APIs for configuring
x402 payment requirements on server routes, reducing boilerplate while
preserving full PaymentOption flexibility.

TypeScript: withPayment() HOF for Express, Hono, and Next.js that wraps
a PaymentOption into a wildcard RouteConfig and returns framework middleware.

Python: @x402_app.pay() decorator for Flask and FastAPI that attaches
payment config to route handlers, with init_app() scanning decorated
routes to build the middleware automatically.

Also fixes a bug where the assets field in PaymentOption was not passed
through to ResourceConfig in buildPaymentRequirementsFromOptions.
@Hades-Ye Hades-Ye merged commit 0d91511 into dev/v2 Mar 10, 2026
7 checks passed
@Hades-Ye Hades-Ye deleted the feat/decorator-api branch March 10, 2026 08:36
@mustafacryptoafnde-lab
Copy link
Copy Markdown

49 177 2420773

Copy link
Copy Markdown

@mustafacryptoafnde-lab mustafacryptoafnde-lab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#m saleh

using Python decorators, as an alternative to the routes dict approach.
"""

from ..types import PaymentOption, RouteConfig
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#mustafacryptoAfnde

@github-actions github-actions Bot mentioned this pull request Apr 13, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants