-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
149 lines (113 loc) · 3.6 KB
/
Copy pathapp.js
File metadata and controls
149 lines (113 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* Module dependencies.
*/
var config = require('./accountdetails')
var gocardless = require('gocardless')(config);
var express = require('express');
var routes = require('./routes');
var thanks = require('./routes/thanks');
var http = require('http');
var path = require('path');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hjs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.bodyParser());
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.get('/', routes.index);
app.get('/thanks', function(req, res) {
if (!gocardless.verifySignature(req.query, config.appSecret)) return res.end(403);
gocardless.confirmResource({
resource_id: req.query.resource_id,
resource_type: req.query.resource_type
}, function(err, request, body) {
res.render('thanks', { title: 'Thank you' });
});
});
app.get('/bills', function(req, res) {
gocardless.bill.index(function(error, response, data) {
data = JSON.parse(data);
res.render('bills', { bills: data });
});
});
app.get('/users', function(req, res) {
gocardless.user.index(function(error, response, data) {
data = JSON.parse(data);
res.render('users', { users: data });
});
});
app.get('/subscriptions', function(req, res) {
gocardless.subscription.index(function(error, response, data) {
data = JSON.parse(data);
res.render('subscriptions', { subscriptions: data });
});
});
app.get('/preauthorization', function(req, res) {
gocardless.preAuthorization.index(function(error, response, data) {
data = JSON.parse(data);
res.render('preauthorization', { preauthorization: data });
});
});
app.get('/billid/:id', function(req, res) {
gocardless.bill.find(req.params.id, function(error, response, data) {
data = JSON.parse(data);
res.render('billid', { bill:data });
});
});
app.get('/subid/:id', function(req, res) {
gocardless.subscription.find(req.params.id, function(error, response, data) {
data = JSON.parse(data);
res.render('subid', { subid:data });
});
});
app.get('/authid/:id', function(req, res) {
gocardless.preAuthorization.find(req.params.id, function(error, response, data) {
data = JSON.parse(data);
res.render('authid', { authid:data });
});
});
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
app.post('/subscribe', function(req, res) {
var url = gocardless.subscription.newUrl({
amount: '1.25',
interval_length: '1',
interval_unit: 'month',
name: 'Coffee',
description: 'Fresh roast coffee subscription',
setup_fee: '10.00'
});
res.redirect(url);
});
app.post('/preauth', function(req, res) {
var url = gocardless.preAuthorization.newUrl({
max_amount: '15.00',
interval_length: '3',
interval_unit: 'month',
name: 'Pizza',
description: 'Pizza every single month'
});
res.redirect(url);
});
app.post('/buy', function(req, res) {
var descript = req.body.description
var cost = req.body.price
var url = gocardless.bill.newUrl({
amount: cost,
name: descript,
//description: 'Delicious Fried Chicken'
});
res.redirect(url);
});