diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-03-03 16:44:12 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-03-03 16:44:12 +0700 |
| commit | 76961c8312312609dbef0646274f6dd1f6c2bf19 (patch) | |
| tree | 111c9ff63449f4e188a72435a850ac8efc2a9d28 /src/lib/checkout/components | |
| parent | 069f9fa637cd24e9b92c7a1e4de56fa9e263508f (diff) | |
add midtrans payment email notification
Diffstat (limited to 'src/lib/checkout/components')
| -rw-r--r-- | src/lib/checkout/components/Checkout.jsx | 6 | ||||
| -rw-r--r-- | src/lib/checkout/components/FinishCheckout.jsx | 18 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 42608cef..8af3d996 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -126,7 +126,7 @@ const Checkout = () => { `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/midtrans-payment?transactionId=${isCheckouted.id}` ) for (const product of products) deleteItemCart({ productId: product.id }) - window.snap.pay(payment.data.token) + window.location.href = payment.data.redirectUrl } return ( @@ -252,7 +252,7 @@ const Checkout = () => { <button className='flex-1 btn-yellow' onClick={checkout} - disabled={isLoading} + disabled={isLoading || !products || products?.length == 0} > {isLoading ? 'Loading...' : 'Bayar'} </button> @@ -261,7 +261,7 @@ const Checkout = () => { <Script async src='https://app.sandbox.midtrans.com/snap/snap.js' - data-client-key='' + data-client-key={process.env.NEXT_PUBLIC_MIDTRANS_CLIENT_KEY} /> </> ) diff --git a/src/lib/checkout/components/FinishCheckout.jsx b/src/lib/checkout/components/FinishCheckout.jsx index a7d65dd0..f5346d67 100644 --- a/src/lib/checkout/components/FinishCheckout.jsx +++ b/src/lib/checkout/components/FinishCheckout.jsx @@ -1,8 +1,16 @@ import Link from '@/core/components/elements/Link/Link' -import useTransaction from '@/lib/transaction/hooks/useTransaction' +import axios from 'axios' +import { useEffect } from 'react' -const FinishCheckout = ({ id }) => { - const { transaction } = useTransaction({ id }) +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 ( <div className='p-4'> @@ -13,11 +21,11 @@ const FinishCheckout = ({ id }) => { Rincian belanja sudah kami kirimkan ke email anda. Mohon dicek kembali. jika tidak menerima email, anda dapat menghubungi kami disini. </p> - <p className='mb-2 font-medium'>{transaction.data?.name}</p> + <p className='mb-2 font-medium'>{query?.order_id?.replaceAll('-', '/')}</p> <p className='text-caption-2 text-yellow_r-11'>No. Transaksi</p> </div> <Link - href={transaction.data?.id ? `/my/transaction/${transaction.data.id}` : '/'} + href='/my/transactions' className='bg-yellow_r-6 text-yellow_r-12 rounded-b-xl py-4 block' > Lihat detail pembelian Anda disini |
