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 (
@@ -180,7 +177,7 @@ const Checkout = ({ socketId, transactionSuccess }) => { Item - {grandTotal} + Subtotal @@ -198,7 +195,7 @@ const Checkout = ({ socketId, transactionSuccess }) => {
SUBTOTAL - Rp{grandTotal.toLocaleString('id-ID')} + Rp{subtotal.toLocaleString('id-ID')}
TAX @@ -206,7 +203,7 @@ const Checkout = ({ socketId, transactionSuccess }) => {
Total - Rp{grandTotal.toLocaleString('id-ID')} + Rp{value?.toLocaleString('id-ID')}
@@ -227,14 +224,6 @@ const Checkout = ({ socketId, transactionSuccess }) => { {activeAccordion === 'QRIS' && (
- {!transactionSuccess && ( - <> -
Rp{value?.toLocaleString('id-ID')}
- {timeLeft !== null && ( -

Waktu tersisa: {formatTimeLeft(timeLeft)}

- )} - - )} {transactionSuccess && (
@@ -263,10 +252,6 @@ const Checkout = ({ socketId, transactionSuccess }) => {
Bank: {transferData?.bank_name}
Account No: {transferData?.bank_account}
Account Name: {transferData?.account_name}
-
Total: Rp{value?.toLocaleString('id-ID')}
- {timeLeft !== null && ( -
Waktu Tersisa: {formatTimeLeft(timeLeft)}
- )}
)}