forked from joaoplay16/agendamento-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
67 lines (59 loc) · 1.94 KB
/
server.js
File metadata and controls
67 lines (59 loc) · 1.94 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
const express = require("express")
const app = express()
const mercadopago = require("mercadopago")
const cors = require("cors")
require("dotenv").config()
//REPLACE WITH YOUR ACCESS TOKEN AVAILABLE IN: https://developers.mercadopago.com/panel/credentials
mercadopago.configurations.setAccessToken(process.env.MP_ACCESS_TOKEN)
app.use(cors())
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
app.use(express.static("./build"))
app.get("*", function (req, res) {
res.status(200).sendFile(__dirname + "/build/index.html")
})
app.post("/process_payment", (req, res) => {
var payment_data = {
transaction_amount: Number(req.body.transactionAmount),
token: req.body.token,
description: req.body.description,
installments: Number(req.body.installments),
payment_method_id: req.body.paymentMethodId,
issuer_id: req.body.issuer,
payer: {
email: req.body.email,
identification: {
type: req.body.docType,
number: req.body.docNumber,
},
},
}
// console.log(payment_data)
mercadopago.payment
.save(payment_data)
.then(function (response) {
// res.status(response.status).json({
// status: response.body.status,
// status_detail: response.body.status_detail,
// id: response.body.id
// });
res.json({
id: response.body.id,
status: response.body.status,
payment_type_id: response.body.payment_type_id,
status_detail: response.body.status_detail,
date_approved: response.body.date_approved,
description: response.body.description,
installments: response.body.installments,
transaction_amount: response.body.transaction_amount
})
// console.log("body", response.body)
})
.catch(function (error) {
console.log(error)
res.json(error)
})
})
app.listen(process.env.PORT || 8080, () => {
console.log("The server is now running on Port 8080")
})