diff --git a/src/Checkout.js b/src/Checkout.js index 95c0fdf..1f74f1b 100644 --- a/src/Checkout.js +++ b/src/Checkout.js @@ -44,9 +44,6 @@ const Checkout = ({ socketId, transactionSuccess }) => { const [activeAccordion, setActiveAccordion] = useState('QRIS'); - let grandTotal = 0; - let tax = 0; - useEffect(() => { if (!socketId) return; @@ -79,7 +76,6 @@ const Checkout = ({ socketId, transactionSuccess }) => { const result = await response.json(); if (response.ok) { - setValue(result.total_price); if (result.pay_timeout && result.time_now) { const timeout = new Date(result.pay_timeout).getTime(); const now = new Date(result.time_now).getTime(); @@ -87,12 +83,9 @@ const Checkout = ({ socketId, transactionSuccess }) => { setTimeLeft(timeout - now); } + setValue(result.total_price); setQrisData(result.qris_dynamic || null); setTransferData(result); - - grandTotal = result.total_price; - tax = 0; - } else { alert(`Request gagal: ${result?.error || 'Unknown error'}`); } @@ -155,6 +148,10 @@ const Checkout = ({ socketId, transactionSuccess }) => { return () => clearInterval(interval); }, [payTimeout]); + const subtotal = products.reduce((acc, item) => acc + (item.price || 0), 0); + const grandTotal = subtotal; + const tax = 0; + return (
Waktu tersisa: {formatTimeLeft(timeLeft)}
- )} - > - )} {transactionSuccess && (