resolved conflicts
This commit is contained in:
commit
539316a953
10
.env
10
.env
@ -12,12 +12,12 @@ CLOUDINARY_API_KEY = "877544192441588"
|
|||||||
CLOUDINARY_API_SECRET = "9paejuSC-fY5b0WoaUuSFURSnvM"
|
CLOUDINARY_API_SECRET = "9paejuSC-fY5b0WoaUuSFURSnvM"
|
||||||
WEBHOOK_SECRET_KEY="whsec_m9u7CFBCY1qWarhxq65CkII6egOBf20K"
|
WEBHOOK_SECRET_KEY="whsec_m9u7CFBCY1qWarhxq65CkII6egOBf20K"
|
||||||
|
|
||||||
STRIPE_SECRET_KEY="sk_test_51OhPRdSG6gbAOwcEid1GavJ4FTD0ZuHVTferdvJwKal77RlMtFJGBzL5GjtL0ie8ZJztsGjUWi8DWrnw1pDdDRGS005Hk0ahql"
|
# STRIPE_SECRET_KEY="sk_test_51OhPRdSG6gbAOwcEid1GavJ4FTD0ZuHVTferdvJwKal77RlMtFJGBzL5GjtL0ie8ZJztsGjUWi8DWrnw1pDdDRGS005Hk0ahql"
|
||||||
STRIPE_WEBHOOK_SECRET="whsec_dc9b9084fc764c806c8c5c06dd91de1ee809e9c8deab6d56e8e3ef2fc9c30c67"
|
# STRIPE_WEBHOOK_SECRET="whsec_dc9b9084fc764c806c8c5c06dd91de1ee809e9c8deab6d56e8e3ef2fc9c30c67"
|
||||||
<<<<<<< HEAD
|
|
||||||
FRONTEND_URL="http://127.0.0.1:5173"
|
FRONTEND_URL="http://127.0.0.1:5173"
|
||||||
RAZERPAY_KEY_ID="rzp_test_smzQmWoS64S2W9"
|
RAZERPAY_KEY_ID="rzp_test_2rg1Bq3Ki8xw9e"
|
||||||
RAZERPAY_SECRET_KEY="cSn6MgA4xSEaZBpPp4zpDA3C"
|
RAZERPAY_SECRET_KEY="WFhHbXL7AlLIuull9kKjYiNA"
|
||||||
FRONTEND_URL="https://smellika.com"
|
FRONTEND_URL="https://smellika.com"
|
||||||
|
|
||||||
|
|
||||||
|
4
app.js
4
app.js
@ -171,7 +171,7 @@ import CouponRoute from "./resources/Affiliate&Coupon/Coupon/CouponRoute.js";
|
|||||||
// import ShortUrlRouter from "./resources/Businesses/Short_Urls/ShortUrlRoute.js";
|
// import ShortUrlRouter from "./resources/Businesses/Short_Urls/ShortUrlRoute.js";
|
||||||
//support Ticket
|
//support Ticket
|
||||||
import SupportRouter from "./resources/Supports/supportRoute.js";
|
import SupportRouter from "./resources/Supports/supportRoute.js";
|
||||||
import RegisterEmail from "./resources/EmailCMS/RegisterEmail/RegisterEmailRoutes.js";
|
// Point of Sale
|
||||||
app.use("/api/v1/", user);
|
app.use("/api/v1/", user);
|
||||||
|
|
||||||
//Product
|
//Product
|
||||||
@ -239,6 +239,6 @@ app.use("/api/panel", PanelRoute);
|
|||||||
//Support
|
//Support
|
||||||
|
|
||||||
// Email CMS
|
// Email CMS
|
||||||
app.use("/api", RegisterEmail);
|
// app.use("/api", RegisterEmail);
|
||||||
app.use("/api", SupportRouter);
|
app.use("/api", SupportRouter);
|
||||||
export default app;
|
export default app;
|
||||||
|
@ -110,7 +110,6 @@ export const isFranchiAuthenticated = async (req, res, next) => {
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
export const authorizeRoles = (...roles) => {
|
export const authorizeRoles = (...roles) => {
|
||||||
console.log("this is the roles ", roles);
|
|
||||||
//pass admin
|
//pass admin
|
||||||
return (req, res, next) => {
|
return (req, res, next) => {
|
||||||
if (!roles.includes(req.user.role)) {
|
if (!roles.includes(req.user.role)) {
|
||||||
|
9
package-lock.json
generated
9
package-lock.json
generated
@ -5417,7 +5417,8 @@
|
|||||||
"cloudinary-core": {
|
"cloudinary-core": {
|
||||||
"version": "2.12.3",
|
"version": "2.12.3",
|
||||||
"resolved": "https://registry.npmjs.org/cloudinary-core/-/cloudinary-core-2.12.3.tgz",
|
"resolved": "https://registry.npmjs.org/cloudinary-core/-/cloudinary-core-2.12.3.tgz",
|
||||||
"integrity": "sha512-Ll4eDzcrIVn4zCttMh3Mdi+KNz07p5EEjBT2PQSRx8Eok1lKPt3uBBenOk/w88RKK3B8SFIWcEe/mN4BHQ0p8A=="
|
"integrity": "sha512-Ll4eDzcrIVn4zCttMh3Mdi+KNz07p5EEjBT2PQSRx8Eok1lKPt3uBBenOk/w88RKK3B8SFIWcEe/mN4BHQ0p8A==",
|
||||||
|
"requires": {}
|
||||||
},
|
},
|
||||||
"color-convert": {
|
"color-convert": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
@ -6660,7 +6661,8 @@
|
|||||||
"multer-storage-cloudinary": {
|
"multer-storage-cloudinary": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/multer-storage-cloudinary/-/multer-storage-cloudinary-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/multer-storage-cloudinary/-/multer-storage-cloudinary-4.0.0.tgz",
|
||||||
"integrity": "sha512-25lm9R6o5dWrHLqLvygNX+kBOxprzpmZdnVKH4+r68WcfCt8XV6xfQaMuAg+kUE5Xmr8mJNA4gE0AcBj9FJyWA=="
|
"integrity": "sha512-25lm9R6o5dWrHLqLvygNX+kBOxprzpmZdnVKH4+r68WcfCt8XV6xfQaMuAg+kUE5Xmr8mJNA4gE0AcBj9FJyWA==",
|
||||||
|
"requires": {}
|
||||||
},
|
},
|
||||||
"mute-stream": {
|
"mute-stream": {
|
||||||
"version": "0.0.8",
|
"version": "0.0.8",
|
||||||
@ -7893,7 +7895,8 @@
|
|||||||
"ws": {
|
"ws": {
|
||||||
"version": "7.4.6",
|
"version": "7.4.6",
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz",
|
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz",
|
||||||
"integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A=="
|
"integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==",
|
||||||
|
"requires": {}
|
||||||
},
|
},
|
||||||
"xregexp": {
|
"xregexp": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
|
225
resources/Orders/PosCheckoutController.js
Normal file
225
resources/Orders/PosCheckoutController.js
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
import { shippingAddress } from "../ShippingAddresses/ShippingAddressModel.js";
|
||||||
|
import { Order } from "./orderModel.js";
|
||||||
|
|
||||||
|
import sendEmail from "../../Utils/sendEmail.js";
|
||||||
|
//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 poscreateOrderCheckout = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { userr, address, cart, subtotal, orderType } = req.body;
|
||||||
|
|
||||||
|
// Perform validation
|
||||||
|
if (cart.length < 1)
|
||||||
|
return res.status(400).json({ message: "Cart is empty!" });
|
||||||
|
if (!address)
|
||||||
|
return res
|
||||||
|
.status(404)
|
||||||
|
.json({ message: "Please select a shipping address!" });
|
||||||
|
if (!subtotal)
|
||||||
|
return res
|
||||||
|
.status(404)
|
||||||
|
.json({ message: "Please provide the product subtotal!" });
|
||||||
|
if (!userr) return res.status(400).json({ message: "User is not defined" });
|
||||||
|
|
||||||
|
// Retrieve shipping address from database
|
||||||
|
let addss = await shippingAddress.findById(address);
|
||||||
|
|
||||||
|
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,
|
||||||
|
company_name: addss?.company_name,
|
||||||
|
gst_number: addss?.gst_number,
|
||||||
|
addressId: address,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Construct order items array
|
||||||
|
const orderItems = cart.map((item) => ({
|
||||||
|
product: item.product._id,
|
||||||
|
name: item.product.name,
|
||||||
|
variant_Name: item.variant.variant_Name,
|
||||||
|
price: Number(item.variant.price),
|
||||||
|
total_price: item.quantity * Number(item.variant.price),
|
||||||
|
image: item.product.image,
|
||||||
|
quantity: item.quantity,
|
||||||
|
gst_amount: Number(
|
||||||
|
(Number(item.variant.price) * item.variant.gst_Id?.tax) / 100
|
||||||
|
)?.toFixed(3),
|
||||||
|
total_gst_amount: Number(
|
||||||
|
Number(item.quantity) *
|
||||||
|
Number((Number(item.variant.price) * item.variant.gst_Id?.tax) / 100)
|
||||||
|
)?.toFixed(3),
|
||||||
|
gst_rate: item.variant.gst_Id?.tax,
|
||||||
|
tax_Name: item.variant?.gst_Id?.name,
|
||||||
|
product_Subtotal: Number(
|
||||||
|
Number(item.quantity * Number(item.variant.price)) +
|
||||||
|
Number(
|
||||||
|
Number(item.quantity) *
|
||||||
|
Number(
|
||||||
|
(Number(item.variant.price) * item.variant.gst_Id?.tax) / 100
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).toFixed(3),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Generate a unique order ID
|
||||||
|
const Id = await generateUniqueOrderId();
|
||||||
|
|
||||||
|
// Create the order document
|
||||||
|
const order = await Order.create({
|
||||||
|
orderID: Id,
|
||||||
|
total_amount: subtotal,
|
||||||
|
orderItems,
|
||||||
|
shippingInfo: shipping,
|
||||||
|
user: userr,
|
||||||
|
orderType,
|
||||||
|
paymentMode: "cod",
|
||||||
|
payment_status: "success",
|
||||||
|
isPaid: true,
|
||||||
|
paidAt: new Date().toISOString(),
|
||||||
|
});
|
||||||
|
// console.log(order);
|
||||||
|
// Find the user associated with the order
|
||||||
|
const orderWithUser = await Order.findById(order._id).populate("user");
|
||||||
|
|
||||||
|
if (!orderWithUser) {
|
||||||
|
return res
|
||||||
|
.status(404)
|
||||||
|
.json({ success: false, message: "Order not found" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = orderWithUser.user;
|
||||||
|
const userEmail = user.email;
|
||||||
|
|
||||||
|
// Send email after order creation
|
||||||
|
await sendEmail({
|
||||||
|
to: userEmail,
|
||||||
|
from: `${process.env.SEND_EMAIL_FROM}`,
|
||||||
|
subject: `Your Order #${order?.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 ${
|
||||||
|
order?.shippingInfo?.first_Name
|
||||||
|
},</strong>
|
||||||
|
|
||||||
|
<p style="color: #555; font-size: 15px;">Great news! Your order #${
|
||||||
|
order?.orderID
|
||||||
|
} has been confirmed. Here are the details</p>
|
||||||
|
<h4 style="color: #333; font-family: Arial, sans-serif;">Shipping Address : ${
|
||||||
|
order?.shippingInfo?.first_Name
|
||||||
|
} ${order?.shippingInfo?.last_Name} , ${order?.shippingInfo?.street} ${
|
||||||
|
order?.shippingInfo?.city
|
||||||
|
} ${order?.shippingInfo?.state} ${order?.shippingInfo?.country}, PIN-${
|
||||||
|
order?.shippingInfo?.postalCode
|
||||||
|
}, Phone Number: ${order?.shippingInfo?.phone_Number}
|
||||||
|
${
|
||||||
|
order?.shippingInfo?.company_name
|
||||||
|
? ",Company Name :" + order?.shippingInfo?.company_name + ""
|
||||||
|
: ""
|
||||||
|
} ${
|
||||||
|
order?.shippingInfo?.gst_number
|
||||||
|
? ", GST_NO:" + order?.shippingInfo?.gst_number
|
||||||
|
: ""
|
||||||
|
}</h4>
|
||||||
|
<h4 style="color: #333; font-family: Arial, sans-serif;">Order Items :</h4>
|
||||||
|
<table style="border-collapse: collapse; width: 100%;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||||
|
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Variant</th>
|
||||||
|
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||||
|
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
||||||
|
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">SubTotal</th>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
${order?.orderItems
|
||||||
|
?.map(
|
||||||
|
(product, index) => `
|
||||||
|
<tr>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
|
index + 1
|
||||||
|
}</td>
|
||||||
|
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
|
product.name
|
||||||
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
|
product?.variant_Name
|
||||||
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||||
|
product?.image[0]?.url
|
||||||
|
}" alt="${
|
||||||
|
product.name
|
||||||
|
}" style="max-width: 40px; height: auto;"></td>
|
||||||
|
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
|
product.quantity
|
||||||
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||||
|
product.price
|
||||||
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||||
|
product?.gst_amount
|
||||||
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||||
|
product?.product_Subtotal
|
||||||
|
}</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
`
|
||||||
|
)
|
||||||
|
.join("")}
|
||||||
|
<tr>
|
||||||
|
<th colspan="7" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||||
|
order?.total_amount
|
||||||
|
}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<span style="color: #555; font-size: 13px;">Best regards,</span><br/>
|
||||||
|
|
||||||
|
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(201).json({ success: true, order });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error creating order:", error);
|
||||||
|
return res
|
||||||
|
.status(500)
|
||||||
|
.json({ success: false, message: "Internal server error" });
|
||||||
|
}
|
||||||
|
};
|
@ -31,6 +31,8 @@ const generateUniqueOrderId = async () => {
|
|||||||
|
|
||||||
export const getRzpkey = async (req, res) => {
|
export const getRzpkey = async (req, res) => {
|
||||||
const { name, email } = req.user;
|
const { name, email } = req.user;
|
||||||
|
// console.log(name);
|
||||||
|
// console.log(email);
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
key: process.env.RAZERPAY_KEY_ID,
|
key: process.env.RAZERPAY_KEY_ID,
|
||||||
@ -38,22 +40,36 @@ export const getRzpkey = async (req, res) => {
|
|||||||
email,
|
email,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
//point of sale order
|
||||||
|
export const getRazerpayKey = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { name, email } = req.params;
|
||||||
|
// console.log("name", name, "email", email);
|
||||||
|
if (!name || !email) {
|
||||||
|
throw new Error("Name and email are required parameters");
|
||||||
|
}
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
key: process.env.RAZERPAY_KEY_ID,
|
||||||
|
name,
|
||||||
|
email,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error in getRzpKey:", error);
|
||||||
|
res
|
||||||
|
.status(500)
|
||||||
|
.json({
|
||||||
|
success: false,
|
||||||
|
message: error.message || "Internal server error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const checkout = async (req, res) => {
|
export const checkout = async (req, res) => {
|
||||||
// console.log(req.body.subtotal);
|
try {
|
||||||
const options = {
|
const { userr,address, cart, subtotal,orderType } = req.body;
|
||||||
amount: Number(req.body.subtotal * 100),
|
// console.log(req.body.cart[0].product);
|
||||||
currency: "INR",
|
// console.log(req.body.cart[0].variant);
|
||||||
};
|
|
||||||
const order = await instance.orders.create(options);
|
|
||||||
// id: "order_Ns423uPG0r36Dk";
|
|
||||||
|
|
||||||
//save order in database
|
|
||||||
|
|
||||||
if (order?.id) {
|
|
||||||
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)
|
if (cart.length < 1)
|
||||||
return res.status(400).json({ message: "cart is empty!" });
|
return res.status(400).json({ message: "cart is empty!" });
|
||||||
if (!address)
|
if (!address)
|
||||||
@ -64,63 +80,103 @@ export const checkout = async (req, res) => {
|
|||||||
return res
|
return res
|
||||||
.status(404)
|
.status(404)
|
||||||
.json({ message: "please provide product subtotal!" });
|
.json({ message: "please provide product subtotal!" });
|
||||||
// switch (true) {
|
const options = {
|
||||||
// //validation
|
amount: Number(req.body.subtotal * 100),
|
||||||
// case !address: {
|
currency: "INR",
|
||||||
// return res.status(404).json({ msg: "please select shipping address" });
|
|
||||||
// }
|
|
||||||
// case !subtotal: {
|
|
||||||
// return res.status(404).json({ msg: "please provide product subtotal" });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
let addss = await shippingAddress.findById(address);
|
|
||||||
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,
|
|
||||||
};
|
};
|
||||||
// console.log("cart", cart[0]?.product?.gst);
|
// Determine the user ID
|
||||||
const orderItems = await cart.map((item) => ({
|
let User;
|
||||||
product: item.product._id,
|
if (userr) {
|
||||||
name: item.product.name,
|
User = userr; // Use provided user ID
|
||||||
price: item.product.price,
|
} else {
|
||||||
total_Amount: item.product.total_amount,
|
User = req.user._id; // Use authenticated user ID
|
||||||
|
}
|
||||||
|
// console.log(User);
|
||||||
|
const order = await instance.orders.create(options);
|
||||||
|
// console.log(order);
|
||||||
|
//save order in database
|
||||||
|
if (order?.id) {
|
||||||
|
// const { email } = req.user;
|
||||||
|
// if (!email)
|
||||||
|
// return res.status(400).send({ message: "Please enter the email" });
|
||||||
|
let addss = await shippingAddress.findById(address);
|
||||||
|
|
||||||
image: item.product.image,
|
let shipping = {
|
||||||
quantity: item.quantity,
|
first_Name: addss.first_Name,
|
||||||
gst_amount: item.product.gst_amount,
|
last_Name: addss?.last_Name,
|
||||||
gst_rate: item.product.gst?.tax,
|
phone_Number: addss?.phone_Number,
|
||||||
tax_Name: item.product.gst?.name,
|
street: addss?.street,
|
||||||
product_Subtotal: item.subtotal,
|
city: addss?.city,
|
||||||
}));
|
state: addss?.state,
|
||||||
|
postalCode: addss?.postalCode,
|
||||||
|
country: addss?.country,
|
||||||
|
company_name: addss?.company_name,
|
||||||
|
gst_number: addss?.gst_number,
|
||||||
|
addressId: address,
|
||||||
|
};
|
||||||
|
// console.log("cart", cart[0]?.product?.gst);
|
||||||
|
const orderItems = await cart.map((item) => ({
|
||||||
|
product: item.product._id,
|
||||||
|
name: item.product.name,
|
||||||
|
variant_Name: item.variant.variant_Name,
|
||||||
|
price: Number(item.variant.price),
|
||||||
|
total_price: item.quantity * Number(item.variant.price),
|
||||||
|
|
||||||
// console.log("line", lineItems[0]);
|
image: item.product.image,
|
||||||
const Id = await generateUniqueOrderId();
|
quantity: item.quantity,
|
||||||
const orders = await Order.create({
|
gst_amount: Number(
|
||||||
orderID: Id,
|
(Number(item.variant.price) * item.variant.gst_Id?.tax) / 100
|
||||||
total_amount: subtotal,
|
)?.toFixed(3),
|
||||||
orderItems,
|
total_gst_amount: Number(
|
||||||
shippingInfo: shipping,
|
Number(item.quantity) *
|
||||||
user: req.user._id,
|
Number(
|
||||||
razorpay_order_id: order?.id,
|
(Number(item.variant.price) * item.variant.gst_Id?.tax) / 100
|
||||||
|
)
|
||||||
|
)?.toFixed(3),
|
||||||
|
gst_rate: item.variant.gst_Id?.tax,
|
||||||
|
tax_Name: item.variant?.gst_Id?.name,
|
||||||
|
product_Subtotal: Number(
|
||||||
|
Number(item.quantity * Number(item.variant.price)) +
|
||||||
|
Number(
|
||||||
|
Number(item.quantity) *
|
||||||
|
Number(
|
||||||
|
(Number(item.variant.price) * item.variant.gst_Id?.tax) / 100
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).toFixed(3),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// console.log("Order", orderItems[0]);
|
||||||
|
const Id = await generateUniqueOrderId();
|
||||||
|
const orders = await Order.create({
|
||||||
|
orderID: Id,
|
||||||
|
total_amount: subtotal,
|
||||||
|
orderItems,
|
||||||
|
shippingInfo: shipping,
|
||||||
|
user: User,
|
||||||
|
razorpay_order_id: order?.id,
|
||||||
|
orderType,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
message: "Failled to order Create",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
order,
|
||||||
});
|
});
|
||||||
} else {
|
} catch (error) {
|
||||||
res.status(400).json({
|
console.log("error", error);
|
||||||
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
message: "Failled to order Create",
|
message: error?.description
|
||||||
|
? "Razorpay" + error?.description
|
||||||
|
: "Something went wrong!",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).json({
|
|
||||||
success: true,
|
|
||||||
order,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const paymentVerification = async (req, res) => {
|
export const paymentVerification = async (req, res) => {
|
||||||
@ -180,7 +236,16 @@ export const paymentVerification = async (req, res) => {
|
|||||||
findSameOrder?.shippingInfo?.state
|
findSameOrder?.shippingInfo?.state
|
||||||
} ${findSameOrder?.shippingInfo?.country}, PIN-${
|
} ${findSameOrder?.shippingInfo?.country}, PIN-${
|
||||||
findSameOrder?.shippingInfo?.postalCode
|
findSameOrder?.shippingInfo?.postalCode
|
||||||
}, Phone Number: ${findSameOrder?.shippingInfo?.phone_Number}</h4>
|
}, Phone Number: ${findSameOrder?.shippingInfo?.phone_Number}
|
||||||
|
${
|
||||||
|
findSameOrder?.shippingInfo?.company_name
|
||||||
|
? ",Company Name :" + findSameOrder?.shippingInfo?.company_name + ""
|
||||||
|
: ""
|
||||||
|
} ${
|
||||||
|
findSameOrder?.shippingInfo?.gst_number
|
||||||
|
? ", GST_NO:" + findSameOrder?.shippingInfo?.gst_number
|
||||||
|
: ""
|
||||||
|
}</h4>
|
||||||
<h4 style="color: #333; font-family: Arial, sans-serif;">Order Items :</h4>
|
<h4 style="color: #333; font-family: Arial, sans-serif;">Order Items :</h4>
|
||||||
<table style="border-collapse: collapse; width: 100%;">
|
<table style="border-collapse: collapse; width: 100%;">
|
||||||
<thead>
|
<thead>
|
||||||
@ -188,6 +253,8 @@ export const paymentVerification = async (req, res) => {
|
|||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||||
|
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Variant</th>
|
||||||
|
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||||
|
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||||
@ -210,6 +277,9 @@ export const paymentVerification = async (req, res) => {
|
|||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
product.name
|
product.name
|
||||||
}</td>
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
|
product?.variant_Name
|
||||||
|
}</td>
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||||
product?.image[0]?.url
|
product?.image[0]?.url
|
||||||
}" alt="${
|
}" alt="${
|
||||||
@ -226,7 +296,7 @@ export const paymentVerification = async (req, res) => {
|
|||||||
product?.gst_amount
|
product?.gst_amount
|
||||||
}</td>
|
}</td>
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||||
product.product_Subtotal
|
product?.product_Subtotal
|
||||||
}</td>
|
}</td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
@ -234,7 +304,7 @@ export const paymentVerification = async (req, res) => {
|
|||||||
)
|
)
|
||||||
.join("")}
|
.join("")}
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
<th colspan="7" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||||
findSameOrder?.total_amount
|
findSameOrder?.total_amount
|
||||||
}</td>
|
}</td>
|
||||||
@ -269,6 +339,167 @@ export const paymentVerification = async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// point of sale payment varification
|
||||||
|
export const pospaymentVerification = async (req, res) => {
|
||||||
|
const { razorpay_order_id, razorpay_payment_id, razorpay_signature } =
|
||||||
|
req.body;
|
||||||
|
|
||||||
|
const body = razorpay_order_id + "|" + razorpay_payment_id;
|
||||||
|
|
||||||
|
const expectedSignature = crypto
|
||||||
|
.createHmac("sha256", process.env.RAZERPAY_SECRET_KEY)
|
||||||
|
.update(body.toString())
|
||||||
|
.digest("hex");
|
||||||
|
|
||||||
|
const isAuthentic = expectedSignature === razorpay_signature;
|
||||||
|
|
||||||
|
if (isAuthentic) {
|
||||||
|
// Database comes here
|
||||||
|
let findSameOrder = await Order.findOne({
|
||||||
|
razorpay_order_id: razorpay_order_id,
|
||||||
|
}).populate({
|
||||||
|
path: "user",
|
||||||
|
select: "name email -_id",
|
||||||
|
});
|
||||||
|
// console.log("findSameOrder", findSameOrder);
|
||||||
|
if (findSameOrder) {
|
||||||
|
(findSameOrder.razorpay_payment_id = razorpay_payment_id), // await Payment.create({
|
||||||
|
(findSameOrder.isPaid = true),
|
||||||
|
(findSameOrder.paidAt = Date.now()),
|
||||||
|
(findSameOrder.razorpay_signature = razorpay_signature);
|
||||||
|
// await Payment.create({
|
||||||
|
findSameOrder.payment_status = "success";
|
||||||
|
|
||||||
|
findSameOrder.orderStatus = "new";
|
||||||
|
await findSameOrder.save();
|
||||||
|
}
|
||||||
|
//send email to customer
|
||||||
|
// console.log("findSameOrder", findSameOrder);
|
||||||
|
await sendEmail({
|
||||||
|
to: `${findSameOrder?.user?.email}`, // Change to your recipient
|
||||||
|
|
||||||
|
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
||||||
|
|
||||||
|
subject: `Your Order #${findSameOrder?.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 ${
|
||||||
|
findSameOrder?.shippingInfo?.first_Name
|
||||||
|
},</strong>
|
||||||
|
|
||||||
|
<p style="color: #555; font-size: 15px;">Great news! Your order #${
|
||||||
|
findSameOrder?.orderID
|
||||||
|
} has been confirmed. Here are the details</p>
|
||||||
|
<h4 style="color: #333; font-family: Arial, sans-serif;">Shipping Address : ${
|
||||||
|
findSameOrder?.shippingInfo?.first_Name
|
||||||
|
} ${findSameOrder?.shippingInfo?.last_Name} , ${
|
||||||
|
findSameOrder?.shippingInfo?.street
|
||||||
|
} ${findSameOrder?.shippingInfo?.city} ${
|
||||||
|
findSameOrder?.shippingInfo?.state
|
||||||
|
} ${findSameOrder?.shippingInfo?.country}, PIN-${
|
||||||
|
findSameOrder?.shippingInfo?.postalCode
|
||||||
|
}, Phone Number: ${findSameOrder?.shippingInfo?.phone_Number}
|
||||||
|
${
|
||||||
|
findSameOrder?.shippingInfo?.company_name
|
||||||
|
? ",Company Name :" + findSameOrder?.shippingInfo?.company_name + ""
|
||||||
|
: ""
|
||||||
|
} ${
|
||||||
|
findSameOrder?.shippingInfo?.gst_number
|
||||||
|
? ", GST_NO:" + findSameOrder?.shippingInfo?.gst_number
|
||||||
|
: ""
|
||||||
|
}</h4>
|
||||||
|
<h4 style="color: #333; font-family: Arial, sans-serif;">Order Items :</h4>
|
||||||
|
<table style="border-collapse: collapse; width: 100%;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||||
|
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Variant</th>
|
||||||
|
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||||
|
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
||||||
|
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">SubTotal</th>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
${findSameOrder?.orderItems
|
||||||
|
?.map(
|
||||||
|
(product, index) => `
|
||||||
|
<tr>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
|
index + 1
|
||||||
|
}</td>
|
||||||
|
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
|
product.name
|
||||||
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
|
product?.variant_Name
|
||||||
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||||
|
product?.image[0]?.url
|
||||||
|
}" alt="${
|
||||||
|
product.name
|
||||||
|
}" style="max-width: 40px; height: auto;"></td>
|
||||||
|
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
|
product.quantity
|
||||||
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||||
|
product.price
|
||||||
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||||
|
product?.gst_amount
|
||||||
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||||
|
product?.product_Subtotal
|
||||||
|
}</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
`
|
||||||
|
)
|
||||||
|
.join("")}
|
||||||
|
<tr>
|
||||||
|
<th colspan="7" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||||
|
findSameOrder?.total_amount
|
||||||
|
}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<span style="color: #555; font-size: 13px;">Best regards,</span><br/>
|
||||||
|
|
||||||
|
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
||||||
|
});
|
||||||
|
// console.log("findSameOrder", findSameOrder);
|
||||||
|
|
||||||
|
// // findSameOrder.razorpay_payment_id=razorpay_payment_id,// await Payment.create({
|
||||||
|
// findOrder.paidAt = new Date(event.data.object.created * 1000);
|
||||||
|
// findOrder.isPaid = true;
|
||||||
|
|
||||||
|
// razorpay_signature: { type: String },
|
||||||
|
// razorpay_order_id,
|
||||||
|
// razorpay_payment_id,
|
||||||
|
// razorpay_signature,
|
||||||
|
// });
|
||||||
|
|
||||||
|
res.redirect(`https://admin.smellika.com/#/pos`);
|
||||||
|
// res.redirect(`http://localhost:3000/#/pos`);
|
||||||
|
} else {
|
||||||
|
res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const handlePayment = async (req, res) => {
|
export const handlePayment = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { email } = req.user;
|
const { email } = req.user;
|
||||||
|
@ -176,14 +176,12 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||||
|
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Variant</th>
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||||
|
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
||||||
|
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">SubTotal</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">SubTotal</th>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
@ -199,6 +197,9 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
|
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
product.name
|
product.name
|
||||||
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
|
product?.variant_Name
|
||||||
}</td>
|
}</td>
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||||
product?.image[0]?.url
|
product?.image[0]?.url
|
||||||
@ -224,7 +225,7 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
)
|
)
|
||||||
.join("")}
|
.join("")}
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
<th colspan="7" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||||
order?.total_amount
|
order?.total_amount
|
||||||
}</td>
|
}</td>
|
||||||
@ -267,6 +268,7 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||||
|
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Variant</th>
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||||
|
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||||
@ -288,6 +290,9 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
|
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
product.name
|
product.name
|
||||||
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
|
product?.variant_Name
|
||||||
}</td>
|
}</td>
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||||
product?.image[0]?.url
|
product?.image[0]?.url
|
||||||
@ -313,7 +318,7 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
)
|
)
|
||||||
.join("")}
|
.join("")}
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
<th colspan="7" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||||
order?.total_amount
|
order?.total_amount
|
||||||
}</td>
|
}</td>
|
||||||
@ -383,6 +388,7 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||||
|
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Variant</th>
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||||
|
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||||
@ -404,6 +410,9 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
|
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
product.name
|
product.name
|
||||||
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
|
product?.variant_Name
|
||||||
}</td>
|
}</td>
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||||
product?.image[0]?.url
|
product?.image[0]?.url
|
||||||
@ -429,7 +438,7 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
)
|
)
|
||||||
.join("")}
|
.join("")}
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
<th colspan="7" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||||
order?.total_amount
|
order?.total_amount
|
||||||
}</td>
|
}</td>
|
||||||
@ -470,8 +479,8 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||||
|
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||||
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Variant</th>
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||||
|
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
||||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
||||||
@ -491,6 +500,9 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
|
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
product.name
|
product.name
|
||||||
|
}</td>
|
||||||
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
|
product?.variant_Name
|
||||||
}</td>
|
}</td>
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||||
product?.image[0]?.url
|
product?.image[0]?.url
|
||||||
@ -516,7 +528,7 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
)
|
)
|
||||||
.join("")}
|
.join("")}
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
<th colspan="7" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||||
order?.total_amount
|
order?.total_amount
|
||||||
}</td>
|
}</td>
|
||||||
|
@ -50,6 +50,12 @@ const orderSchema = new mongoose.Schema(
|
|||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
company_name: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
gst_number: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
addressId: {
|
addressId: {
|
||||||
type: mongoose.Schema.ObjectId,
|
type: mongoose.Schema.ObjectId,
|
||||||
ref: "ShippingAddress",
|
ref: "ShippingAddress",
|
||||||
@ -62,11 +68,15 @@ const orderSchema = new mongoose.Schema(
|
|||||||
type: String,
|
type: String,
|
||||||
default: "",
|
default: "",
|
||||||
},
|
},
|
||||||
|
variant_Name: {
|
||||||
|
type: String,
|
||||||
|
default: "",
|
||||||
|
},
|
||||||
price: {
|
price: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: "",
|
default: "",
|
||||||
},
|
},
|
||||||
total_Amount: {
|
total_price: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: "",
|
default: "",
|
||||||
},
|
},
|
||||||
@ -85,6 +95,10 @@ const orderSchema = new mongoose.Schema(
|
|||||||
type: Number,
|
type: Number,
|
||||||
default: "",
|
default: "",
|
||||||
},
|
},
|
||||||
|
total_gst_amount: {
|
||||||
|
type: Number,
|
||||||
|
default: "",
|
||||||
|
},
|
||||||
gst_rate: {
|
gst_rate: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: "",
|
default: "",
|
||||||
@ -110,7 +124,11 @@ const orderSchema = new mongoose.Schema(
|
|||||||
enum: ["online", "cod"],
|
enum: ["online", "cod"],
|
||||||
default: "online",
|
default: "online",
|
||||||
},
|
},
|
||||||
|
orderType: {
|
||||||
|
type: String,
|
||||||
|
enum: ["WebSite", "PointOfSale"],
|
||||||
|
default: "WebSite",
|
||||||
|
},
|
||||||
payment_status: {
|
payment_status: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: ["pending", "success", "failed"],
|
enum: ["pending", "success", "failed"],
|
||||||
|
@ -22,12 +22,17 @@ app.use(bodyParser.raw({ type: "application/json" }));
|
|||||||
import { handlePayment, webhook } from "./StripeCheckOutController.js";
|
import { handlePayment, webhook } from "./StripeCheckOutController.js";
|
||||||
import {
|
import {
|
||||||
checkout,
|
checkout,
|
||||||
|
getRazerpayKey,
|
||||||
getRzpkey,
|
getRzpkey,
|
||||||
paymentVerification,
|
paymentVerification,
|
||||||
|
pospaymentVerification,
|
||||||
} from "./RazerPayCheckoutController.js";
|
} from "./RazerPayCheckoutController.js";
|
||||||
|
import { poscreateOrderCheckout } from "./PosCheckoutController.js";
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
//checkout Routes-------------------------//
|
//checkout Routes-------------------------//
|
||||||
router.route("/checkout/").post(isAuthenticatedUser, createOrderCheckout);
|
router.route("/checkout/").post(isAuthenticatedUser, createOrderCheckout);
|
||||||
|
//checkout Routes-------------------------//
|
||||||
|
router.route("/pos-checkout/").post(isAuthenticatedUser, poscreateOrderCheckout);
|
||||||
router.route("/clientid/get/").get(isAuthenticatedUser, getClientId);
|
router.route("/clientid/get/").get(isAuthenticatedUser, getClientId);
|
||||||
router.route("/:orderID/capture/payment").post(captureOrderPayment);
|
router.route("/:orderID/capture/payment").post(captureOrderPayment);
|
||||||
// ---------------------------------------------------
|
// ---------------------------------------------------
|
||||||
@ -68,10 +73,11 @@ router
|
|||||||
);
|
);
|
||||||
|
|
||||||
//RAZERPAY checkout
|
//RAZERPAY checkout
|
||||||
|
router.route("/getRzpKey/:name/:email").get(isAuthenticatedUser, getRazerpayKey);
|
||||||
router.route("/getRzpKey/").get(isAuthenticatedUser, getRzpkey);
|
router.route("/getRzpKey/").get(isAuthenticatedUser, getRzpkey);
|
||||||
router.route("/Rzpcheckout/").post(isAuthenticatedUser, checkout);
|
router.route("/Rzpcheckout/").post(isAuthenticatedUser, checkout);
|
||||||
router.route("/paymentverification").post(paymentVerification);
|
router.route("/paymentverification").post(paymentVerification);
|
||||||
|
router.route("/pos-paymentverification").post(pospaymentVerification);
|
||||||
// router.route("/product/getAll/").get(getAllProduct)
|
// router.route("/product/getAll/").get(getAllProduct)
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -124,6 +124,8 @@ export const getAllProductAdmin = async (req, res) => {
|
|||||||
$options: "i",
|
$options: "i",
|
||||||
};
|
};
|
||||||
if (req.query?.category) obj.category = req.query.category;
|
if (req.query?.category) obj.category = req.query.category;
|
||||||
|
if (req.query?.FeatureProduct)
|
||||||
|
obj.featured_Product = req.query.FeatureProduct;
|
||||||
const total = await Product.countDocuments(obj);
|
const total = await Product.countDocuments(obj);
|
||||||
const product = await Product.find(obj)
|
const product = await Product.find(obj)
|
||||||
.populate({
|
.populate({
|
||||||
@ -134,6 +136,7 @@ export const getAllProductAdmin = async (req, res) => {
|
|||||||
.skip(PAGE_SIZE * page)
|
.skip(PAGE_SIZE * page)
|
||||||
// .sort("name")
|
// .sort("name")
|
||||||
.sort({
|
.sort({
|
||||||
|
featured_Product: -1,
|
||||||
createdAt: -1,
|
createdAt: -1,
|
||||||
})
|
})
|
||||||
.exec();
|
.exec();
|
||||||
@ -166,6 +169,8 @@ export const getAllProductUser = async (req, res) => {
|
|||||||
$options: "i",
|
$options: "i",
|
||||||
};
|
};
|
||||||
if (req.query?.category) obj.category = req.query.category;
|
if (req.query?.category) obj.category = req.query.category;
|
||||||
|
if (req.query?.FeatureProduct)
|
||||||
|
obj.featured_Product = req.query.FeatureProduct;
|
||||||
obj.product_Status = "Active";
|
obj.product_Status = "Active";
|
||||||
const total = await Product.countDocuments(obj);
|
const total = await Product.countDocuments(obj);
|
||||||
const product = await Product.find(obj)
|
const product = await Product.find(obj)
|
||||||
@ -177,6 +182,7 @@ export const getAllProductUser = async (req, res) => {
|
|||||||
.skip(PAGE_SIZE * page)
|
.skip(PAGE_SIZE * page)
|
||||||
// .sort("name")
|
// .sort("name")
|
||||||
.sort({
|
.sort({
|
||||||
|
featured_Product: -1,
|
||||||
createdAt: -1,
|
createdAt: -1,
|
||||||
})
|
})
|
||||||
.exec();
|
.exec();
|
||||||
@ -230,6 +236,49 @@ export const ChangeProductStatus = async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
//Change Product status
|
||||||
|
export const ChangeFeatueProductStatus = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const data = await Product.findById(req.params.id);
|
||||||
|
if (data) {
|
||||||
|
if (data?.featured_Product === false) {
|
||||||
|
const totalFeatueProduct = await Product.countDocuments({
|
||||||
|
featured_Product: true,
|
||||||
|
});
|
||||||
|
if (totalFeatueProduct > 2) {
|
||||||
|
return res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
msg: "Maximum 3 Featue Product can be..",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let product = await Product.findByIdAndUpdate(
|
||||||
|
req.params.id,
|
||||||
|
{ featured_Product: true },
|
||||||
|
{ new: true } // Return the updated document
|
||||||
|
);
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
msg: "Changed status as Featue Product",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
let product = await Product.findByIdAndUpdate(
|
||||||
|
req.params.id,
|
||||||
|
{ featured_Product: false },
|
||||||
|
{ new: true } // Return the updated document
|
||||||
|
);
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
msg: "Changed status as not Featue Product",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
msg: error.message ? error.message : "Something went wrong!",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
//get One Product
|
//get One Product
|
||||||
export const getOneProduct = async (req, res) => {
|
export const getOneProduct = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
@ -503,14 +552,14 @@ export const deleteProduct = async (req, res) => {
|
|||||||
if (!req.params.id) {
|
if (!req.params.id) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
msg: "Please Provide Product ID!",
|
message: "Please Provide Product ID!",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const getProduct = await Product.findById(req.params.id);
|
const getProduct = await Product.findById(req.params.id);
|
||||||
if (!getProduct) {
|
if (!getProduct) {
|
||||||
return res.status(404).json({
|
return res.status(404).json({
|
||||||
success: false,
|
success: false,
|
||||||
msg: "Product not Found!",
|
message: "Product not Found!",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Deleting Images From Cloudinary
|
// Deleting Images From Cloudinary
|
||||||
@ -528,7 +577,7 @@ export const deleteProduct = async (req, res) => {
|
|||||||
await product.remove();
|
await product.remove();
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: "Product Deleted Successfully!!",
|
message: "Product Deleted Successfully!!",
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
|
@ -38,6 +38,10 @@ const productSchema = new Schema(
|
|||||||
special_instructions: {
|
special_instructions: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
featured_Product: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false, // Initially, products are not featured
|
||||||
|
},
|
||||||
variants: [
|
variants: [
|
||||||
{
|
{
|
||||||
variant_Name: { type: String, default: "" },
|
variant_Name: { type: String, default: "" },
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
getAllProductUser,
|
getAllProductUser,
|
||||||
getAllProductsDevicesFirst,
|
getAllProductsDevicesFirst,
|
||||||
ChangeProductStatus,
|
ChangeProductStatus,
|
||||||
|
ChangeFeatueProductStatus,
|
||||||
} from "./ProductController.js";
|
} from "./ProductController.js";
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||||
@ -30,6 +31,10 @@ router
|
|||||||
|
|
||||||
//change Product status
|
//change Product status
|
||||||
router.route("/product/admin/status/:id").patch(ChangeProductStatus);
|
router.route("/product/admin/status/:id").patch(ChangeProductStatus);
|
||||||
|
router
|
||||||
|
.route("/product/admin/feature_product/status/:id")
|
||||||
|
.patch(ChangeFeatueProductStatus);
|
||||||
|
|
||||||
//get all product user
|
//get all product user
|
||||||
router.route("/product/getAll/user/").get(getAllProductUser);
|
router.route("/product/getAll/user/").get(getAllProductUser);
|
||||||
router
|
router
|
||||||
|
@ -40,11 +40,16 @@ const shippingAddressSchema = new mongoose.Schema(
|
|||||||
},
|
},
|
||||||
company_name: {
|
company_name: {
|
||||||
type: String,
|
type: String,
|
||||||
maxLength: [70, "name cannot exceed 70 characters"],
|
|
||||||
},
|
},
|
||||||
gst_number: {
|
gst_number: {
|
||||||
type: Number,
|
type: String,
|
||||||
maxLength: [15, "name cannot exceed 15 characters"],
|
validate: {
|
||||||
|
validator: function (v) {
|
||||||
|
// Regular expression for Indian GST number validation
|
||||||
|
return /^(\d{2}[A-Z]{5}\d{4}[A-Z]{1}\d[Z]{1}[A-Z\d]{1})$/.test(v);
|
||||||
|
},
|
||||||
|
message: (props) => `${props.value} is not a valid Indian GST number!`,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
default: {
|
default: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
Loading…
Reference in New Issue
Block a user