Skip to content

Instantly share code, notes, and snippets.

@jamztang
Created September 28, 2016 11:56
Show Gist options
  • Save jamztang/355d314aa6cb4d112528dbee5c896843 to your computer and use it in GitHub Desktop.
Save jamztang/355d314aa6cb4d112528dbee5c896843 to your computer and use it in GitHub Desktop.
// hook.io handling Stripe
var stripe = require('stripe');
var url = require('url');
var querystring = require('querystring');
module.exports = function (hook) {
var req = hook.req;
var res = hook.res;
var params = hook.params;
var amount = params["amount"];
var currency = params["currency"];
var description = params["description"];
var productID = params["productID"];
var stripeToken = params["stripeToken"];
stripe(hook.env.stripeSecretKey).charges.create({
amount: amount,
currency: currency,
source: stripeToken,
description: description,
metadata: params
}, function (error, charge) {
var status = error ? 400 : 200;
var message = error ? error.message : 'Thanks for coffee!';
res.writeHead(status, { 'Content-Type': 'text/html' });
return res.end('<h1>' + message + '</h1>');
});
/*
var dict = {
"headers": req.headers,
"method": req.method,
"url" : req.url,
"params": params
};
return res.end(JSON.stringify(dict));
*/
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment