A full-stack payment processing solution using Yoco API with Node.js backend and React TypeScript frontend.
This project provides a complete payment integration solution using Yoco's payment gateway. It consists of:
- Backend: Node.js Express server with Yoco API integration
- Frontend: React TypeScript application with Vite build tool
Yoco-API Backend + Frontend/
├── Backend/ # Node.js Express server
│ ├── routes/ # API routes
│ ├── server.js # Main server file
│ ├── package.json # Backend dependencies
│ └── README.md # Backend documentation
├── Frontend/ # React TypeScript app
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── services/ # API and Yoco integrations
│ │ └── ...
│ ├── package.json # Frontend dependencies
│ └── README.md # Frontend documentation
└── README.md # This file
- ✅ Payment charge creation
- ✅ Charge status retrieval
- ✅ Refund processing
- ✅ Webhook handling
- ✅ CORS enabled for frontend
- ✅ Security middleware
- ✅ Error handling
- ✅ Environment-based configuration
- ✅ Secure payment form
- ✅ Payment status checking
- ✅ Yoco SDK integration
- ✅ Backend health monitoring
- ✅ Responsive design
- ✅ Real-time feedback
- ✅ Error handling
- Node.js 18+ installed
- Yoco developer account
- API keys from Yoco dashboard
cd Backend
npm install
cp .env.example .env
# Edit .env and add your Yoco secret key
npm run devcd Frontend
npm install
cp .env.example .env
# Edit .env and add your Yoco public key
npm run dev- Sign up at Yoco Developer Portal
- Navigate to your dashboard
- Get your API keys:
- Secret Key (for backend):
sk_test_...orsk_live_... - Public Key (for frontend):
pk_test_...orpk_live_...
- Secret Key (for backend):
Backend (.env):
YOCO_SECRET_KEY=sk_test_your_secret_key_here
PORT=5000
FRONTEND_URL=http://localhost:5173Frontend (.env):
VITE_YOCO_PUBLIC_KEY=pk_test_your_public_key_here
VITE_API_URL=http://localhost:5000-
Start the backend (in Backend directory):
npm run dev
Server runs on:
http://localhost:5000 -
Start the frontend (in Frontend directory):
npm run dev
App runs on:
http://localhost:5173
Use these test cards for development:
- Successful Payment:
4000000000000002 - Declined Payment:
4000000000000010 - Insufficient Funds:
4000000000000028
- Open the frontend application
- Enter a test amount (minimum R1.00)
- Add a description
- Click "Pay Now"
- Use test card details in Yoco's popup
- Verify payment status
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/health |
Health check |
| POST | /api/payment/charge |
Create payment charge |
| GET | /api/payment/charge/:id |
Get charge details |
| POST | /api/payment/refund |
Process refund |
| POST | /api/payment/webhook |
Webhook for notifications |
- Secret keys are kept server-side only
- Public keys are used for frontend token generation
- CORS configured for specific origins
- Webhook signature validation (implement as needed)
- Input validation and sanitization
- Error messages don't expose sensitive data
- Set environment variables on your server
- Configure CORS for your frontend domain
- Set up webhook URL in Yoco dashboard
- Use PM2 or similar for process management
- Build the application:
npm run build - Deploy the
distfolder to your hosting service - Configure environment variables for production
- Uses nodemon for auto-restart
- Morgan for request logging
- Helmet for security headers
- CORS for cross-origin requests
- Hot Module Replacement (HMR) with Vite
- TypeScript for type safety
- Tailwind CSS for styling
- Axios for HTTP requests
- Backend README - Detailed backend documentation
- Frontend README - Detailed frontend documentation
- Yoco API Docs - Official Yoco documentation
-
"Yoco not configured" error
- Check your environment variables
- Ensure you're using the correct key format
-
CORS errors
- Verify backend CORS configuration
- Check frontend API URL in environment
-
Payment failures
- Use valid test cards
- Check amount is >= R1.00
- Verify API keys are correct
-
Backend connection issues
- Ensure backend is running on port 5000
- Check network connectivity
- Verify environment variables
This project is for educational/development purposes. Please check Yoco's terms of service for production use.
- Fork the project
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
Happy coding! 💻✨