This project is a simple subscription service built using Express.js and Stripe's payment processing API. It allows users to view available subscription plans, subscribe to services, and manage their subscriptions.
Node.js npm A Stripe account with active subscription products and plans. Getting Started
- Clone the Repository bash Copy code git clone https://github.com/NP5555/stripe_subscriptions_with_nodejs cd stripe-subscriptions-nodejs
- Install Dependencies bash Copy code npm install
- Set Up Environment Variables Create a .env file in the root of the project with the following variables:
- List all available subscription plans and their prices.
- Create a subscription session and redirect users to Stripe Checkout.
- Validate coupon codes for discounted subscriptions.
- Handle webhook events from Stripe for subscription management.
- Node.js
- Express.js
- Stripe API
- EJS (for rendering views)
- dotenv (for environment variable management)
Make sure you have the following installed:
- Node.js
- A Stripe account (to get your API keys)
-
Clone the repository
git clone https://github.com/NP5555/stripe_subscriptions_with_nodejs cd stripe-subscription-service -
Install dependencies
npm install
-
Set up environment variables
Create a
.envfile in the root directory of the project and add your Stripe API keys and other relevant information:STRIPE_SECRET_KEY=your_stripe_secret_key STRIPE_WEBHOOK_SECRET_KEY=your_stripe_webhook_secret BASE_URL=http://localhost:3000 -
Run the application
npm start
The server will start on
http://localhost:3000.
GET /: Returns the main home page.GET /get-price/:productId: Get price details for a specific product by ID.GET /api/get-all-prices: List all active prices from Stripe.GET /subscribe: Redirects to Stripe Checkout for subscribing to a plan.GET /success: Success page after subscription.GET /cancel: Redirect back to home page if the subscription is canceled.GET /api/get-all-customers: Retrieve IDs of all customers from Stripe.GET /customers: Display all customers and their subscription details in a page.POST /webhook: Endpoint for handling webhook events from Stripe.POST /validate-coupon: Validate a coupon code.
This application listens for Stripe webhook events such as:
checkout.session.completedinvoice.paidinvoice.payment_failedcustomer.subscription.updated
You will need to configure your Stripe account to send webhook events to /webhook.
This project is licensed under the MIT License.
- Stripe for their payment processing API.
- Express.js for their web framework.
- EJS for server-side templating.
Feel free to modify, fork, or contribute to the project!
