-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (28 loc) · 772 Bytes
/
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
require('dotenv').config()
const express = require('express')
const paypal = require('./services/paypal')
const app = express()
app.set('view engine', 'ejs')
app.get('/', (req, res) => {
res.render('index')
})
app.post('/pay', async(req, res) => {
try {
const url = await paypal.createOrder()
res.redirect(url)
} catch (error) {
res.send('Error: ' + error)
}
})
app.get('/complete-order', async (req, res) => {
try {
await paypal.capturePayment(req.query.token)
res.send('Course purchased successfully')
} catch (error) {
res.send('Error: ' + error)
}
})
app.get('/cancel-order', (req, res) => {
res.redirect('/')
})
app.listen(3000, () => console.log('Server started on port 3000'))