A robust Dart Frog backend implementation for Paystack payment integration, providing a comprehensive set of APIs for payment processing, subscriptions and more.
- Features
- Getting Started
- API Documentation
- Engineering Documentation
- Contributing
- Testing
- Deployment
- Security
- License
- 💳 Complete payment processing
- 📅 Subscription management
- 👤 Customer management
- 🔄 Transaction handling
- 📊 Payment plans
- 🏦 Bank integration
- 🔒 Secure API endpoints
- ⚡ Built with Dart Frog
- 🔐 Environment-based configuration
- 🧩 Modular architecture
- 📝 Comprehensive logging
- ✅ Input validation
- 🔄 Error handling
- 📊 Response formatting
- Dart SDK: ">=3.0.0 <4.0.0"
- dart_frog_cli
- Paystack account and API keys
- Git (for version control)
- Install dart_frog_cli globally:
dart pub global activate dart_frog_cli
- Clone the repository:
git clone https://github.com/yourusername/mind-paystack-backend.git
cd mind-paystack-backend
- Set up environment files:
# Create .env and .env.example files
touch .env
touch .env.example
# Create env.dart for environment configuration
touch lib/env.dart
- Add the following content to
lib/env.dart
:
import 'package:envied/envied.dart';
part 'env.g.dart';
@Envied(path: '.env')
abstract class Env {
@EnviedField(varName: 'PAYSTACK_SECRET_KEY')
static const paystackSecretKey = _Env.paystackSecretKey;
}
- Create
.env
file with your configuration:
# Paystack Configuration
PAYSTACK_SECRET_KEY=your_secret_key_here
# Server Configuration (optional)
PORT=8080
ENVIRONMENT=development
# Rate Limiting (optional)
RATE_LIMIT_WINDOW=15m
RATE_LIMIT_MAX_REQUESTS=100
# Logging Configuration (optional)
LOG_LEVEL=info
LOG_FORMAT=json
# CORS Configuration (optional)
ALLOWED_ORIGINS=http://localhost:3000,https://yourdomain.com
- Add to
.gitignore
:
echo ".env" >> .gitignore
echo "*.g.dart" >> .gitignore
- Install dependencies:
dart pub get
- Generate environment configuration:
dart run build_runner build
- Run the development server:
dart_frog dev
- Verify the installation:
# Test transaction initialization
curl -X POST http://localhost:8080/api/transactions \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"amount": 5000,
"currency": "NGN"
}'
-
Environment Variables Not Loading
# Check if .env file exists ls -la .env # Verify .env content cat .env # Regenerate environment files dart run build_runner clean dart run build_runner build
-
Port Already in Use
# Kill process using port 8080 lsof -i :8080 kill -9 <PID> # Or run on different port PORT=8081 dart_frog dev
-
Permission Issues
# Fix directory permissions chmod -R 755 . # Fix file permissions chmod 644 .env
POST /api/transactions
Content-Type: application/json
{
"email": "[email protected]",
"amount": 5000,
"currency": "NGN",
"reference": "unique_reference",
"metadata": {
"custom_field": "custom_value"
}
}
GET /api/transactions/{reference}/verify
GET /api/transactions?page=1&perPage=20
POST /api/subscriptions
Content-Type: application/json
{
"customer": "CUS_xyz",
"plan": "PLN_xyz",
"start_date": "2024-12-01"
}
GET /api/subscriptions?customer=CUS_xyz&perPage=20
POST /api/subscriptions/{code}/enable
POST /api/subscriptions/{code}/disable
Content-Type: application/json
{
"token": "subscription_token"
}
mind-paystack-backend/
├── lib/
│ ├── paystack_service.dart
│ └── env.dart
├── routes/
│ ├── _middleware.dart
│ └── api/
│ ├── transactions/
│ ├── subscriptions/
│ ├── plans/
│ ├── customers/
│ ├── banks/
├── test/
├── .env
└── pubspec.yaml
The PaystackTransaction
class handles all Paystack API interactions:
- Transaction management
- Subscription handling
- Customer management
- Payment plans
- Authentication middleware
- Error handling middleware
- Logging middleware
- CORS middleware
class PaystackException implements Exception {
final String message;
final String details;
PaystackException(this.message, this.details);
}
{
"status": "success/error",
"message": "Operation successful/Error message",
"data": {}
}
- Fork the repository
- Create a feature branch
- Write tests
- Implement changes
- Submit PR
- Follow Dart style guide
- Use meaningful variable names
- Add comments for complex logic
- Format code using
dart format
feat: Add new feature
fix: Fix bug
docs: Update documentation
test: Add tests
refactor: Refactor code
- Update documentation
- Add tests
- Update CHANGELOG
- Request review
# Run all tests
dart test
# Run specific test
dart test test/path/to/test.dart
void main() {
group('PaystackTransaction', () {
test('should initialize transaction', () async {
// Test code
});
});
}
dart_frog build
docker build -t mind-paystack-backend .
docker run -p 8080:8080 mind-paystack-backend
- Use production Paystack keys
- Configure proper security headers
- Set up monitoring
- Configure logging
- Never commit API keys
- Validate all inputs
- Use HTTPS
- Implement rate limiting
- Log security events
- Regular dependency updates
- Authentication required
- Input validation
- Rate limiting
- CORS configuration
- Secure headers
This project is licensed under the MIT License - see the LICENSE file for details.
For support, email [email protected] or create an issue in the repository.
Made with ❤️ by Your Dartmind