stripe-subscriptions-nodejs
stripe-subscriptions-nodejs copied to clipboard
Recurring Subscriptions Billing using Stripe API
Clone the project
Clone the project at: https://github.com/bdcorps/stripe-subscriptions-nodejs
git clone https://github.com/bdcorps/stripe-subscriptions-nodejs
Setting up the project
Rename the .env.example to .env. We will replace the variables in the file one-by-one.
STRIPE_SECRET_KEY=sk_test_51H8rImAkSQQctVkLmiefLPUxZhQdclj8BqTZuvHelgyQWum4COBNcIYP8viiH5dFBrEhM69Yt7Tc0hj8o26k9Pbs00tIYJkZvS
PRODUCT_BASIC=price_1HcIFWAkSQQctVkLizPQ2Oum
PRODUCT_PRO=price_1HdI8dAkSQQctVkLD9IeOYjS
MONGODB=mongodb://localhost:27017/users
STRIPE_WEBHOOK_SECRET=whsec_rYanPBSdQSswHjizrBz2pHAo6iYa2Ows
TRIAL_DAYS=14
Set up Stripe
- Create a new Stripe account here.
- Add a name for your account by clicking the
Add a namebutton on the top left. - Copy Secret Key under Developers > API Keys and paste in .env file as the STRIPE_SECRET_KEY.
- Replace the
publishableKeyinpublic/js/account.jswith your own from Developers > API Keys.
Add products: Basic and Pro
- Add a new product by clicking on the
Productbutton on the left side. Call the first one, Product – Basic. Set the Pricing to $10.00 CAD andRecurring. Set the Billing period toMonthly.
[Image]
-
Copy the Price API ID and assign it to PRODUCT_BASIC in the .env file.
-
Repeat the process above for Product – Pro at $12.00 CAD,
Recurring, andMonthly. -
Copy the Price API ID and assign it to PRODUCT_PRO in the .env file.
-
Set a Trial Period with the TRIAL_DAYS in the .env file.
Start the MongoDB
Install MongoDB Community Edition from here. Run it by using,
mongod
The Mongo Server will start running at mongodb://localhost: 27017. We will use the users collection to save the customer information.
If you have an external Mongo server running, replace the default connection string referenced in the MONGODB in .env file.
Set up the Stripe Webhook
Download Stripe CLI.
stripe listen --forward-to localhost:4242/webhook
Copy the webhook secret and assign it to STRIPE_WEBHOOK_SECRET in .env file.
Start
npm start