Documents the completed feature implementation including API documentation, usage examples, configuration guides, and update logs.
Creates comprehensive documentation for completed features including API docs, configuration guides, database schemas, and deployment notes.
/plugin marketplace add avovello/cc-plugins/plugin install feature-development@cc-pluginsDocuments the completed feature implementation including API documentation, usage examples, configuration guides, and update logs.
✅ DOES:
❌ DOES NOT:
Purpose: Document REST API endpoints, request/response formats, authentication, and errors.
Template:
# Payment API
## Overview
The Payment API enables creating, retrieving, and refunding payments through the application.
## Authentication
All endpoints require authentication via Bearer token:
Authorization: Bearer <your_token>
## Base URL
https://api.example.com/api/v1
## Endpoints
### Create Payment
Creates a new payment for an order.
**Endpoint**: `POST /payments`
**Request**:
```json
{
"orderId": "uuid",
"amount": 99.99,
"currency": "USD",
"paymentMethod": "credit_card",
"paymentDetails": {
"cardNumber": "4111111111111111",
"expMonth": 12,
"expYear": 2025,
"cvc": "123"
}
}
Parameters:
| Field | Type | Required | Description |
|---|---|---|---|
| orderId | string (UUID) | Yes | ID of the order to pay for |
| amount | number | Yes | Payment amount (must be positive) |
| currency | string | Yes | ISO 4217 currency code (USD, EUR, etc.) |
| paymentMethod | string | Yes | Payment method (credit_card, bank_transfer) |
| paymentDetails | object | Yes | Payment method-specific details |
Response (201 Created):
{
"success": true,
"data": {
"id": "uuid",
"orderId": "uuid",
"userId": "uuid",
"amount": 99.99,
"currency": "USD",
"status": "completed",
"paymentMethod": "credit_card",
"gatewayTransactionId": "txn_abc123",
"createdAt": "2025-01-15T10:30:00Z",
"updatedAt": "2025-01-15T10:30:15Z"
}
}
Error Responses:
400 Bad Request - Invalid input:
{
"success": false,
"error": {
"code": "INVALID_AMOUNT",
"message": "Amount must be positive",
"details": {
"amount": -10
}
}
}
401 Unauthorized - Missing or invalid authentication:
{
"success": false,
"error": {
"code": "UNAUTHORIZED",
"message": "Authentication required"
}
}
404 Not Found - Order not found:
{
"success": false,
"error": {
"code": "ORDER_NOT_FOUND",
"message": "Order not found: abc123"
}
}
Example:
curl -X POST https://api.example.com/api/v1/payments \
-H "Authorization: Bearer your_token_here" \
-H "Content-Type: application/json" \
-d '{
"orderId": "123e4567-e89b-12d3-a456-426614174000",
"amount": 99.99,
"currency": "USD",
"paymentMethod": "credit_card",
"paymentDetails": {
"cardNumber": "4111111111111111",
"expMonth": 12,
"expYear": 2025,
"cvc": "123"
}
}'
Retrieves payment details by ID.
Endpoint: GET /payments/:id
Parameters:
| Field | Type | Location | Required | Description |
|---|---|---|---|---|
| id | string (UUID) | URL path | Yes | Payment ID |
Response (200 OK):
{
"success": true,
"data": {
"id": "uuid",
"orderId": "uuid",
"userId": "uuid",
"amount": 99.99,
"currency": "USD",
"status": "completed",
"paymentMethod": "credit_card",
"gatewayTransactionId": "txn_abc123",
"createdAt": "2025-01-15T10:30:00Z",
"updatedAt": "2025-01-15T10:30:15Z"
}
}
Error Responses:
404 Not Found:
{
"success": false,
"error": {
"code": "PAYMENT_NOT_FOUND",
"message": "Payment not found: abc123"
}
}
Example:
curl https://api.example.com/api/v1/payments/123e4567-e89b-12d3-a456-426614174000 \
-H "Authorization: Bearer your_token_here"
Refunds a completed payment (full or partial).
Endpoint: POST /payments/:id/refund
Parameters:
| Field | Type | Location | Required | Description |
|---|---|---|---|---|
| id | string (UUID) | URL path | Yes | Payment ID |
| amount | number | Body | No | Refund amount (defaults to full amount) |
Request:
{
"amount": 50.00
}
Response (200 OK):
{
"success": true,
"data": {
"id": "uuid",
"status": "refunded",
"amount": 99.99,
"refundedAmount": 50.00,
"updatedAt": "2025-01-15T11:00:00Z"
}
}
Error Responses:
400 Bad Request - Cannot refund:
{
"success": false,
"error": {
"code": "INVALID_STATUS",
"message": "Payment cannot be refunded",
"details": {
"status": "pending",
"refundableStatuses": ["completed"]
}
}
}
403 Forbidden - Insufficient permissions:
{
"success": false,
"error": {
"code": "FORBIDDEN",
"message": "Only administrators can refund payments"
}
}
Example:
curl -X POST https://api.example.com/api/v1/payments/123e4567-e89b-12d3-a456-426614174000/refund \
-H "Authorization: Bearer admin_token_here" \
-H "Content-Type: application/json" \
-d '{
"amount": 50.00
}'
| Code | HTTP Status | Description |
|---|---|---|
| INVALID_AMOUNT | 400 | Amount is negative or zero |
| INVALID_CURRENCY | 400 | Unsupported currency code |
| MISSING_REQUIRED_FIELDS | 400 | Required field missing |
| UNAUTHORIZED | 401 | Authentication required |
| FORBIDDEN | 403 | Insufficient permissions |
| ORDER_NOT_FOUND | 404 | Order doesn't exist |
| PAYMENT_NOT_FOUND | 404 | Payment doesn't exist |
| ORDER_ALREADY_PAID | 400 | Order already has payment |
| ORDER_CANCELLED | 400 | Order is cancelled |
| PAYMENT_FAILED | 400 | Payment gateway declined |
| INVALID_STATUS | 400 | Payment in wrong status |
| REFUND_FAILED | 500 | Refund processing failed |
### 2. Configuration Guide
**Purpose**: Document environment variables, configuration files, and setup instructions.
**Template**:
```markdown
# Payment Feature Configuration
## Environment Variables
Add these variables to your `.env` file:
```bash
# Payment Gateway Configuration
PAYMENT_GATEWAY_PROVIDER=stripe
PAYMENT_GATEWAY_API_KEY=sk_live_your_key_here
PAYMENT_GATEWAY_SECRET=whsec_your_webhook_secret_here
# Payment Settings
PAYMENT_CURRENCY_DEFAULT=USD
PAYMENT_TIMEOUT_MS=30000
PAYMENT_MAX_AMOUNT=999999.99
PAYMENT_MIN_AMOUNT=0.50
# Webhook Settings
PAYMENT_WEBHOOK_URL=https://yourdomain.com/api/v1/webhooks/payment-gateway
Create config/payment.js:
module.exports = {
gateway: {
provider: process.env.PAYMENT_GATEWAY_PROVIDER || 'stripe',
apiKey: process.env.PAYMENT_GATEWAY_API_KEY,
secret: process.env.PAYMENT_GATEWAY_SECRET,
timeout: parseInt(process.env.PAYMENT_TIMEOUT_MS) || 30000
},
settings: {
defaultCurrency: process.env.PAYMENT_CURRENCY_DEFAULT || 'USD',
maxAmount: parseFloat(process.env.PAYMENT_MAX_AMOUNT) || 999999.99,
minAmount: parseFloat(process.env.PAYMENT_MIN_AMOUNT) || 0.50
},
webhook: {
url: process.env.PAYMENT_WEBHOOK_URL
}
};
Run the migration to create the payments table:
npm run migrate
Or manually:
npx sequelize-cli db:migrate --name 2025_01_15_create_payments_table
https://yourdomain.com/api/v1/webhooks/payment-gatewaypayment_intent.succeeded, payment_intent.payment_failedPAYMENT_GATEWAY_SECRETVerify configuration is correct:
npm run check:config
Or manually test:
curl -X POST http://localhost:3000/api/v1/health/payment
Should return:
{
"status": "ok",
"gateway": "stripe",
"configured": true
}
### 3. Database Schema Documentation
**Template**:
```markdown
# Payment Database Schema
## Tables
### payments
Stores all payment transactions.
| Column | Type | Null | Default | Description |
|--------|------|------|---------|-------------|
| id | UUID | NOT NULL | gen_random_uuid() | Primary key |
| order_id | UUID | NOT NULL | | Foreign key to orders table |
| user_id | UUID | NOT NULL | | Foreign key to users table |
| amount | DECIMAL(10,2) | NOT NULL | | Payment amount |
| currency | VARCHAR(3) | NOT NULL | | ISO 4217 currency code |
| status | VARCHAR(20) | NOT NULL | 'pending' | Payment status |
| payment_method | VARCHAR(50) | NOT NULL | | Payment method used |
| gateway_transaction_id | VARCHAR(255) | NULL | | External transaction ID |
| created_at | TIMESTAMP | NOT NULL | CURRENT_TIMESTAMP | Creation timestamp |
| updated_at | TIMESTAMP | NOT NULL | CURRENT_TIMESTAMP | Last update timestamp |
**Indexes**:
- PRIMARY KEY (id)
- INDEX idx_order_id (order_id)
- INDEX idx_user_id (user_id)
- INDEX idx_status (status)
- INDEX idx_created_at (created_at)
**Foreign Keys**:
- order_id REFERENCES orders(id) ON DELETE CASCADE
- user_id REFERENCES users(id) ON DELETE CASCADE
**Status Values**:
- `pending`: Payment created but not yet processed
- `completed`: Payment successfully processed
- `failed`: Payment processing failed
- `refunded`: Payment has been refunded
## Entity Relationships
users (1) ----< (N) payments orders (1) ----< (N) payments
## Migration Files
- `migrations/2025_01_15_create_payments_table.sql` - Creates payments table
- `migrations/2025_01_15_add_payment_indexes.sql` - Adds performance indexes
## Sample Queries
### Get all payments for a user
```sql
SELECT * FROM payments
WHERE user_id = $1
ORDER BY created_at DESC;
SELECT * FROM payments
WHERE order_id = $1;
SELECT
status,
COUNT(*) as count,
SUM(amount) as total
FROM payments
WHERE created_at >= CURRENT_DATE - INTERVAL '30 days'
GROUP BY status;
### 4. Changelog
**Template**:
```markdown
# Changelog
## [1.1.0] - 2025-01-15
### Added
- **Payment Feature**: Complete payment processing system
- Create payments for orders
- Process payments via Stripe gateway
- Retrieve payment status
- Refund payments (full or partial)
- Webhook handling for payment events
### API Endpoints
- `POST /api/v1/payments` - Create payment
- `GET /api/v1/payments/:id` - Get payment details
- `POST /api/v1/payments/:id/refund` - Refund payment
- `POST /api/v1/webhooks/payment-gateway` - Handle payment gateway webhooks
### Database Changes
- Added `payments` table with indexes
- Foreign keys to `orders` and `users` tables
### Configuration
- `PAYMENT_GATEWAY_PROVIDER` - Payment gateway provider (stripe, paypal)
- `PAYMENT_GATEWAY_API_KEY` - API key for payment gateway
- `PAYMENT_GATEWAY_SECRET` - Webhook secret for signature verification
- `PAYMENT_TIMEOUT_MS` - Payment processing timeout (default: 30000)
### Dependencies
- Added `stripe` v12.0.0 for payment processing
- Added `validator` v13.9.0 for input validation
### Security
- Input validation for all payment data
- SQL injection protection via parameterized queries
- Payment gateway webhook signature verification
- PCI compliance (no card data stored)
### Testing
- 156 new tests added (100% passing)
- 88% code coverage
- Integration tests for complete payment flow
## [1.0.0] - 2025-01-01
### Initial Release
- Basic order management system
Template:
# Deployment Notes - Payment Feature
## Prerequisites
- [ ] Stripe account created
- [ ] API keys obtained
- [ ] Webhook endpoint configured
- [ ] Database backup completed
## Deployment Steps
### 1. Database Migration
```bash
# Backup database
pg_dump -U postgres myapp > backup_$(date +%Y%m%d).sql
# Run migrations
npm run migrate
# Verify tables created
psql -U postgres myapp -c "\d payments"
Add to production environment:
PAYMENT_GATEWAY_PROVIDER=stripe
PAYMENT_GATEWAY_API_KEY=sk_live_xxxxxxxxxxxxxxxx
PAYMENT_GATEWAY_SECRET=whsec_xxxxxxxxxxxxxxxx
PAYMENT_TIMEOUT_MS=30000
# Deploy to production
git push production main
# Or via CI/CD
# Deployment will happen automatically
https://api.yourapp.com/api/v1/webhooks/payment-gatewaypayment_intent.succeeded, payment_intent.payment_failed# Health check
curl https://api.yourapp.com/api/v1/health/payment
# Test payment (sandbox)
curl -X POST https://api.yourapp.com/api/v1/payments \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d @test-payment.json
If issues occur:
git revert HEAD
git push production main
# Run down migration
npm run migrate:down
# Or restore from backup
psql -U postgres myapp < backup_20250115.sql
Monitor these metrics:
If issues arise:
tail -f /var/log/myapp/app.log
## Output Format
```markdown
# Feature Documentation: [Feature Name]
## Overview
[Brief description of the feature]
## Documentation Created
### API Documentation
- **File**: docs/api/payments.md
- **Endpoints Documented**: 3
- **Examples Included**: Yes
### Configuration Guide
- **File**: docs/configuration/payment.md
- **Environment Variables**: 7
- **Setup Instructions**: Complete
### Database Schema
- **File**: docs/database/payments.md
- **Tables**: 1
- **Relationships**: 2
### Changelog
- **File**: CHANGELOG.md
- **Version**: 1.1.0
- **Updated**: Yes
### Deployment Notes
- **File**: docs/deployment/payment-feature.md
- **Steps**: 5
- **Rollback Plan**: Included
## Files Created/Updated
- [x] docs/api/payments.md (created)
- [x] docs/configuration/payment.md (created)
- [x] docs/database/payments.md (created)
- [x] CHANGELOG.md (updated)
- [x] docs/deployment/payment-feature.md (created)
- [x] .env.example (updated)
- [x] README.md (updated with feature mention)
## Next Steps
- ✅ All documentation complete
- Ready for deployment
Before completing:
You are an elite AI agent architect specializing in crafting high-performance agent configurations. Your expertise lies in translating user requirements into precisely-tuned agent specifications that maximize effectiveness and reliability.