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

gumroad-onetime

v0.0.4-4

Published

One time payment url handling middleware for gumroad payment gateway links

Downloads

14

Readme

#Gumroad-Onetime

This node package makes handling one-time gumroad urls for managing payments as simple as possible. It uses Redis to store session data and urls, and the gumroad API wrapper to communicate with gumroad (making temprary link urls and removing them once used/purchased).

More detailed description of the process

##Install

npm install gumroad-onetime

##Setup

Setup your client:

var gr = require('gumroad-onetime');

gr.setup({
	// gumroad username/email
	username: "<username/email>",
	
	// gumroad password
	password: "<password>",
	
	// url for handling purchases
	path: "/buy",

	// when a user returns from paying, this function will be called 
	// and passed the session data you asked to store, or an error if applicable.
	onPurchase: function(err, req, res, data){
		console.log("Error: ", err);
		console.log("Session Data: ", data);
	}
});

###Middleware

Middleware follows the connect style function(req, res, next){} so can either be added to a standard http server, where the middleware will check if it needs to handle the request and if not, passes it to the rest of your app/routes.

http.createServer(function (req, res) {
	gr.middleware(req, res, function(req, res){
		// other routes
		// the rest of your app
		// etc
	});
	
}).listen(80);

The middleware also allows you to add it seemlessly to Express or Connect apps, and any other frameworks that follow the same pattern.

var express = require('express');
var app = express.createServer();

app.configure(function(){
    app.use(express.methodOverride());
    app.use(express.bodyParser());

    app.use(gr.middleware); // Insert Gumroad-onetime middleware

    app.use(app.router);
});

app.get('/', function(req, res){
  res.send('Hello World');
});

app.listen(3000);

###Purchases

At any point you can send a user through the purchase process, by passing the request and response objects, the link info for your purchase as well as any session data you want to keep, like so:

var userData = {user: "data", that: ["you'd", "like", "to", "store"], awesome: true};

var link = {
	name: "Awesome thing to buy",
	price: 9001,
	desc: "A nice informative description for the purchase"
}

gr.purchase(req, res, userData, link, function(err, data) {
	if (err) {
		console.log("Error completing purchase.")
	} else {
		res.writeHead(500, {'Content-Type': 'text/html'});
		res.end('Purchase successful.');
	}
});

##FYI When you issue a purchase call, gumroad-onetime creates a gumroad URL with the path you requested (ie: "/buy") and a unique token (uuid v4.) and whatever title, price and description you selected for your link.

The user request is then responded to with a 302 redirect to Gumroad, and any session data you need stored (username, what they're buying etc) is stored in redis.

When the user has completed the purchase, gumroad will give them the url which will be http://<your host>/<gumroad-onetime path>?token=<uuid>, which the middleware then intercepts, validates against the redis store and fires your onPurchase callback, with the session data you asked to be stored, allowing you to then update the users profile/inventory/credits/etc as required.

The gumroad URL is then removed, so no further purchases can be made on that url.