subscription

Library to store and manage paid subscriptions via Stripe and LevelDB

NodeJS library to simplify paid subscriptions with Stripe and LevelDB.

$ npm install subscription

Define a new subscription:

subscription = require('subscription')('stripe-api-key', 'leveldb-path')
 
subscription.define('atlas magazine', { 'price': 1000, period: '1 month', currency: 'usd' }, function (erroratlas) {
 
  subscription.priceOf(atlas, '1 month')
  // => 1000 (Ten dollars) 
 
  subscription.priceOf(atlas, '1 year')
  // => 12000 (One Twenty Dollars) 
 
})

Purchase a subscription:

options = {
  customer: 'customer@website.com',
  length: '1 year',
  token: 'tok_2oWvm6yRBFSMSh' // obtained with Stripe.js 
}
 
subscription.purchase('atlas magazine', options, function (errorpurchase) {
  purchase.amount
  // => 12000 
 
  purchase.expires_ts
  // => 1390912838816 
})

Validate a subscription:

subscription.has('azer@kodfabrik.com', 'atlas magazine', function (errorhas) {
  has
  // => true 
})

Get remaining subscription of a customer:

subscription.remaining('azer@kodfabrik.com', 'atlas magazine', function (errorremaining) {
 
  remaining
  // => 8035200000 (3 months) 
 
})

List all subscriptions of a user:

subscription.subscriptionsOf('azer@kodfabrik.com', function (errorsubs) {
 
  subs
  // => ['atlas magazine'] 
 
})
  • test.js
  • english-time: The library used for parsing time inputs.

Verbose:

$ DEBUG=subscription:* npm test

Less Verbose:

$ DEBUG=subscription:fatal,subscription:purchase
$ API_KEY=sk_test_FIvJu2hkZszNIFzGgVNAqo2x