From 78d02a2392924d5d4a21206fb52f627251883af8 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 6 Mar 2023 11:59:03 +0700 Subject: fix --- src/lib/checkout/components/Checkout.jsx | 49 +++++++++++++++++++++++--- src/lib/checkout/components/FinishCheckout.jsx | 11 ------ 2 files changed, 44 insertions(+), 16 deletions(-) (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 8af3d996..b4fd33ff 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -17,6 +17,7 @@ import { useRouter } from 'next/router' import VariantGroupCard from '@/lib/variant/components/VariantGroupCard' import axios from 'axios' import Script from 'next/script' +import Image from '@/core/components/elements/Image/Image' const Checkout = () => { const router = useRouter() @@ -56,6 +57,7 @@ const Checkout = () => { }) }, [addresses]) + const [paymentMethod, setPaymentMethod] = useState('') const [products, setProducts] = useState(null) const [totalAmount, setTotalAmount] = useState(0) const [totalDiscountAmount, setTotalDiscountAmount] = useState(0) @@ -96,6 +98,11 @@ const Checkout = () => { const [isLoading, setIsLoading] = useState(false) const checkout = async () => { + if (!paymentMethod) { + toast.error('Metode pembayaran harus dipilih', { position: 'bottom-center' }) + return + } + const file = poFile.current.files[0] if (typeof file !== 'undefined' && file.size > 5000000) { toast.error('Maksimal ukuran file adalah 5MB', { position: 'bottom-center' }) @@ -121,12 +128,16 @@ const Checkout = () => { toast.error('Gagal melakukan transaksi, terjadi kesalahan internal') return } - - const payment = await axios.post( - `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/midtrans-payment?transactionId=${isCheckouted.id}` - ) + for (const product of products) deleteItemCart({ productId: product.id }) - window.location.href = payment.data.redirectUrl + if (paymentMethod == 'midtrans') { + const payment = await axios.post( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/midtrans-payment?transactionId=${isCheckouted.id}` + ) + window.location.href = payment.data.redirectUrl + } else { + router.push(`/shop/checkout/finish?order_id=${isCheckouted.name}`) + } } return ( @@ -221,6 +232,34 @@ const Checkout = () => { +
+
Metode Pembayaran
+
+
setPaymentMethod('manual')} + > + Bank BCA (PT. Indoteknik Dotcom) +
8870-4000-81
+
+
setPaymentMethod('midtrans')} + > + Midtrans Payment +
+
+
+ + +
Purchase Order
diff --git a/src/lib/checkout/components/FinishCheckout.jsx b/src/lib/checkout/components/FinishCheckout.jsx index f5346d67..33c0d46a 100644 --- a/src/lib/checkout/components/FinishCheckout.jsx +++ b/src/lib/checkout/components/FinishCheckout.jsx @@ -1,17 +1,6 @@ import Link from '@/core/components/elements/Link/Link' -import axios from 'axios' -import { useEffect } from 'react' const FinishCheckout = ({ query }) => { - useEffect(() => { - if (query?.order_id) { - console.log(`${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/finish-checkout?orderName=${query.order_id}`); - axios.post( - `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/finish-checkout?orderId=${query.order_id}` - ) - } - }, [query]) - return (
-- cgit v1.2.3