🚨 Error: POST http://localhost:5000/api/donations/initialize 500 (Internal Server Error)
This error occurs when the donation initialization fails. Here's how to fix it:
Create or update your backend/.env file:
# Server Configuration
PORT=5000
NODE_ENV=development
# Database
MONGODB_URI=mongodb://localhost:27017/alembank_church
# Chapa Payment Gateway (REQUIRED)
CHAPA_SECRET_KEY=your-chapa-secret-key-here
# Frontend URL (for callbacks)
FRONTEND_URL=http://localhost:3000
# Email Configuration (optional for now)
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password
EMAIL_FROM=noreply@alembankchurch.orgVisit this URL to check if everything is working:
http://localhost:5000/api/donations/test
This will show you:
- ✅ Database connection status
- ✅ Chapa API configuration
- ✅ Environment variables status
- Sign up at Chapa.co
- Go to your dashboard
- Copy your Secret Key
- Add it to your .env file
Error: CHAPA_SECRET_KEY is not configured
Solution: Add your Chapa secret key to the .env file
Error: Database connection error
Solution:
- Make sure MongoDB is running
- Check your
MONGODB_URIin.env - Run:
mongodto start MongoDB
Error: Invalid Chapa API key
Solution:
- Check your Chapa dashboard for the correct key
- Make sure you're using the Secret Key, not Public Key
- Verify the key is active in your Chapa account
Error: Unable to connect to Chapa payment service
Solution:
- Check your internet connection
- Try again in a few minutes
- Contact Chapa support if the issue persists
To see detailed error logs, check your backend console. The improved error handling will show:
🔍 Initializing donation: { firstName: 'John', lastName: 'Doe', ... }
✅ Donation record saved to database
🔍 Making Chapa API request to: https://api.chapa.co/v1/transaction/initialize
✅ Chapa API response status: 200
✅ Chapa API response data: { status: 'success', ... }
-
Start your backend:
cd backend npm run dev -
Start your frontend:
cd frontend npm run dev -
Test the donation form:
- Go to http://localhost:3000/donate
- Fill out the form
- Submit and check the console for errors
You can test the API directly using curl:
curl -X POST http://localhost:5000/api/donations/initialize \
-H "Content-Type: application/json" \
-d '{
"firstName": "Test",
"lastName": "User",
"email": "test@example.com",
"phone": "1234567890",
"amount": 100,
"purpose": "general",
"isAnonymous": false
}'Make sure you have:
- ✅ MongoDB running
- ✅ Backend server running on port 5000
- ✅ Frontend server running on port 3000
- ✅ Chapa API key in
.env - ✅ All required environment variables set
For production, you'll need:
- Real Chapa API key (not test key)
- Proper domain URLs in environment variables
- SSL certificates for secure payments
- Email service configured for notifications
- Check the backend console for detailed error messages
- Visit the test endpoint to see system status
- Verify your Chapa account is active
- Contact support if the issue persists
If you're still having issues:
- Check the backend console logs
- Test the
/api/donations/testendpoint - Verify all environment variables are set
- Make sure MongoDB is running
- Confirm your Chapa API key is valid