summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-01-20 00:10:23 -0500
committerJules Laplace <jules@okfoc.us>2015-01-20 00:10:23 -0500
commit717e87b7422db8e1eda655fbf04e45fe5f877c9b (patch)
tree391531defbea8e312a49e635c1568f66f248ac82
parent904a18b763889c9f85d874388fdff9daaefb89cd (diff)
combining webhook stuff
-rw-r--r--package.json1
-rw-r--r--server/index.js3
-rw-r--r--server/lib/api/profile.js1
-rw-r--r--server/lib/schemas/Subscription.js1
-rw-r--r--server/lib/schemas/User.js4
-rw-r--r--server/lib/views/index.js1
-rw-r--r--server/lib/webhook/config.js6
-rw-r--r--server/lib/webhook/index.js (renamed from server/lib/views/subscription.js)45
8 files changed, 26 insertions, 36 deletions
diff --git a/package.json b/package.json
index 34e0c4c..8afb96e 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,7 @@
"mongoose-unique-validator": "~0.3.0",
"monk": "~0.7.1",
"multer": "~0.1.0",
+ "node-recurly": "^2.1.0",
"node-restful": "~0.1.14",
"passport": "~0.2.0",
"passport-facebook": "~1.0.3",
diff --git a/server/index.js b/server/index.js
index 0f4941a..9a9323c 100644
--- a/server/index.js
+++ b/server/index.js
@@ -70,9 +70,6 @@ site.setup = function(){
app.all('*', middleware.ensureLocals);
app.all('*', middleware.ensureIP);
- // where should this live?
- app.get('/subscribe/webhook', views.subscription.webhook);
-
server = http.createServer(app)
server.listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
diff --git a/server/lib/api/profile.js b/server/lib/api/profile.js
index 996505f..d72a2c3 100644
--- a/server/lib/api/profile.js
+++ b/server/lib/api/profile.js
@@ -32,6 +32,7 @@ var profile = {
delete data.old_password
delete data.new_password
delete data.isStaff
+ delete data.plan_level
data.updated_at = new Date ()
if (req.files.avatar) {
diff --git a/server/lib/schemas/Subscription.js b/server/lib/schemas/Subscription.js
index 8315009..7f2579b 100644
--- a/server/lib/schemas/Subscription.js
+++ b/server/lib/schemas/Subscription.js
@@ -15,6 +15,7 @@ var SubscriptionSchema = new mongoose.Schema({
plans: [{
tier: { type: String },
monthly: { type: Boolean },
+ projects: [{ type: mongoose.Schema.ObjectId }],
}],
created_at: { type: Date, default: Date.now },
diff --git a/server/lib/schemas/User.js b/server/lib/schemas/User.js
index 180a140..ae1d912 100644
--- a/server/lib/schemas/User.js
+++ b/server/lib/schemas/User.js
@@ -54,7 +54,9 @@ var UserSchema = new mongoose.Schema({
type: String,
default: "",
},
-
+
+ plan_level: { type: Number, default: 0 },
+
location: { type: String, default: "" },
photo: { type: String, default: "" },
bio: { type: String, default: "" },
diff --git a/server/lib/views/index.js b/server/lib/views/index.js
index 2a8f921..0ce0357 100644
--- a/server/lib/views/index.js
+++ b/server/lib/views/index.js
@@ -22,7 +22,6 @@ marked.setOptions({
var views = module.exports = {
staff: require('./staff'),
- subscription: require('./subscription'),
editor_new: function (req, res) {
if (! req.user) {
diff --git a/server/lib/webhook/config.js b/server/lib/webhook/config.js
new file mode 100644
index 0000000..ecafeb3
--- /dev/null
+++ b/server/lib/webhook/config.js
@@ -0,0 +1,6 @@
+module.exports = {
+ API_KEY: require('process').env['VVALLS_RECURLY_SECRET'],
+ SUBDOMAIN: 'vvalls',
+ ENVIRONMENT: 'sandbox',
+ DEBUG: true,
+};
diff --git a/server/lib/views/subscription.js b/server/lib/webhook/index.js
index b9c79cb..c4b4b76 100644
--- a/server/lib/views/subscription.js
+++ b/server/lib/webhook/index.js
@@ -1,3 +1,6 @@
+// // where should this live?
+// app.get('/subscribe/webhook', views.subscription.webhook);
+
/* jshint node: true */
var User = require('../schemas/User'),
@@ -7,7 +10,9 @@ var User = require('../schemas/User'),
util = require('../util'),
_ = require('lodash'),
moment = require('moment'),
- xml2js = require('xml2js');
+ xml2js = require('xml2js'),
+ Recurly = require('node-recurly'),
+ recurly = new Recurly(require('./config'));
var parser = new xml2js.Parser();
// fs.readFile('./foo.xml', function(err, data) {
@@ -16,37 +21,15 @@ var parser = new xml2js.Parser();
// });
// });
+/*
+app.use(express.basicAuth(function(user, pass, callback) {
+ var result = (user === 'testUser' && pass === 'testPass');
+ callback(null, result);
+}));
+*/
+
var subscription = module.exports = {
- fields: [
- // accounts
- "new_account_notification",
- "canceled_account_notification",
- "billing_info_updated_notification",
- "reactivated_account_notification",
-
- // invoices
- "new_invoice_notification",
- "closed_invoice_notification",
- "past_due_invoice_notification",
-
- // subscriptions
- "new_subscription_notification",
- "updated_subscription_notification",
- "canceled_subscription_notification",
- "expired_subscription_notification",
- "renewed_subscription_notification",
-
- // payments
- "successful_payment_notification",
- "failed_payment_notification",
- "successful_refund_notification",
- "void_payment_notification",
- ],
-
- middleware: {
- },
-
callbacks: {
// accounts
new_account_notification: function(data){
@@ -97,7 +80,7 @@ var subscription = module.exports = {
console.log(inspect(result, { colors: true, depth: Infinity }));
for (var i in data) {
if (subscription.callbacks[i]) {
- subscription.callbacks[i](data)
+ subscription.callbacks[i](data[i])
}
}
});