Clone the project at: https://github.com/bdcorps/stripe-subscriptions-nodejs
git clone https://github.com/bdcorps/stripe-subscriptions-nodejs
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
- Create a new Stripe account here.
- Add a name for your account by clicking the
Add a name
button on the top left. - Copy Secret Key under Developers > API Keys and paste in .env file as the STRIPE_SECRET_KEY.
- Replace the
publishableKey
inpublic/js/account.js
with your own from Developers > API Keys.
- Add a new product by clicking on the
Product
button 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.
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.
Download Stripe CLI.
stripe listen --forward-to localhost:4242/webhook
Copy the webhook secret and assign it to STRIPE_WEBHOOK_SECRET in .env file.
npm start