razerpay integration
This commit is contained in:
parent
8a7d257b1e
commit
ee5f7f9491
@ -56,15 +56,23 @@ export const checkout = async (req, res) => {
|
||||
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" });
|
||||
}
|
||||
}
|
||||
if (!address)
|
||||
return res
|
||||
.status(404)
|
||||
.json({ message: "please select shipping address!" });
|
||||
if (!subtotal)
|
||||
return res
|
||||
.status(404)
|
||||
.json({ message: "please provide product subtotal!" });
|
||||
// switch (true) {
|
||||
// //validation
|
||||
// case !address: {
|
||||
// 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,
|
||||
@ -77,12 +85,18 @@ export const checkout = async (req, res) => {
|
||||
country: addss.country,
|
||||
addressId: address,
|
||||
};
|
||||
// console.log("cart", cart[0]?.product?.gst);
|
||||
const orderItems = await cart.map((item) => ({
|
||||
product: item.product._id,
|
||||
name: item.product.name,
|
||||
price: item.product.total_amount,
|
||||
price: item.product.price,
|
||||
total_Amount: item.product.total_amount,
|
||||
|
||||
image: item.product.image,
|
||||
quantity: item.quantity,
|
||||
gst_amount: item.product.gst_amount,
|
||||
gst_rate: item.product.gst?.tax,
|
||||
tax_Name: item.product.gst?.name,
|
||||
product_Subtotal: item.subtotal,
|
||||
}));
|
||||
|
||||
@ -130,7 +144,7 @@ export const paymentVerification = async (req, res) => {
|
||||
path: "user",
|
||||
select: "name email -_id",
|
||||
});
|
||||
console.log("findSameOrder", findSameOrder);
|
||||
// console.log("findSameOrder", findSameOrder);
|
||||
if (findSameOrder) {
|
||||
(findSameOrder.razorpay_payment_id = razorpay_payment_id), // await Payment.create({
|
||||
(findSameOrder.isPaid = true),
|
||||
@ -143,7 +157,7 @@ export const paymentVerification = async (req, res) => {
|
||||
await findSameOrder.save();
|
||||
}
|
||||
//send email to customer
|
||||
|
||||
// console.log("findSameOrder", findSameOrder);
|
||||
await sendEmail({
|
||||
to: `${findSameOrder?.user?.email}`, // Change to your recipient
|
||||
|
||||
@ -151,10 +165,84 @@ export const paymentVerification = async (req, res) => {
|
||||
|
||||
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>
|
||||
<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>
|
||||
<br/>
|
||||
<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}</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;">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;"><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="6" 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>`,
|
||||
@ -171,7 +259,7 @@ export const paymentVerification = async (req, res) => {
|
||||
// razorpay_signature,
|
||||
// });
|
||||
|
||||
res.redirect(`http://localhost:5173/account`);
|
||||
res.redirect(`https://smellika.com/shop`);
|
||||
// res.redirect(
|
||||
// `http://localhost:5173/cart/paymentsuccess?reference=${razorpay_payment_id}`
|
||||
// );
|
||||
|
@ -66,6 +66,10 @@ const orderSchema = new mongoose.Schema(
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
total_Amount: {
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
quantity: {
|
||||
type: Number,
|
||||
default: "",
|
||||
@ -77,6 +81,18 @@ const orderSchema = new mongoose.Schema(
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
gst_amount: {
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
gst_rate: {
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
tax_Name: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
product: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "Product",
|
||||
|
Loading…
Reference in New Issue
Block a user