Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial payment server.

  • Loading branch information...
commit 7a0a5ce7890d9ce57526850cfeb2b2609cad4acf 1 parent 9585224
@nelhage authored
Showing with 41 additions and 0 deletions.
  1. +2 −0  .gitignore
  2. +39 −0 serve.js
View
2  .gitignore
@@ -0,0 +1,2 @@
+node_modules/
+config.json
View
39 serve.js
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.