express-billing-page
An Express (4.0+) middleware for rendering billing pages to your users, directly connected to Stripe.
Designed for MongoDB.
Requires Bootstrap 4 (CSS + JS), jQuery, and Open Iconic on your client side.
The goal is to be a drop-in module for handling and managing Stripe subscriptions.
Show your users a status of their subscriptions, a list of invoices, and allow them to manage their subscriptions and cards on their own.
Features
Who uses it?
|
|
|
|
|
Nucleus | ElioPay | Backery | Litch.app | Musli.io |
👋 Want to be listed there? Contact me.
Notes
-
req.user
must contain a valid user object
-
In your Mongoose model, your users should have a plan
attribute (if you offer plans) and a stripe
object:
let UserSchema = {
...
plan: String,
stripe: {
subscriptionId: String,
subscriptionStatus: String,
customerId: String,
subscriptionItems: []
}
...
}
Usage
Install the library
npm install express-billing-page
Server code:
app.use('/billing', require('express-billing-page')({
mongoUser: db.User,
secretKey: "sk_live_xxxxxxxxxxxxxxxxxxxxxxx",
publicKey: "pk_live_xxxxxxxxxxxxxxxxxxxxxxx",
upgradable: true,
accountPath: '/account',
sendMail: (subject, text, email) => {
},
onSubscriptionChange: (user) => {
console.log('Subscription status: ' + user.stripe.subscriptionStatus)
console.log('The user is on this plan: ' + user.plan)
},
plans: [{
name: 'Hobby',
id: 'hobby',
order: 1,
stripeId: 'plan_xxxxxxxxxxxxx',
price: 12,
advantages: ['200 daily active users', '1 year data retention', '3 apps', 'Priority support']
}, {
name: 'Pro',
id: 'pro',
order: 2,
stripeId: 'plan_xxxxxxxxxxxxx',
price: 29,
advantages: ['10000 daily active users', 'Unlimited data retention', '10 apps', 'High priority support']
}]
}))
Simple client code example (jQuery & bootstrap.js are required):
.
<h1>Your subscription</h1>
<div id='billingSection'></div>
<script src='/billing/billing.js'></script>
<script>
billing.load('#billingSection')
</script>