feat(payments): schema-based request validation with bounds - #560
Open
ZacLou wants to merge 1 commit into
Open
Conversation
…-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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces ad-hoc payment input validation with declarative schemas that carry explicit min/max bounds, as requested in #547.
Changes
BodySchemanow returns field-leveldetailsso callers get structuredvalidation_errorresponseschargeCreate,settle,settleBulkwith strict bounds on every fieldvalidateBodynow emitserror: validation_errorwith adetailsarraycharges.tsandusage.tsroutes now usevalidateBodymiddleware instead of inlinevalidateChargeInput/ manual checkspayment-validation.test.tscovering valid payloads, missing fields, out-of-bounds values, and unknown fieldsExample 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.