Skip to content

Commit

Permalink
Initial payment server.
Browse files Browse the repository at this point in the history
  • Loading branch information
nelhage committed Oct 6, 2012
1 parent 9585224 commit 7a0a5ce
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
config.json
39 changes: 39 additions & 0 deletions serve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var express = require('express'),
fs = require('fs'),
path = require('path'),
http = require('http');
var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')));
var stripe = require('stripe')(config.secret_key);

var app = express();
app.configure(
function() {
app.use(express.bodyParser());
});

app.post("/money/ajax/pay", function (req,res) {
var amt = req.body.amount;
var token = req.body.token;
if (!amt || !token) {
res.send(400, {error: "Missing parameter"});
return;
}
console.log("Charging %s", token);
stripe.charges.create({
amount: amt,
currency: 'usd',
card: token,
description: 'Charge from nelhage.com/money'
}, function (error, response) {
if (error) {
res.send(error, {
error: response.error.message,
});
console.log("Failed charge: %j", response);
} else {
res.send(200, {});
}
});
});

http.createServer(app).listen(19080);

0 comments on commit 7a0a5ce

Please sign in to comment.