summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorHATEC\SPVDEV001 <tri.susilo@altama.co.id>2024-04-06 12:31:45 +0700
committerHATEC\SPVDEV001 <tri.susilo@altama.co.id>2024-04-06 12:31:45 +0700
commitc8cb137354ec569b4a13e180bc9cac2cab90c470 (patch)
tree9da6b941233f1a1cdcdf468beb8d5ce0db65385a /src/lib
parenta44ddf0ff093e09a0c70c61c0f65287bb7fdcbf3 (diff)
add voucher minus
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/checkout/components/Checkout.jsx38
-rw-r--r--src/lib/checkout/email/FinishCheckoutEmail.jsx4
2 files changed, 27 insertions, 15 deletions
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 52edbd05..7a456d70 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -111,6 +111,7 @@ const Checkout = () => {
const [checkoutValidation, setCheckoutValidation] = useState(false);
const [loadingVoucher, setLoadingVoucher] = useState(true);
const [loadingRajaOngkir, setLoadingRajaOngkir] = useState(false);
+ const [grandTotal, setGrandTotal] = useState(0);
const expedisiValidation = useRef(null);
@@ -295,6 +296,14 @@ const Checkout = () => {
const [isLoading, setIsLoading] = useState(false);
+ useEffect(() => {
+ const GT =
+ cartCheckout?.grandTotal +
+ Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000;
+ const finalGT = GT < 0 ? 0 : GT;
+ setGrandTotal(finalGT);
+ }, [biayaKirim, cartCheckout?.grandTotal, activeVoucher]);
+
const checkout = async () => {
const file = poFile.current.files[0];
if (typeof file !== 'undefined' && file.size > 5000000) {
@@ -352,11 +361,20 @@ const Checkout = () => {
const midtrans = async () => {
for (const product of products) deleteItemCart({ productId: product.id });
- const payment = await axios.post(
- `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/midtrans-payment?transactionId=${isCheckouted.id}`
- );
- setIsLoading(false);
- window.location.href = payment.data.redirectUrl;
+ if (grandTotal > 0) {
+ const payment = await axios.post(
+ `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/midtrans-payment?transactionId=${isCheckouted.id}`
+ );
+ setIsLoading(false);
+ window.location.href = payment.data.redirectUrl;
+ } else {
+ window.location.href = `${
+ process.env.NEXT_PUBLIC_SELF_HOST
+ }/shop/checkout/success?order_id=${isCheckouted.name.replace(
+ /\//g,
+ '-'
+ )}`;
+ }
};
gtag('event', 'conversion', {
@@ -913,10 +931,7 @@ const Checkout = () => {
<div className='flex gap-x-2 justify-between mb-4'>
<div>Grand Total</div>
<div className='font-semibold text-gray_r-12'>
- {currencyFormat(
- cartCheckout?.grandTotal +
- Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000
- )}
+ {currencyFormat(grandTotal)}
</div>
</div>
)}
@@ -1208,10 +1223,7 @@ const Checkout = () => {
<div className='flex gap-x-2 justify-between mb-4'>
<div>Grand Total</div>
<div className='font-semibold text-gray_r-12'>
- {currencyFormat(
- cartCheckout?.grandTotal +
- Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000
- )}
+ {currencyFormat(grandTotal)}
</div>
</div>
)}
diff --git a/src/lib/checkout/email/FinishCheckoutEmail.jsx b/src/lib/checkout/email/FinishCheckoutEmail.jsx
index d40ce7d4..23e7f877 100644
--- a/src/lib/checkout/email/FinishCheckoutEmail.jsx
+++ b/src/lib/checkout/email/FinishCheckoutEmail.jsx
@@ -91,7 +91,7 @@ const FinishCheckoutEmail = ({ transaction, payment, statusPayment }) => {
menyelesaikan transaksi dengan detail dibawah ini:
<ul>
<li>Nomor Pembelian: {transaction.name}</li>
- <li>Nominal: {currencyFormat(transaction.amountTotal)}</li>
+ <li>Nominal: {transaction.amountTotal > 0 ? currencyFormat(transaction.amountTotal) : '0'}</li>
<li>Tanggal: {transaction.dateOrder}</li>
</ul>
</>
@@ -213,7 +213,7 @@ const FinishCheckoutEmail = ({ transaction, payment, statusPayment }) => {
<Column style={style.descriptionLCol}>Grand Total</Column>
<Column style={style.descriptionRCol}>
<span style={{ fontWeight: '600' }}>
- {currencyFormat(transaction.amountTotal)}
+ {transaction.amountTotal > 0 ? currencyFormat(transaction.amountTotal) : '0'}
</span>
</Column>
</Row>