-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (37 loc) · 1.22 KB
/
index.js
File metadata and controls
49 lines (37 loc) · 1.22 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
const express = require("express");
const https = require("https")
const fs = require("fs")
const path = require('path')
const axios = require('axios')
const bodyParser = require('body-parser')
const jsonParser = bodyParser.json()
const app = express();
app.use(express.static('static'))
app.listen(process.env.PORT || 3000, () => {
console.log(`Server is runing at port ${process.env.PORT || 3000}`);
});
app.get('/', (req,res)=>{
res.sendFile("index.html")
})
app.post('/paymentSession', jsonParser, async (req, res) => {
const { appleUrl } = req.body
// use set the certificates for the POST request
httpsAgent = new https.Agent({
rejectUnauthorized: false,
cert: fs.readFileSync(path.join(__dirname, './apple-pay/certificate_sandbox.pem')),
key: fs.readFileSync(path.join(__dirname, './apple-pay/certificate_sandbox.key')),
})
response = await axios.post(
appleUrl,
{
merchantIdentifier: 'merchant.verygoodsecurity.demo.applepay',
initiativeContext: 'vgs-google-apple-pay-demo-js.herokuapp.com',
initiative: "web",
displayName: "Very Good Security Demo Account"
},
{
httpsAgent,
}
)
res.send(response.data)
})