npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chargify

v0.4.0-rc1

Published

Easy integration with Chargify for adding recurring payments to your application.

Downloads

488

Readme

Easy integration with Chargify for adding recurring payments to your application.

Important note

This library inspired, and has been superceded by Fermata. While Fermata's API is a little different, the codebase descends more or less directly from this library, so the overall idea is very similar.

The main differences are improved callback arguments (an error is now provided for bad status codes) and the removal of the .add, .remove and .req methods in favor of a generic HTTP method call syntax.

Oh, and also! Under node.js (and some browsers, not that that's relevant for this plugin), Fermata behaves as catch-all Proxy object. So in many cases you can actually drop the parentheses and treat the REST URLs native objects: site.subscriptions[42].components[5].get(callback)

Other than that, you should find the new library quite familiar once you load the Chargify plugin (included):

var f = require('fermata'),
    c = require('fermata/plugins/chargify');
f.registerPlugin('chargify', c);

var wrapped_site = f.chargify('example-site', "API_KEY"),
    some_subscription = wrapped_site('subscriptions')(42);  // or even `wrapped_site.subscriptions[42]`!
some_subscription.get(function(err, data) { if (!err) console.log(data.subscription.state); });

By using Fermata you get the benefits of a more refined version of this API, in a library useable with Chargify and any other RESTful services your app needs to connect to.

(end of Important Note), this here library's API documentation below…

As of version 0.2, this module is essentially a wrapper around Request, but adds a little convenience for connecting to the Chargify API.

Example

You can normally require and instantiate at the same time using your Chargify subdomain and API key.

var chargify = require('chargify');
var chargify_site = chargify('YOUR-CHARGIFY-SUBDOMAIN', 'YOUR-API-KEY');

List subscriptions:

chargify_site.get('subscriptions.json', function(err, res, body) {
    if (err) throw err;
    console.log(res.statusCode);
    console.log(body);
});

Load subscription #40:

chargify_site.get('subscriptions/40.json', function(err, res, body) {
    if (err) throw err;
    console.log(res.statusCode);
    console.log(body);
});

Create a new customer:

chargify_site.post({
    uri: 'customers.json',
    json: {
        customer: {
            first_name: 'Joe',
            last_name: 'Blow',
            email: '[email protected]'
        }
    }
}, function(err, res, body) {
    if (err) throw err;
    console.log(res.statusCode);
    console.log(body);
});

Documentation

chargify(subdomain, api_key)

Returns a chargify_site. The available methods are listed below.

  • chargify_site.get(options, callback)
  • chargify_site.post(options, callback)
  • chargify_site.put(options, callback)
  • chargify_site.del(options, callback)

The first argument can be either a url or an options object. he only required key is uri. The only required option is uri, all others are optional. The key attributes are listed below. See the Request module's README for a full list.

  • uri - Required. The URI of the resource. host, protocol, and auth information are optional.
  • json - sets the body of the request using a JavaScript object.

See also

Testing

Before running the tests, you need to create a Chargify test site and specify the site's subdomain and your API key in a JSON file called config.json.

Example config.json file:

{
    "chargifySubdomain": "chargify-test",
    "chargifyAPIKey": "xxxxxxxxxxxxxx-9x_"
}

Then simply run:

npm test

License

Copyright © 2012 by &yet, LLC and Will White. Released under the terms of the MIT License:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.