New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

subscription

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

subscription

Library to store and manage paid subscriptions via Stripe and LevelDB

  • 0.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.5K
decreased by-12.36%
Maintainers
1
Weekly downloads
 
Created
Source

subscription

NodeJS library to simplify paid subscriptions with Stripe and LevelDB.

Install

$ npm install subscription

Usage

Define a new subscription:

subscription = require('subscription')('stripe-api-key', 'leveldb-path')

subscription.service.define('atlas magazine', { 'price': 1000, period: '1 month', currency: 'usd' }, function (error, atlas) {

  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' // obtain it with Stripe.js
}

subscription.purchase('atlas magazine', options, function (error, purchase) {
  purchase.amount
  // => 12000

  purchase.expires_ts
  // => 1390912838816
})

Validate a subscription:

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

Get remaining subscription of a customer:

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

List subscriptions of a user:

subscription.subscriptionsOf('azer@kodfabrik.com', function (error, subs) {
  subs
  // => ['atlas magazine']
})

Extend a subscription:

subscription.purchase.extension('atlas magazine', { customer: 'azer@kodfabrik.com', length: '2 years', token: token }, function (error, purchase) {
  purchase.amount
  // => 24000
});

Upgrade a subscription:

subscription.purchase.upgrade({ customer: 'hi@ada.io', from: 'cheaper', to: 'more expensive service', token: token }, function (error, purchase) {
  if (error) return callback(error);
});

Debugging

Verbose:

$ DEBUG=subscription:* npm test

Less Verbose:

$ DEBUG=subscription:fatal,subscription:purchase

Running Tests

$ API_KEY=sk_test_FIvJu2hkZszNIFzGgVNAqo2x npm test

More Docs

  • test.js
  • english-time: The library used for parsing time inputs.

Keywords

FAQs

Package last updated on 10 Nov 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc