Add Payments Support
Added
Core package (@uigen-dev/core)
- Payment resource refactor - Transformed payments from component-based to resource-based architecture
PricingResourceGenerator- Auto-generates pricing resource from payment config (11 tests)MonetizationConfiginterface for resource/operation-level payment gatesPricingPageConfiginterface with extensible pricing source strategy (inline, endpoint, component)x-uigen-monetizedannotation for marking resources/operations as requiring payment- Enhanced
PaymentHandlerwithextractPricingPageConfig(),handlePathLevel(),handleOperationLevel() - Updated
ResourceExtractorto integrate monetization flags into resources and operations - Security model: Only frontend-safe fields (
publishableKey) in spec, backend secrets in.env - 123 tests passing in Phase 1 (core infrastructure)
# Document-level payment configuration x-uigen-payments: providers: - provider: stripe publishableKey: ${STRIPE_PUBLISHABLE_KEY} mode: test pricingPage: enabled: true source: inline products: - id: pro name: Professional price: 2900 interval: month # Mark resources as monetized paths: /api/v1/meetings: x-uigen-monetized: true
React package (@uigen-dev/react)
- Pricing infrastructure - Complete pricing and monetization UI components
PricingSourceFactorywith strategy pattern for extensible pricing sources (14 tests)InlinePricingSource,EndpointPricingSource,ComponentPricingSourceimplementationsusePaymentStatushook for checking user subscription status (22 tests)MonetizationHandlercomponent for intercepting 402 responses (10 tests)UpgradePromptcomponent with inline and fullpage modes (17 tests)PricingViewcomponent with auto-generated pricing page (12 tests)/pricingroute auto-generated whenpricingPage.enabled: true(6 tests)- 67 tests passing in Phase 2 (React infrastructure)
Documentation
- Updated
apps/docs/content/payments/overview.mdwith resource-based approach- Explained auto-generated pricing page
- Documented payment gates (resource and operation level)
- Added security model explanation
- Added runtime flow diagram
- Created
apps/docs/content/payments/payment-gates.mdcomprehensive guide- Resource-level and operation-level gates
- Custom messages and redirects
- Backend enforcement examples (FastAPI and Express.js)
- Best practices and advanced patterns
- Testing examples and troubleshooting
Skills
- Updated
SKILLS/configure-payments.mdwith new patterns- Document-level
x-uigen-paymentsconfiguration x-uigen-monetizedannotation examples- Payment gates workflow explanation
- Security best practices (frontend-safe keys only)
- Backend enforcement examples
- Document-level
Annotations
- Added
x-uigen-monetizedto annotation registry- Supports boolean shorthand:
x-uigen-monetized: true - Supports object form with custom message and redirect
- Applies to paths (resource-level) and operations (operation-level)
- 18 total annotations in registry
- Supports boolean shorthand:
Changed
- Payment configuration location - Moved from
infoobject to document root- Now:
x-uigen-paymentsat document level (consistent withx-uigen-auth) - Before:
info['x-uigen-payments']
- Now:
- Security model - Only frontend-safe fields in spec
- Frontend:
publishableKeyonly - Backend:
apiKey,webhookSecret,clientSecretstay in.env
- Frontend:
- Payment enforcement - Backend is source of truth
- Backend enforces limits and returns 402 Payment Required
- Frontend intercepts 402 and shows upgrade prompt
- No frontend-only checks (cannot be bypassed)
Tests
- 190 tests passing across payment resource refactor
- Phase 1 (Core): 123 tests
- Phase 2 (React): 67 tests
- Full integration coverage
Documentation
- Payment Overview - Resource-based approach
- Payment Gates Guide - Comprehensive guide
- Configure Payments Skill - AI-assisted setup