Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 78d090491b8a8068d5994c37908160f8c3fca415 @boucher committed Feb 1, 2012
Showing with 79 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 Procfile
  3. BIN cash_register.wav
  4. +30 −0 index.html
  5. +8 −0 package.json
  6. +39 −0 web.js
@@ -0,0 +1 @@
+node_modules
@@ -0,0 +1 @@
+web: node web.js
Binary file not shown.
@@ -0,0 +1,30 @@
+<html>
+<head>
+<script src="/dnode.js" type="text/javascript"></script>
+<script type="text/javascript">
+ window.onload = function () {
+
+ var cashRegisterAudio = document.getElementById('cash_register');
+
+ DNode(function(){
+ this.chargeSucceeded = function(charge) {
+ var chargeLi = document.createElement('li');
+ chargeLi.innerHTML = "Charge for $"+(charge.amount/100).toFixed(2) +
+ " with description '"+charge.description+"' succeeded!";
+
+ document.getElementById('charges').appendChild(chargeLi);
+ cashRegisterAudio.play();
+ }
+ }).connect();
+
+ };
+</script>
+</head>
+<body>
+
+<ul id="charges">
+</ul>
+
+<audio id="cash_register" src="/cash_register.wav" style="display:none;" preload></audio>
+</body>
+</html>
@@ -0,0 +1,8 @@
+{
+ "name": "payments-webhook-node",
+ "version": "0.0.1",
+ "dependencies": {
+ "express": "2.5.6",
+ "dnode": "0.9.6"
+ }
+}
@@ -0,0 +1,39 @@
+var EventEmitter = require('events').EventEmitter;
+var emitter = new EventEmitter;
+
+var express = require('express');
+var app = express.createServer();
+
+app.use(express.static(__dirname));
+app.use(express.bodyParser())
+
+app.post('/stripe-webhook', function(request, response){
+ console.log(request.body)
+ if (request.body.type === 'charge.succeeded') {
+ console.log(request.body.data.object);
+ emitter.emit('chargeSucceeded', request.body.data.object);
+ }
+ response.send('OK');
+});
+
+function chargeServer(client, con) {
+ con.on('ready', function () {
+ if (typeof client['chargeSucceeded'] === 'function') {
+ emitter.on('chargeSucceeded', client['chargeSucceeded']);
+ }
+ });
+
+ con.on('end', function () {
+ if (typeof client['chargeSucceeded'] === 'function') {
+ emitter.removeListener('chargeSucceeded', client['chargeSucceeded']);
+ }
+ });
+}
+
+app.listen(8080);
+
+// then just pass the server app handle to .listen()!
+
+var dnode = require('dnode');
+var server = dnode(chargeServer);
+server.listen(app);

0 comments on commit 78d0904

Please sign in to comment.