Merge branch 'master' of http://128.199.30.231/possibillion/smellika-api
This commit is contained in:
commit
fa76a3e0ab
24
.env
24
.env
@ -1,37 +1,27 @@
|
||||
|
||||
# mongodb
|
||||
# DB_URL="mongodb+srv://smellica:Anjefef23dnsfjne@cluster0.c5gfqzm.mongodb.net/?retryWrites=true&w=majority"
|
||||
# DB_URL="mongodb+srv://Get-Sygnal:Doo1KHDIWWlSsTFW@cluster.zom9mlq.mongodb.net/test?ssl=true&sslValidate=true"
|
||||
|
||||
DB_URL="mongodb+srv://smellica:Anjefef23dnsfjne@cluster0.c5gfqzm.mongodb.net/"
|
||||
# //Anjefef23dnsfjne
|
||||
PORT = 5000
|
||||
JWT_SECRET = jdvnvjwrniwj4562jn6@1xsbfeh@wre4Njdf;
|
||||
JWT_SECRET = jdvnvjwrniwj4562ddsjn6@1xsbfeh@wre4Njdf;
|
||||
|
||||
|
||||
# // smellica cloudinary credential
|
||||
CLOUDINARY_NAME = "dnmgivd1x"
|
||||
CLOUDINARY_API_KEY = "877544192441588"
|
||||
CLOUDINARY_API_SECRET = "9paejuSC-fY5b0WoaUuSFURSnvM"
|
||||
WEBHOOK_SECRET_KEY="whsec_m9u7CFBCY1qWarhxq65CkII6egOBf20K"
|
||||
|
||||
# SEND_EMAIL_FROM="project.boloai@gmail.com"
|
||||
STRIPE_SECRET_KEY="sk_test_51OhPRdSG6gbAOwcEid1GavJ4FTD0ZuHVTferdvJwKal77RlMtFJGBzL5GjtL0ie8ZJztsGjUWi8DWrnw1pDdDRGS005Hk0ahql"
|
||||
STRIPE_WEBHOOK_SECRET="whsec_dc9b9084fc764c806c8c5c06dd91de1ee809e9c8deab6d56e8e3ef2fc9c30c67"
|
||||
FRONTEND_URL="http://127.0.0.1:5173"
|
||||
|
||||
# # Bolo Ai
|
||||
# SENDGRID_API_KEY="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"
|
||||
|
||||
# SMPT_HOST="smtp-relay.brevo.com"
|
||||
# SMPT_PORT="587"
|
||||
# SMPT_MAIL="beameri.team@gmail.com"
|
||||
# SMPT_PASSWORD="xsmtpsib-a88c224860249a3f1e0765e0e3d119c1bf07ad21f2859318fbf50975deee1711-JrdPpfsvF6LwEn4A"
|
||||
SEND_EMAIL_FROM="hello@smellika.com"
|
||||
|
||||
# Bolo Ai
|
||||
SENDGRID_API_KEY="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"
|
||||
|
||||
#brevo send mail
|
||||
SMPT_HOST="smtp-relay.brevo.com"
|
||||
SMPT_PORT="587"
|
||||
SMPT_MAIL="neonflake.enterprises@gmail.com"
|
||||
SMPT_PASSWORD="ND5sgVnWtrpUFfTb"
|
||||
# SMPT_PASSWORD="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"
|
||||
|
||||
PAYPAL_CLIENT_ID="AemCjVuWswklp1sWUo4peCFg9eS4bofMsMR0RCrVRB2DifYR1IUSrWqtHpVmQlrVMKTI2cWZXLJAdYwn"
|
||||
PAYPAL_CLIENT_SECRET="EAo0Y9ff3jpHHg1QAbftdebfh7cb_-vnebhQrP9KALbCVer908yx2tO2eHO39r7EJSfqc4D69Qgx8R31"
|
||||
|
92
app.js
92
app.js
@ -11,12 +11,22 @@ import cookieParser from "cookie-parser";
|
||||
import designRoute from "./resources/Design/designRouter.js";
|
||||
// app.use(express.json({ limit: "50mb" }));
|
||||
// app.use(express.urlencoded({ extended: true, limit: "50mb" }));
|
||||
|
||||
//webhook call route according strip (webhook want raw data not json data)
|
||||
app.use((req, res, next) => {
|
||||
if (req.originalUrl === "/api/order/webhook") {
|
||||
next();
|
||||
} else {
|
||||
express.json()(req, res, next);
|
||||
}
|
||||
});
|
||||
///////////////////////////////////////////////
|
||||
|
||||
app.use(cookieParser());
|
||||
|
||||
//handdle cores
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
// app.use(bodyParser.urlencoded({ extended: true }));
|
||||
app.use("/api/design", designRoute);
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
@ -32,6 +42,84 @@ app.use(
|
||||
})
|
||||
);
|
||||
|
||||
// const { STRIPE_SECRET_KEY, WEBHOOK_SECRET_KEY } = process.env;
|
||||
// import { Stripe } from "stripe";
|
||||
// const stripe = new Stripe(STRIPE_SECRET_KEY, {
|
||||
// apiVersion: "2020-08-27",
|
||||
// });
|
||||
// app.post(
|
||||
// "/webhook",
|
||||
// express.raw({ type: "application/json" }),
|
||||
// (request, response) => {
|
||||
// const sig = request.headers["stripe-signature"];
|
||||
|
||||
// const signatureParts = sig.split(",");
|
||||
|
||||
// // Initialize variables to store extracted values
|
||||
// let t, v1, v0;
|
||||
|
||||
// // Iterate over signature parts
|
||||
// signatureParts.forEach((part) => {
|
||||
// // Split each part by "=" to separate key and value
|
||||
// const [key, value] = part.split("=");
|
||||
|
||||
// // Assign value to the corresponding variable based on the key
|
||||
// if (key === "t") {
|
||||
// t = value;
|
||||
// } else if (key === "v1") {
|
||||
// v1 = value;
|
||||
// } else if (key === "v0") {
|
||||
// v0 = value;
|
||||
// }
|
||||
// });
|
||||
|
||||
// // Log the extracted values
|
||||
// // console.log("t:", t);
|
||||
// // console.log("v1:", v1);
|
||||
// // console.log("v0:", v0);
|
||||
|
||||
// let event;
|
||||
// // console.log("sig", sig);
|
||||
// // console.log(typeof request.body);
|
||||
// // console.log("request.body", request.body);
|
||||
// // const concatenatedString = t + "." + JSON.stringify(request.body);
|
||||
// const requestBodyString = JSON.stringify(request.body);
|
||||
// const concatenatedString = `${t}.${requestBodyString}`;
|
||||
// console.log("concatenatedString", concatenatedString);
|
||||
|
||||
// try {
|
||||
// event = stripe.webhooks.constructEvent(
|
||||
// concatenatedString,
|
||||
// sig,
|
||||
// "whsec_dc9b9084fc764c806c8c5c06dd91de1ee809e9c8deab6d56e8e3ef2fc9c30c67"
|
||||
// );
|
||||
// console.log(
|
||||
// "+++++++++++++++event-----------------++=",
|
||||
// event,
|
||||
// "=================="
|
||||
// );
|
||||
// } catch (err) {
|
||||
// response.status(400).send(`Webhook Error: ${err.message}`);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // Handle the event
|
||||
// switch (event.type) {
|
||||
// case "payment_intent.succeeded":
|
||||
// console.log("event.data.object", event.data.object);
|
||||
// const paymentIntentSucceeded = event.data.object;
|
||||
// // Then define and call a function to handle the event payment_intent.succeeded
|
||||
// break;
|
||||
// // ... handle other event types
|
||||
// default:
|
||||
// console.log(`Unhandled event type ${event.type}`);
|
||||
// }
|
||||
|
||||
// // Return a 200 response to acknowledge receipt of the event
|
||||
// response.send();
|
||||
// }
|
||||
// );
|
||||
|
||||
//auth
|
||||
import user from "./resources/user/userRoute.js";
|
||||
import ProductRouter from "./resources/Products/ProductRoute.js";
|
||||
|
224
package-lock.json
generated
224
package-lock.json
generated
@ -21,6 +21,7 @@
|
||||
"express-fileupload": "^1.4.0",
|
||||
"generate-password": "^1.7.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"micro": "^10.0.1",
|
||||
"mongoose": "^6.3.5",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"multer-storage-cloudinary": "^4.0.0",
|
||||
@ -193,6 +194,11 @@
|
||||
"resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz",
|
||||
"integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw=="
|
||||
},
|
||||
"node_modules/arg": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/arg/-/arg-4.1.0.tgz",
|
||||
"integrity": "sha512-ZWc51jO3qegGkVh8Hwpv636EkbesNV5ZNQPCtRa+0qytRYPEs9IYT9qITY9buezqUH5uqyzlWLcufrzU2rffdg=="
|
||||
},
|
||||
"node_modules/array-flatten": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
||||
@ -316,7 +322,7 @@
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer": {
|
||||
"node_modules/bson/node_modules/buffer": {
|
||||
"version": "5.7.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
||||
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
|
||||
@ -369,12 +375,17 @@
|
||||
}
|
||||
},
|
||||
"node_modules/call-bind": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
|
||||
"integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.6.tgz",
|
||||
"integrity": "sha512-Mj50FLHtlsoVfRfnHaZvyrooHcrlceNZdL/QBvJJVd9Ta55qCQK0gs4ss2oZDeV9zFCs6ewzYgVE5yfVmfFpVg==",
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.1",
|
||||
"get-intrinsic": "^1.0.2"
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2",
|
||||
"get-intrinsic": "^1.2.3",
|
||||
"set-function-length": "^1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
@ -604,6 +615,20 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/define-data-property": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.2.tgz",
|
||||
"integrity": "sha512-SRtsSqsDbgpJBbW3pABMCOt6rQyeM8s8RiyeSN8jYG8sYmt/kGJejbydttUsnDs1tadr19tvhT4ShwMyoqAm4g==",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"get-intrinsic": "^1.2.2",
|
||||
"gopd": "^1.0.1",
|
||||
"has-property-descriptors": "^1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/degenerator": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/degenerator/-/degenerator-3.0.2.tgz",
|
||||
@ -681,6 +706,14 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/es-errors": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
||||
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/escape-html": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
|
||||
@ -931,9 +964,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/function-bind": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
||||
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
||||
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/generate-password": {
|
||||
"version": "1.7.0",
|
||||
@ -941,13 +977,18 @@
|
||||
"integrity": "sha512-WPCtlfy0jexf7W5IbwxGUgpIDvsZIohbI2DAq2Q6TSlKKis+G4GT9sxvPxrZUGL8kP6WUXMWNqYnxY6DDKAdFA=="
|
||||
},
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz",
|
||||
"integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==",
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz",
|
||||
"integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==",
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.1",
|
||||
"has": "^1.0.3",
|
||||
"has-symbols": "^1.0.1"
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2",
|
||||
"has-proto": "^1.0.1",
|
||||
"has-symbols": "^1.0.3",
|
||||
"hasown": "^2.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
@ -1004,23 +1045,23 @@
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/gopd": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
|
||||
"integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==",
|
||||
"dependencies": {
|
||||
"get-intrinsic": "^1.1.3"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/graceful-fs": {
|
||||
"version": "4.2.10",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz",
|
||||
"integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/has": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
|
||||
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/has-flag": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
||||
@ -1029,6 +1070,28 @@
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/has-property-descriptors": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz",
|
||||
"integrity": "sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==",
|
||||
"dependencies": {
|
||||
"get-intrinsic": "^1.2.2"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-symbols": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
|
||||
@ -1040,6 +1103,17 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/hasown": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.1.tgz",
|
||||
"integrity": "sha512-1/th4MHjnwncwXsIW6QMzlvYL9kG5e/CpVvLRZe4XPa8TOUNbCELqmvhDmnkNsAjwaG4+I8gJJL0JBvTTLO9qA==",
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/http-errors": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
|
||||
@ -1373,6 +1447,88 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/micro": {
|
||||
"version": "10.0.1",
|
||||
"resolved": "https://registry.npmjs.org/micro/-/micro-10.0.1.tgz",
|
||||
"integrity": "sha512-9uwZSsUrqf6+4FLLpiPj5TRWQv5w5uJrJwsx1LR/TjqvQmKC1XnGQ9OHrFwR3cbZ46YqPqxO/XJCOpWnqMPw2Q==",
|
||||
"dependencies": {
|
||||
"arg": "4.1.0",
|
||||
"content-type": "1.0.4",
|
||||
"raw-body": "2.4.1"
|
||||
},
|
||||
"bin": {
|
||||
"micro": "dist/src/bin/micro.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/micro/node_modules/bytes": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
|
||||
"integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/micro/node_modules/depd": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
|
||||
"integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/micro/node_modules/http-errors": {
|
||||
"version": "1.7.3",
|
||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.3.tgz",
|
||||
"integrity": "sha512-ZTTX0MWrsQ2ZAhA1cejAwDLycFsd7I7nVtnkT3Ol0aqodaKW+0CTZDQ1uBv5whptCnc8e8HeRRJxRs0kmm/Qfw==",
|
||||
"dependencies": {
|
||||
"depd": "~1.1.2",
|
||||
"inherits": "2.0.4",
|
||||
"setprototypeof": "1.1.1",
|
||||
"statuses": ">= 1.5.0 < 2",
|
||||
"toidentifier": "1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/micro/node_modules/raw-body": {
|
||||
"version": "2.4.1",
|
||||
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.1.tgz",
|
||||
"integrity": "sha512-9WmIKF6mkvA0SLmA2Knm9+qj89e+j1zqgyn8aXGd7+nAduPoqgI9lO57SAZNn/Byzo5P7JhXTyg9PzaJbH73bA==",
|
||||
"dependencies": {
|
||||
"bytes": "3.1.0",
|
||||
"http-errors": "1.7.3",
|
||||
"iconv-lite": "0.4.24",
|
||||
"unpipe": "1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/micro/node_modules/setprototypeof": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
|
||||
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
|
||||
},
|
||||
"node_modules/micro/node_modules/statuses": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
|
||||
"integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/micro/node_modules/toidentifier": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
|
||||
"integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==",
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
|
||||
@ -2047,6 +2203,22 @@
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/set-function-length": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.1.tgz",
|
||||
"integrity": "sha512-j4t6ccc+VsKwYHso+kElc5neZpjtq9EnRICFZtWyBsLojhmeF/ZBd/elqm22WJh/BziDe/SBiOeAt0m2mfLD0g==",
|
||||
"dependencies": {
|
||||
"define-data-property": "^1.1.2",
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2",
|
||||
"get-intrinsic": "^1.2.3",
|
||||
"gopd": "^1.0.1",
|
||||
"has-property-descriptors": "^1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/setprototypeof": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
||||
|
@ -23,6 +23,7 @@
|
||||
"express-fileupload": "^1.4.0",
|
||||
"generate-password": "^1.7.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"micro": "^10.0.1",
|
||||
"mongoose": "^6.3.5",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"multer-storage-cloudinary": "^4.0.0",
|
||||
|
209
resources/Orders/StripeCheckOutController.js
Normal file
209
resources/Orders/StripeCheckOutController.js
Normal file
@ -0,0 +1,209 @@
|
||||
// app.post("/checkout-session", handlePayment);
|
||||
import bodyParser from "body-parser";
|
||||
const { STRIPE_SECRET_KEY, WEBHOOK_SECRET_KEY } = process.env;
|
||||
import crypto from "crypto";
|
||||
import Stripe from "stripe";
|
||||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
|
||||
// const stripe = require("stripe")("Your Secret Key");
|
||||
import { Order } from "./orderModel.js";
|
||||
|
||||
import { shippingAddress } from "../ShippingAddresses/ShippingAddressModel.js";
|
||||
import sendEmail from "../../Utils/sendEmail.js";
|
||||
// const endpointSecret = STRIPE_SECRET_KEY;
|
||||
//generate unique order id
|
||||
const generateUniqueOrderId = async () => {
|
||||
const currentYear = new Date().getFullYear();
|
||||
// Find the latest order to get the last serial number
|
||||
const latestOrder = await Order.findOne({}, {}, { sort: { orderID: -1 } });
|
||||
let serialNumber = 1;
|
||||
|
||||
if (latestOrder) {
|
||||
const lastYear = parseInt(latestOrder.orderID.substring(0, 4), 10);
|
||||
if (lastYear === currentYear) {
|
||||
// If the last order was in the current year, increment the serial number
|
||||
serialNumber = parseInt(latestOrder.orderID.substring(4), 10) + 1;
|
||||
}
|
||||
}
|
||||
// Pad the serial number with zeros and concatenate with the current year
|
||||
const paddedSerialNumber = serialNumber.toString().padStart(7, "0");
|
||||
const orderId = `${currentYear}${paddedSerialNumber}`;
|
||||
return orderId;
|
||||
};
|
||||
|
||||
export const handlePayment = async (req, res) => {
|
||||
try {
|
||||
const { email } = req.user;
|
||||
if (!email)
|
||||
return res.status(400).send({ message: "Please enter the email" });
|
||||
const { address, cart, subtotal } = req.body;
|
||||
if (cart.length < 1)
|
||||
return res.status(400).json({ message: "cart is empty!" });
|
||||
switch (true) {
|
||||
//validation
|
||||
case !address: {
|
||||
return res.status(404).json({ msg: "please provide shipping address" });
|
||||
}
|
||||
case !subtotal: {
|
||||
return res.status(404).json({ msg: "please provide product subtotal" });
|
||||
}
|
||||
}
|
||||
let addss = await shippingAddress.findById(address);
|
||||
console.log(addss?.postalCode);
|
||||
let shipping = {
|
||||
first_Name: addss.first_Name,
|
||||
last_Name: addss.last_Name,
|
||||
phone_Number: addss.phone_Number,
|
||||
street: addss.street,
|
||||
city: addss.city,
|
||||
state: addss.state,
|
||||
postalCode: addss?.postalCode,
|
||||
country: addss.country,
|
||||
addressId: address,
|
||||
};
|
||||
const orderItems = await cart.map((item) => ({
|
||||
product: item.product._id,
|
||||
name: item.product.name,
|
||||
price: item.product.total_amount,
|
||||
image: item.product.image,
|
||||
quantity: item.quantity,
|
||||
product_Subtotal: item.subtotal,
|
||||
}));
|
||||
|
||||
// console.log("line", lineItems[0]);
|
||||
const Id = await generateUniqueOrderId();
|
||||
const order = await Order.create({
|
||||
orderID: Id,
|
||||
total_amount: subtotal,
|
||||
orderItems,
|
||||
shippingInfo: shipping,
|
||||
user: req.user._id,
|
||||
});
|
||||
console.log("fffffffff", order, "llllllllll");
|
||||
const lineItems = await cart.map((item) => ({
|
||||
price_data: {
|
||||
currency: "inr",
|
||||
product_data: {
|
||||
name: item.product.name,
|
||||
|
||||
images: [item.product.image[0]?.url],
|
||||
},
|
||||
unit_amount: Number(item.product.total_amount) * 100,
|
||||
},
|
||||
quantity: Number(item.quantity),
|
||||
}));
|
||||
if (order) {
|
||||
const session = await stripe.checkout.sessions.create({
|
||||
payment_method_types: ["card"],
|
||||
line_items: lineItems,
|
||||
mode: "payment",
|
||||
customer_email: `${email}`,
|
||||
metadata: {
|
||||
orderId: order._id.toString(),
|
||||
|
||||
// Add any other key-value pairs as needed
|
||||
},
|
||||
success_url: `${process.env.FRONTEND_URL}/cart`,
|
||||
cancel_url: `${process.env.FRONTEND_URL}/error`,
|
||||
});
|
||||
// res.json({ sessionId: session.id });
|
||||
|
||||
res.status(200).send({ message: "order created", url: session.url });
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
res.status(500).send({ message: "Something went wrong", err });
|
||||
}
|
||||
};
|
||||
|
||||
export const webhook = async (req, res) => {
|
||||
const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
|
||||
const signature = req.headers["stripe-signature"];
|
||||
let event;
|
||||
if (webhookSecret) {
|
||||
try {
|
||||
event = stripe.webhooks.constructEvent(
|
||||
req.body,
|
||||
signature,
|
||||
webhookSecret
|
||||
);
|
||||
} catch (err) {
|
||||
console.log(`❌ Error message: ${err.message}`);
|
||||
res.status(400).send(`Webhook Error: ${err.message}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.type === "checkout.session.completed") {
|
||||
// console.log("dddddddddddd", event.data);
|
||||
const findOrder = await Order.findById(event.data.object.metadata?.orderId);
|
||||
findOrder.paypal_payer_id = event.data.object.id;
|
||||
findOrder.paidAt = new Date(event.data.object.created * 1000);
|
||||
findOrder.isPaid = true;
|
||||
if (event.data.object?.payment_status === "paid") {
|
||||
findOrder.payment_status = "success";
|
||||
} else {
|
||||
findOrder.payment_status = "failed";
|
||||
}
|
||||
findOrder.orderStatus = "new";
|
||||
await findOrder.save();
|
||||
await sendEmail({
|
||||
to: `${event.data.object.customer_email}`, // Change to your recipient
|
||||
|
||||
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
||||
|
||||
subject: `Your Order #${findOrder?.orderID} Confirmation`,
|
||||
html: ` <h1 style="color: #333; text-align: center; font-family: Arial, sans-serif;">Welcome to Smellika - Let the Shopping Begin!</h1>
|
||||
<strong style="color: #1b03a3; font-size: 16px"> Hi ${findOrder?.shippingInfo?.first_Name},</strong>
|
||||
|
||||
<p style="color: #555; font-size: 15px;">Great news! Your order #${findOrder?.orderID} has been confirmed. Here are the details</p>
|
||||
<br/>
|
||||
<span style="color: #555; font-size: 13px;">Best regards,</span><br/>
|
||||
|
||||
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
||||
});
|
||||
|
||||
// Items: [List of Purchased Items]
|
||||
// Total Amount: [Total Amount]
|
||||
// Shipping Address: [Shipping Address]
|
||||
|
||||
// We'll keep you updated on the shipping progress. Thanks for choosing Smellika!
|
||||
|
||||
// Best regards
|
||||
// Team Smellika
|
||||
console.log(
|
||||
"event.data.object",
|
||||
event.data.object,
|
||||
"---------------------"
|
||||
);
|
||||
|
||||
console.log(`💰 Payment status: ${event.data.object?.payment_status}`);
|
||||
|
||||
// Saving the payment details in the database
|
||||
// const payment = await Payment.create({
|
||||
// customer_email: event.data.object.customer_email,
|
||||
// amount: event.data.object.amount_total / 100,
|
||||
// paymentId: event.data.object.id,
|
||||
// paymentStatus: event.data.object.payment_status,
|
||||
// createdAt: event.data.object.created,
|
||||
// });
|
||||
}
|
||||
// if (event.type === "checkout.session.completed") {
|
||||
// console.log("dddddddddddd", event.data);
|
||||
// console.log("event.data.object", event.data.object);
|
||||
// console.log(`💰 Payment status: ${event.data.object?.payment_status}`);
|
||||
// payment_intent.payment_failed;
|
||||
|
||||
// // Saving the payment details in the database
|
||||
// // const payment = await Payment.create({
|
||||
// // customer_email: event.data.object.customer_email,
|
||||
// // amount: event.data.object.amount_total / 100,
|
||||
// // paymentId: event.data.object.id,
|
||||
// // paymentStatus: event.data.object.payment_status,
|
||||
// // createdAt: event.data.object.created,
|
||||
// // });
|
||||
// }
|
||||
|
||||
// Return a 200 res to acknowledge receipt of the event
|
||||
res.status(200).end();
|
||||
// res.send().end();
|
||||
};
|
@ -44,7 +44,7 @@ const orderSchema = new mongoose.Schema(
|
||||
trim: true,
|
||||
// Add a regular expression to enforce a specific postal code format
|
||||
// For example, assuming a 5-digit format for the United States
|
||||
match: /^\d{5}$/,
|
||||
match: /^\d{6}$/,
|
||||
},
|
||||
country: {
|
||||
type: String,
|
||||
@ -73,16 +73,10 @@ const orderSchema = new mongoose.Schema(
|
||||
},
|
||||
image: [{}],
|
||||
|
||||
price_With_Tax: {
|
||||
product_Subtotal: {
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
|
||||
taxId: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
|
||||
product: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "Product",
|
||||
@ -126,8 +120,8 @@ const orderSchema = new mongoose.Schema(
|
||||
// default: "new",
|
||||
},
|
||||
|
||||
paypal_payer_id: { type: String },
|
||||
paypal_payment_id: { type: String },
|
||||
// paypal_payer_id: { type: String },
|
||||
stripe_payment_id: { type: String },
|
||||
// paypal_signature: { type: String },
|
||||
// order_used: { type: Boolean, default: false },
|
||||
isDelivered: { type: Boolean, required: true, default: false },
|
||||
|
@ -1,3 +1,4 @@
|
||||
import bodyParser from "body-parser";
|
||||
import {
|
||||
deleteOneOrder,
|
||||
getAllOrder,
|
||||
@ -12,12 +13,29 @@ import {
|
||||
createOrderCheckout,
|
||||
getClientId,
|
||||
} from "./CheckoutController.js";
|
||||
|
||||
const app = express();
|
||||
|
||||
// Configure bodyParser to parse the raw request body as a buffer
|
||||
app.use(bodyParser.raw({ type: "application/json" }));
|
||||
import { handlePayment, webhook } from "./StripeCheckOutController.js";
|
||||
const router = express.Router();
|
||||
//checkout Routes-------------------------//
|
||||
router.route("/checkout/").post(isAuthenticatedUser, createOrderCheckout);
|
||||
router.route("/clientid/get/").get(isAuthenticatedUser, getClientId);
|
||||
router.route("/:orderID/capture/payment").post(captureOrderPayment);
|
||||
// ---------------------------------------------------
|
||||
// ----------------------stripe checkOut-----------------//
|
||||
|
||||
// app.post("/webhook", express.raw({ type: "application/json" }), webhook);
|
||||
router
|
||||
.route("/stripe-checkout-session")
|
||||
.post(isAuthenticatedUser, handlePayment);
|
||||
router
|
||||
.route("/webhook")
|
||||
.post(express.raw({ type: "application/json" }), webhook);
|
||||
|
||||
// --------------------------------------------------
|
||||
//get user self
|
||||
router.route("/user/self").get(isAuthenticatedUser, getUserSelf);
|
||||
|
||||
|
@ -39,6 +39,21 @@ export const registerUser = async (req, res) => {
|
||||
// url: myCloud.secure_url,
|
||||
// },
|
||||
});
|
||||
await sendEmail({
|
||||
to: `${email}`, // Change to your recipient
|
||||
|
||||
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
||||
|
||||
subject: `Welcome to Smellika - Let the Shopping Begin!`,
|
||||
html: ` <h1 style="color: #333; text-align: center; font-family: Arial, sans-serif;">Welcome to Smellika - Let the Shopping Begin!</h1>
|
||||
<strong style="color: #1b03a3; font-size: 16px"> Hey ${name},</strong>
|
||||
|
||||
<p style="color: #555; font-size: 15px;">Welcome to Smellika! We're thrilled to have you on board. Get ready for a world of exclusive deals, exciting products, and seamless shopping experiences. Start exploring now!</p>
|
||||
<br/>
|
||||
<span style="color: #555; font-size: 13px;">Happy shopping,</span><br/>
|
||||
|
||||
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
||||
});
|
||||
sendToken(user, 201, res);
|
||||
} catch (e) {
|
||||
return res.status(400).json({ success: false, message: e.message });
|
||||
|
Loading…
Reference in New Issue
Block a user