some refactoring and enabling payment (final)

This commit is contained in:
lion
2019-02-06 14:55:48 +01:00
parent 25663ddf4a
commit 0087a7ee0c
17 changed files with 1199 additions and 459 deletions

View File

@@ -5,6 +5,7 @@ const MarketAlert = require("./MarketAlert");
const sendNotification = require("./utils/sendnotification");
const scrapTheItems = require("./utils/scraptheitems");
const sequelize = require("./db.js");
const Twocheckout = require("2checkout-node");
const app = express();
app.use(bodyParser.json());
@@ -23,7 +24,7 @@ app.get("/sendnotifications", async function(req, res) {
})
.map(sendNotification)
);
if (lastDateUpdate.some(dateUpdate => !dateUpdate)) return;
lastDateUpdate = lastDateUpdate.filter(Boolean(dateUpdate));
lastDateUpdate.length &&
lastDateUpdate.forEach(dateUpdate =>
MarketAlert.update(
@@ -47,14 +48,49 @@ app.get("/items/:url", async (req, res) => {
app.post("/marketalerts", function(req, res) {
const { email, last_date, olx_url } = req.body;
sequelize.sync().then(() =>
MarketAlert.create({
olx_url,
last_date,
email
})
);
console.log(email, last_date, olx_url);
res.json({ message: "Market Alert Created!" });
// sequelize.sync().then(() =>
// MarketAlert.create({
// olx_url,
// last_date,
// email
// })
// );
// res.json({ message: "Market Alert Created!" });
});
app.post("/payforalert", function(request, response) {
let tco = new Twocheckout({
sellerId: "901402692",
privateKey: "A28DCE5F-9292-405C-8161-F84D8BB83AFC",
sandbox: true
});
let params = {
merchantOrderId: "123",
token: request.body.token,
currency: "USD",
total: "2.00",
billingAddr: {
name: "Testing Tester",
addrLine1: "123 Test St",
city: "Sarajevo",
state: "BiH",
zipCode: "71000",
country: "BiH",
email: request.body.email,
phoneNumber: "5555555555"
}
};
tco.checkout.authorize(params, function(error, data) {
if (error) {
response.send(error.message);
} else {
response.send(data.response.responseMsg);
}
});
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`));

View File

@@ -4,6 +4,14 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"2checkout-node": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/2checkout-node/-/2checkout-node-0.0.1.tgz",
"integrity": "sha1-7a5MHUAIh6Y+hUXjf7mrBVeaaIU=",
"requires": {
"request": "2.x.x"
}
},
"@sendgrid/client": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/@sendgrid/client/-/client-6.3.0.tgz",

View File

@@ -9,6 +9,7 @@
"author": "Ehvan Gradanin",
"license": "ISC",
"dependencies": {
"2checkout-node": "0.0.1",
"@sendgrid/mail": "^6.3.1",
"cheerio": "^1.0.0-rc.2",
"express": "^4.16.4",