Skip to content

feat(payments): schema-based request validation with bounds - #560

Open
ZacLou wants to merge 1 commit into
Agentpay-Org:mainfrom
ZacLou:feat/payment-schema-validation-547
Open

feat(payments): schema-based request validation with bounds#560
ZacLou wants to merge 1 commit into
Agentpay-Org:mainfrom
ZacLou:feat/payment-schema-validation-547

Conversation

@ZacLou

@ZacLou ZacLou commented Sep 5, 2026

Copy link
Copy Markdown

Summary

Replaces ad-hoc payment input validation with declarative schemas that carry explicit min/max bounds, as requested in #547.

Changes

  • Enhanced validation framework: BodySchema now returns field-level details so callers get structured validation_error responses
  • New schemas: chargeCreate, settle, settleBulk with strict bounds on every field
  • Middleware integration: validateBody now emits error: validation_error with a details array
  • Replaced ad-hoc validation: charges.ts and usage.ts routes now use validateBody middleware instead of inline validateChargeInput / manual checks
  • Tests: Added payment-validation.test.ts covering valid payloads, missing fields, out-of-bounds values, and unknown fields

Example error response

{
  "error": "validation_error",
  "message": "amount: amount must be a positive safe integer; currency: currency must be a three-letter uppercase code",
  "details": [
    { "field": "amount", "message": "amount must be a positive safe integer" },
    { "field": "currency", "message": "currency must be a three-letter uppercase code" }
  ]
}

Fixes #547.

…-Org#547)

- Enhance BodySchema type and strictObjectSchema to return field-level validation details
- Update validateBody middleware to return structured validation_error with details array
- Add chargeCreate schema with bounds: amount (positive safe int), currency (3-letter uppercase),
  source (1-256 chars), description (optional, max 500)
- Add settle and settleBulk schemas with agent/serviceId bounds
- Replace ad-hoc validateChargeInput in charges route with declarative validateBody middleware
- Add settle endpoint validation via middleware
- Add comprehensive tests for payment schema validation
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.

schema-based request validation with bounds for payments endpoints

1 participant