forked from phiyawat/web-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
200 lines (184 loc) · 5.03 KB
/
index.js
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
var express = require("express");
var app = express();
var list = require("./list");
var bodyParser = require("body-parser");
var request = require("request");
var publicKey = "pkey_test_5dk77lui11gdmmp9jc4";
var privateKey = "skey_test_5dk77lui9m6jv0s33pp";
app.set("port", process.env.PORT || 5000);
app.use(express.static(__dirname + "/public"));
app.use(bodyParser.json());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
// views is directory for all template files
app.set("views", __dirname + "/views");
app.set("view engine", "ejs");
app.get("/", function(req, res) {
res.send(
"<meta property='og:image' content='https://firebasestorage.googleapis.com/v0/b/my-project-9d06f.appspot.com/o/image%2F46453079_289614934991275_4718699032732499968_n.jpg?alt=media&token=cf42a6d3-cd02-455e-aadc-04fc477295a2' />" +
"<meta property='og:url' content='https://phiyawat-comsci.herokuapp.com/'>" +
"<meta property='og:type' content='website'/>" +
"<meta property='og:title' content='phiyawat-comsci.herokuapp.com'/>" +
"<meta property='og:description' content='TU more sheet แหล่งซื้อขายชีทสรุปของธรรมศาสตร์'/>" +
"<meta property='fb:app_id' content='512026392655945'"
);
});
app.get("/list/:id", function(req, res) {
var id = req.params.id;
res.json(list.findById(id));
});
app.post("/newlist", function(req, res) {
var json = req.body;
res.send("Add new " + json.name + " Completed!");
});
app.post("/card", function(req, res) {
var data = req.body;
var dataString =
"card[name]=JOHN DOE&card[number]=" +
data.number +
"&card[security_code]=" +
data.code +
"&card[expiration_month]=" +
data.expireMonth +
"&card[expiration_year]=" +
data.expireYear;
request.post(
"https://vault.omise.co/tokens",
{
auth: {
user: publicKey
},
body: dataString
},
function(error, response, body) {
res.send(body);
}
);
});
app.post("/charges", function(req, res) {
var data = req.body;
var dataString =
"description=Charge for order 3947&amount=" +
data.prices +
"¤cy=thb&return_uri=http://www.example.com/orders/3947/complete&card=" +
data.tokens;
request.post(
"https://api.omise.co/charges",
{
auth: {
user: privateKey
},
body: dataString
},
function(error, response, body) {
res.send(body);
}
);
});
app.post("/confirm", function(req, res) {
var data = req.body;
var headers = {
"Content-Type": "application/json",
"X-LINE-ChannelId": "1634944383",
"X-LINE-ChannelSecret": "61ccd09a220863c54c519a88cba9d1d1",
"X-LINE-MerchantDeviceProfileId": "DEVICE PROFILE ID"
};
var dataString = {
amount: data.prices,
currency: "THB"
};
request.post(
"https://sandbox-api-pay.line.me/v2/payments/" +
data.transactionId +
"/confirm",
{
headers: headers,
body: JSON.stringify(dataString)
},
function(error, response, body) {
res.send(body);
}
);
});
app.post("/linePay", function(req, res) {
var data = req.body;
var headers = {
"Content-Type": "application/json",
"X-LINE-ChannelId": "1634944383",
"X-LINE-ChannelSecret": "61ccd09a220863c54c519a88cba9d1d1",
"X-LINE-MerchantDeviceProfileId": "DEVICE PROFILE ID"
};
var dataString = {
productName: "TUMoreSheet",
amount: data.prices,
currency: "THB",
orderId: data.date,
confirmUrl: "https://moresheet.co/BuyComplete",
cancelUrl: "https://moresheet.co/BuyCancel"
};
request.post(
"https://sandbox-api-pay.line.me/v2/payments/request",
{
headers: headers,
body: JSON.stringify(dataString)
},
function(error, response, body) {
res.send(body);
}
);
});
app.post("/confirmPrompt", function(req, res) {
var data = req.body;
var headers = {
"Content-Type": "application/x-www-form-urlencoded",
};
var dataString = {
ID: data.transactionId,
secret: "moresheet88724"
};
request({
url:"https://poomrokc.services:4242/confirm",
method:"POST",
headers: headers,
form: dataString
},
function(error, response, body) {
res.send(body);
}
);
});
app.post("/promptPay", function(req, res) {
var data = req.body;
var headers = {
"Content-Type": "application/x-www-form-urlencoded",
};
var dataString = {
fourDigit: data.fourDigit,
amount: data.prices,
time: data.time,
secret:"moresheet88724"
};
request({
url:"https://poomrokc.services:4242/createTrans",
method:"POST",
headers: headers,
form: dataString
},
function(error, response, body) {
res.send(body);
}
);
});
app.get("/index", function(req, res) {
res.send("<h1>This is index page</h1>");
});
// beware of port to cloud
app.listen(app.get("port"), function() {
console.log("Node app is running on port", app.get("port"));
});