From ee5f7f94919fc7644b8f45519ac774b1a7329e4a Mon Sep 17 00:00:00 2001 From: pawan-dot <71133473+pawan-dot@users.noreply.github.com> Date: Tue, 2 Apr 2024 18:52:33 +0530 Subject: [PATCH] razerpay integration --- .../Orders/RazerPayCheckoutController.js | 120 +++++++++++++++--- resources/Orders/orderModel.js | 16 +++ 2 files changed, 120 insertions(+), 16 deletions(-) diff --git a/resources/Orders/RazerPayCheckoutController.js b/resources/Orders/RazerPayCheckoutController.js index c39b04f..fe4f436 100644 --- a/resources/Orders/RazerPayCheckoutController.js +++ b/resources/Orders/RazerPayCheckoutController.js @@ -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: `
Great news! Your order #${findSameOrder?.orderID} has been confirmed. Here are the details
-Great news! Your order #${ + findSameOrder?.orderID + } has been confirmed. Here are the details
+S No. | + +Product Name | +Image | + +Quantity | +Price | +GST Amount | + +SubTotal | + +
---|---|---|---|---|---|---|
${ + index + 1 + } | + +${ + product.name + } | +${ + product.quantity + } | +₹${ + product.price + } | +₹${ + product?.gst_amount + } | +₹${ + product.product_Subtotal + } | + +|
Total Amount : | +₹${ + findSameOrder?.total_amount + } | +