diff --git a/backend/index.js b/backend/index.js
index 6345cc6..dfa36bc 100644
--- a/backend/index.js
+++ b/backend/index.js
@@ -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}!`));
diff --git a/backend/package-lock.json b/backend/package-lock.json
index 52a9248..e3a96c5 100644
--- a/backend/package-lock.json
+++ b/backend/package-lock.json
@@ -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",
diff --git a/backend/package.json b/backend/package.json
index 793dc4c..88ccdfb 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -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",
diff --git a/frontend-react/public/index.html b/frontend-react/public/index.html
index 5c3706e..1648ee8 100755
--- a/frontend-react/public/index.html
+++ b/frontend-react/public/index.html
@@ -19,6 +19,10 @@
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Roboto+Slab:400,700|Material+Icons"
/>
+