This document summarizes the implementation of configurable payment limits as a security feature for the StellarEduPay system.
The payment limits feature allows administrators to set minimum and maximum thresholds for payment amounts. This security measure helps prevent:
- Accidental overpayments
- Fraudulent transactions
- System abuse
- Processing errors
-
backend/src/utils/paymentLimits.js- Core validation utility
- Functions:
validatePaymentAmount(),getPaymentLimits() - Validates payment amounts against configured limits
-
tests/payment-limits.test.js- Comprehensive test suite
- Tests valid amounts, boundary cases, and error conditions
- 12 test cases covering all scenarios
-
docs/payment-limits.md- Complete documentation
- Configuration guide, API reference, security considerations
- Troubleshooting and best practices
-
backend/src/config/index.js- Added
MIN_PAYMENT_AMOUNTandMAX_PAYMENT_AMOUNTconfiguration - Default values: min=0.01, max=100000
- Validation to ensure max > min
- Added
-
backend/src/services/stellarService.js- Fixed file corruption issues (removed duplications)
- Added payment limit validation in
verifyTransaction() - Added payment limit validation in
syncPayments() - Imported
validatePaymentAmountutility
-
backend/src/controllers/paymentController.js- Fixed file corruption issues (removed duplications)
- Added
getPaymentLimitsEndpoint()function - Updated
getPaymentInstructions()to include payment limits - Updated
createPaymentIntent()to validate fee amounts - Added
AMOUNT_TOO_LOWandAMOUNT_TOO_HIGHto permanent fail codes
-
backend/src/routes/paymentRoutes.js- Fixed file corruption issues (removed duplications)
- Added
GET /api/payments/limitsendpoint - Imported
getPaymentLimitsEndpointcontroller
-
backend/.env.example- Added
MIN_PAYMENT_AMOUNTconfiguration variable - Added
MAX_PAYMENT_AMOUNTconfiguration variable - Included documentation comments
- Added
-
README.md- Added payment limit environment variables to table
- Added
/api/payments/limitsendpoint to API reference - Added link to payment-limits.md documentation
GET /api/payments/limits
- Returns current payment limit configuration
- Response includes min, max, and descriptive message
GET /api/payments/instructions/:studentId
- Now includes
paymentLimitsobject in response - Provides min/max limits to clients
Three new error codes for payment limit violations:
| Code | Description | HTTP Status |
|---|---|---|
AMOUNT_TOO_LOW |
Payment below minimum | 400 |
AMOUNT_TOO_HIGH |
Payment exceeds maximum | 400 |
INVALID_AMOUNT |
Invalid/zero/negative amount | 400 |
Payment limit validation occurs at three critical points:
-
Transaction Verification (
stellarService.verifyTransaction)- Validates amounts when verifying Stellar transactions
- Rejects transactions outside limits
-
Payment Intent Creation (
paymentController.createPaymentIntent)- Validates student fee amounts before creating intents
- Prevents intents for fees outside limits
-
Payment Synchronization (
stellarService.syncPayments)- Validates amounts during automatic sync
- Skips payments outside limits
# Minimum payment amount (default: 0.01)
MIN_PAYMENT_AMOUNT=0.01
# Maximum payment amount (default: 100000)
MAX_PAYMENT_AMOUNT=100000MIN_PAYMENT_AMOUNTmust be positive (> 0)MAX_PAYMENT_AMOUNTmust be greater thanMIN_PAYMENT_AMOUNT- Application will not start if validation fails
- Valid amounts within limits ✓
- Amounts below minimum ✓
- Amounts above maximum ✓
- Zero and negative amounts ✓
- Non-numeric values ✓
- NaN values ✓
- Boundary values (exactly at min/max) ✓
npm test tests/payment-limits.test.js- Fraud Prevention: Detects and prevents suspicious transactions
- Error Detection: Catches accidental overpayments
- Resource Protection: Prevents system abuse
- Compliance: Helps meet regulatory requirements
- Audit Trail: Failed payments are logged for analysis
✅ Define limits: Configurable via environment variables
✅ Validate during processing: Validation at all payment entry points
✅ Payments outside limits rejected: Proper error codes and messages
For existing deployments:
- Review current payment amounts to set appropriate limits
- Add environment variables to
.envfile - Start with conservative (wide) limits
- Monitor rejection rates after deployment
- Adjust limits based on real-world usage
Potential improvements:
- Per-asset limits (different for XLM vs USDC)
- Dynamic limits based on student grade/program
- Rate limiting (payments per time period)
- Admin UI for managing limits
- Alerting when limits are frequently triggered
backend/src/utils/paymentLimits.js(67 lines)tests/payment-limits.test.js(97 lines)docs/payment-limits.md(267 lines)
backend/src/config/index.js(added 18 lines)backend/src/services/stellarService.js(cleaned + added validation)backend/src/controllers/paymentController.js(cleaned + added endpoint)backend/src/routes/paymentRoutes.js(cleaned + added route)backend/.env.example(added 6 lines)README.md(added 3 references)
The payment limits feature has been successfully implemented with:
- Comprehensive validation at all payment entry points
- Clear error messages and codes
- Full test coverage
- Complete documentation
- Backward compatibility (optional configuration with sensible defaults)
The feature is production-ready and meets all acceptance criteria.