forked from dvjsharma/Drawn2Shoe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dvjsharma#10 from Akashsah2003/master
Payment
- Loading branch information
Showing
6 changed files
with
86 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,49 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import React, { useEffect, useState, useCallback } from "react"; | ||
import axios from "axios"; | ||
import Cartcard from "../../components/Cart-Card"; | ||
import useRazorpay from "react-razorpay"; | ||
|
||
const Cart = () => { | ||
const [cartitems, setCartitems] = useState(); | ||
const [subtotal, setSubtotal] = useState(0); | ||
const [Razorpay, isLoaded] = useRazorpay(); | ||
|
||
const handlePayment = useCallback(() => { | ||
|
||
const options = { | ||
key: "rzp_test_NuTUG6yrfovjY3", | ||
amount: `${subtotal+110}00`, | ||
currency: "INR", | ||
name: "Acme Corp", | ||
description: "Test Transaction", | ||
image: "https://example.com/your_logo", | ||
handler: (res) => { | ||
console.log(res); | ||
}, | ||
prefill: { | ||
name: "Piyush Garg", | ||
email: "[email protected]", | ||
contact: "9999999999", | ||
}, | ||
notes: { | ||
address: "Razorpay Corporate Office", | ||
}, | ||
theme: { | ||
color: "#3399cc", | ||
}, | ||
}; | ||
|
||
const rzpay = new Razorpay(options); | ||
rzpay.open(); | ||
}, [subtotal]); | ||
|
||
useEffect(() => { | ||
if (isLoaded) { | ||
handlePayment(); | ||
} | ||
}, [isLoaded, handlePayment]) | ||
|
||
|
||
let toDisplay = []; | ||
useEffect(() => { | ||
const fetchcart = async () => { | ||
|
@@ -24,6 +64,18 @@ const Cart = () => { | |
fetchcart(); | ||
}, []) | ||
|
||
if (cartitems) { | ||
let ntotal = 0; | ||
for (let index = 0; index < cartitems.length; index++) { | ||
|
||
ntotal = ntotal + parseInt(cartitems[index].price); | ||
} | ||
if (subtotal != ntotal) | ||
{ | ||
setSubtotal(ntotal); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
if (cartitems) | ||
{ | ||
|
@@ -153,25 +205,25 @@ const Cart = () => { | |
<div className="mt-6 h-full rounded-lg border bg-white p-6 shadow-md md:mt-0 md:w-1/3"> | ||
<div className="mb-2 flex justify-between"> | ||
<p className="text-gray-700">Subtotal</p> | ||
<p className="text-gray-700">$129.99</p> | ||
<p className="text-gray-700">₹ {subtotal}</p> | ||
</div> | ||
<div className="flex justify-between"> | ||
<p className="text-gray-700">Shipping</p> | ||
<p className="text-gray-700">$4.99</p> | ||
<p className="text-gray-700">₹ 110</p> | ||
</div> | ||
<hr className="my-4" /> | ||
<div className="flex justify-between"> | ||
<p className="text-lg font-bold">Total</p> | ||
<div className=""> | ||
<p className="mb-1 text-lg font-bold"> | ||
$134.98 USD | ||
₹ {subtotal + 110} INR | ||
</p> | ||
<p className="text-sm text-gray-700"> | ||
including VAT | ||
</p> | ||
</div> | ||
</div> | ||
<button className="mt-6 w-full rounded-md bg-blue-500 py-1.5 font-medium text-blue-50 hover:bg-blue-600"> | ||
<button className="mt-6 w-full rounded-md bg-blue-500 py-1.5 font-medium text-blue-50 hover:bg-blue-600" onClick={handlePayment}> | ||
Check out | ||
</button> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import express from "express"; | ||
import { getcart } from "../controllers/cart.js"; | ||
import { getcart, addcart } from "../controllers/cart.js"; | ||
import { isAuthenticated } from "../middlewares/auth.js"; | ||
|
||
const router = express.Router(); | ||
|
||
|
||
router.get('/', isAuthenticated, getcart); | ||
|
||
router.post('/add', isAuthenticated, addcart); | ||
|
||
|
||
export default router; |