Skip to content

TheWorthyOne/Payment_Processor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stripe Checkout Payment Processor

A comprehensive payment processing system built with Node.js, Express, and Stripe Checkout. Supports recurring subscription plans with monthly and annual billing options.

Features

  • ✅ 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

Tech Stack

  • Backend: Node.js, Express.js
  • Payment: Stripe API (Checkout Sessions)
  • Frontend: EJS templating, Vanilla JavaScript
  • Styling: Custom CSS with modern design
  • Testing: Jest (configured)

Prerequisites

  • Node.js 14+ installed
  • Stripe account (test or live)
  • Git for version control

Installation

  1. Clone the repository

    git clone https://github.com/TheWorthyOne/Payment_Processor.git
    cd Payment_Processor
  2. Install dependencies

    npm install
  3. Configure environment variables

    cp .env.example .env
  4. Update .env file 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

Getting Stripe Keys

  1. Sign up for Stripe: stripe.com
  2. Get API keys from Stripe Dashboard → Developers → API Keys
  3. 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 .env file

Running the Application

Development Mode

npm run dev

The server will start on http://localhost:3000

Production Mode

npm start

Using Stripe Mock for Testing

For 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 serve

Then update your environment to use the mock server:

STRIPE_SECRET_KEY=sk_test_123
STRIPE_MOCK_URL=http://localhost:12111

Project Structure

Payment_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

API Endpoints

Payment Flow

  • GET / - Main payment page with subscription plans
  • POST /create-checkout-session - Creates Stripe Checkout session
  • GET /success - Payment success page
  • GET /cancel - Payment cancellation page

Webhooks

  • POST /webhook - Stripe webhook endpoint for payment events

Customer Management

  • POST /customer-portal - Creates Stripe Customer Portal session

Utility

  • GET /health - Health check endpoint

Subscription Plans

Monthly Plan

  • Price: $10/month
  • Features: All premium features, monthly billing
  • Stripe Product ID: Configured via API

Annual Plan

  • Price: $100/year (Save $20 vs monthly)
  • Features: All premium features, annual billing
  • Best Value: Highlighted on payment page

Webhook Events

The application handles these Stripe webhook events:

  1. checkout.session.completed - Successful payment
  2. invoice.payment_succeeded - Recurring payment success
  3. invoice.payment_failed - Recurring payment failure
  4. customer.subscription.deleted - Subscription cancellation

Security Features

  • Stripe signature verification for webhooks
  • HTTPS-only in production
  • Environment-based configuration
  • No sensitive data in client-side code
  • Proper error handling and logging

Deployment

Environment Setup

  1. 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
  2. Install production dependencies:

    npm ci --only=production

Platform Options

  • 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

Testing

Unit Tests

npm test

Integration Testing

Use Stripe Mock for comprehensive testing:

  1. Start stripe-mock server
  2. Run tests with mock environment
  3. Test webhook event handling

Customization

Adding New Plans

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'
  }
};

Custom Styling

Modify CSS in views/index.ejs or create external stylesheets in public/css/.

Adding Features

  • Database integration for customer data
  • Email notifications (Nodemailer)
  • Analytics tracking
  • Admin dashboard
  • API rate limiting

Troubleshooting

Common Issues

  1. Stripe Key Errors

    • Verify keys in .env file
    • Ensure correct test/live mode
    • Check Stripe account status
  2. Webhook Failures

    • Verify webhook secret
    • Check webhook endpoint URL
    • Review Stripe webhook logs
  3. Payment Issues

    • Check Stripe test cards
    • Verify currency settings
    • Review plan configurations

Debug Mode

Enable debug logging:

DEBUG=stripe* npm run dev

Support

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT License - see LICENSE file for details.


Note: Always test thoroughly in Stripe test mode before using live keys in production.

About

A complete checkout payment system utilizing Stripe

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published