summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2024-08-23 14:19:05 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2024-08-23 14:19:05 +0700
commit67731281227f961c9b56f9f310951a8e5c82ab39 (patch)
tree62046280e3bd712a60e508b7f25602237a933b50 /src/lib
parent79c74d25a84de79513c738cc022751928f05fe44 (diff)
bug fixing checkout ios env
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/checkout/components/Checkout.jsx40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 09a791ee..47f148d1 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -389,12 +389,38 @@ const Checkout = () => {
if (typeof file !== 'undefined') data.po_file = await getFileBase64(file);
const isCheckouted = await checkoutApi({ data });
+
if (!isCheckouted?.id) {
toast.error('Gagal melakukan transaksi, terjadi kesalahan internal');
return;
- }
+ } else {
+ gtagPurchase(products, biayaKirim, isCheckouted.name);
+
+ gtag('event', 'conversion', {
+ send_to: 'AW-954540379/nDymCL3BhaQYENvClMcD',
+ value:
+ cartCheckout?.grandTotal +
+ Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000,
+ currency: 'IDR',
+ transaction_id: isCheckouted.id,
+ });
- gtagPurchase(products, biayaKirim, isCheckouted.name);
+ for (const product of products) deleteItemCart({ productId: product.id });
+ 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,
+ '-'
+ )}`;
+ }
+ }
const midtrans = async () => {
for (const product of products) deleteItemCart({ productId: product.id });
@@ -413,16 +439,6 @@ const Checkout = () => {
)}`;
}
};
-
- gtag('event', 'conversion', {
- send_to: 'AW-954540379/nDymCL3BhaQYENvClMcD',
- value:
- cartCheckout?.grandTotal +
- Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000,
- currency: 'IDR',
- transaction_id: isCheckouted.id,
- event_callback: midtrans,
- });
};
const handlingActivateCode = async () => {