2.0.0 • Published 5 years ago

express-billing-page v2.0.0

Weekly downloads
31
License
MIT
Repository
-
Last release
5 years ago

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

  • Upgrade popups
  • List of recent invoices to download
  • Support SCA (3D secure)
  • Display alert in case of payment failure
  • List active subscription plans
  • Add/remove/select credit cards
  • Support trials (with credit card)
  • Button to self cancel subscriptions
  • Support coupons in the URL

Who uses it?

👋 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, // A direct access to your Mongoose database User
	secretKey: "sk_live_xxxxxxxxxxxxxxxxxxxxxxx",
	publicKey: "pk_live_xxxxxxxxxxxxxxxxxxxxxxx",
	upgradable: true, // If you offer a product based on plans, will offer a popup to upgrade plans
	accountPath: '/account', // So the redirects don't fail
	sendMail: (subject, text, email) => {
		// Send a mail with the library of your choice
		// For upgrades and cancellations emails
	},
	onSubscriptionChange: (user) => {
		// Called when the subscription of an user changed
		// When he upgrades, cancels, or finishes trial

		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', // Id of your plan on Stripe
		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>
2.0.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago