A comprehensive payment processing system built with Node.js, Express, and Stripe Checkout. Supports recurring subscription plans with monthly and annual billing options.
- ✅ Stripe Checkout integration for secure payments
- ✅ Multiple subscription plans (Monthly: $10, Annual: $100)
- ✅ Customer management and email handling
- ✅ Webhook event processing for real-time payment updates
- ✅ Responsive, modern UI with payment flow
- ✅ Customer portal for subscription management
- ✅ Success/cancel page handling
- ✅ Environment-based configuration
- ✅ Health check endpoint
- Backend: Node.js, Express.js
- Payment: Stripe API (Checkout Sessions)
- Frontend: EJS templating, Vanilla JavaScript
- Styling: Custom CSS with modern design
- Testing: Jest (configured)
- Node.js 14+ installed
- Stripe account (test or live)
- Git for version control
-
Clone the repository
git clone https://github.com/TheWorthyOne/Payment_Processor.git cd Payment_Processor -
Install dependencies
npm install
-
Configure environment variables
cp .env.example .env
-
Update
.envfile with your Stripe keys# Test Keys (for development) STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key_here STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key_here STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret_here # Server Configuration NODE_ENV=development PORT=3000
- Sign up for Stripe: stripe.com
- Get API keys from Stripe Dashboard → Developers → API Keys
- Set up webhook endpoint:
- In Stripe Dashboard → Developers → Webhooks
- Add endpoint:
https://your-domain.com/webhook - Select events:
checkout.session.completed,invoice.payment_succeeded,invoice.payment_failed,customer.subscription.deleted - Copy the webhook signing secret to your
.envfile
npm run devThe server will start on http://localhost:3000
npm startFor local testing without hitting Stripe's servers:
# Install stripe-mock (Go-based tool)
# Follow instructions at: https://github.com/stripe/stripe-mock
# Start stripe-mock on default ports (HTTP: 12111, HTTPS: 12112)
npm run serveThen update your environment to use the mock server:
STRIPE_SECRET_KEY=sk_test_123
STRIPE_MOCK_URL=http://localhost:12111Payment_Processor/
├── server.js # Main Express server
├── package.json # Dependencies and scripts
├── .env.example # Environment template
├── .env # Environment configuration (git-ignored)
├── README.md # This file
├── views/ # EJS templates
│ ├── index.ejs # Main payment page
│ ├── success.ejs # Payment success page
│ └── cancel.ejs # Payment cancel page
├── public/ # Static assets
│ └── css/ # Stylesheets
└── tests/ # Test files
GET /- Main payment page with subscription plansPOST /create-checkout-session- Creates Stripe Checkout sessionGET /success- Payment success pageGET /cancel- Payment cancellation page
POST /webhook- Stripe webhook endpoint for payment events
POST /customer-portal- Creates Stripe Customer Portal session
GET /health- Health check endpoint
- Price: $10/month
- Features: All premium features, monthly billing
- Stripe Product ID: Configured via API
- Price: $100/year (Save $20 vs monthly)
- Features: All premium features, annual billing
- Best Value: Highlighted on payment page
The application handles these Stripe webhook events:
- checkout.session.completed - Successful payment
- invoice.payment_succeeded - Recurring payment success
- invoice.payment_failed - Recurring payment failure
- customer.subscription.deleted - Subscription cancellation
- Stripe signature verification for webhooks
- HTTPS-only in production
- Environment-based configuration
- No sensitive data in client-side code
- Proper error handling and logging
-
Set production environment variables:
NODE_ENV=production STRIPE_SECRET_KEY=sk_live_your_live_key STRIPE_PUBLISHABLE_KEY=pk_live_your_live_key STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret PORT=3000
-
Install production dependencies:
npm ci --only=production
- Heroku: Easy deployment with git push
- Vercel: Serverless deployment (requires serverless adaptation)
- DigitalOcean: Droplet with Node.js
- AWS: EC2 or Lambda
- Railway: Modern deployment platform
npm testUse Stripe Mock for comprehensive testing:
- Start stripe-mock server
- Run tests with mock environment
- Test webhook event handling
Edit SUBSCRIPTION_PLANS in server.js:
const SUBSCRIPTION_PLANS = {
// existing plans...
premium: {
name: 'Premium Plan',
price: 2500, // $25 in cents
interval: 'month',
currency: 'usd',
description: 'Advanced features for power users'
}
};Modify CSS in views/index.ejs or create external stylesheets in public/css/.
- Database integration for customer data
- Email notifications (Nodemailer)
- Analytics tracking
- Admin dashboard
- API rate limiting
-
Stripe Key Errors
- Verify keys in
.envfile - Ensure correct test/live mode
- Check Stripe account status
- Verify keys in
-
Webhook Failures
- Verify webhook secret
- Check webhook endpoint URL
- Review Stripe webhook logs
-
Payment Issues
- Check Stripe test cards
- Verify currency settings
- Review plan configurations
Enable debug logging:
DEBUG=stripe* npm run dev- Documentation: Stripe Checkout Docs
- API Reference: Stripe API Docs
- Issues: Create an issue in this repository
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
Note: Always test thoroughly in Stripe test mode before using live keys in production.