From 800b527bc0661255d1f9ec07d4bb365b23dab610 Mon Sep 17 00:00:00 2001
From: Miqdad <ahmadmiqdad27@gmail.com>
Date: Sat, 6 Sep 2025 21:09:05 +0700
Subject: <Miqdad> Fix detail transaction and no open new tab

---
 src/lib/transaction/components/Transaction.jsx | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

(limited to 'src/lib/transaction/components/Transaction.jsx')

diff --git a/src/lib/transaction/components/Transaction.jsx b/src/lib/transaction/components/Transaction.jsx
index 30ba74d2..cbe725c7 100644
--- a/src/lib/transaction/components/Transaction.jsx
+++ b/src/lib/transaction/components/Transaction.jsx
@@ -221,7 +221,7 @@ const Transaction = ({ id }) => {
       const token = auth?.token;
       const partnerId = auth?.partnerId;
 
-      // 1) Minta Odoo ensure (hanya generate jika kosong / expire / cancel)
+      // 1) Minta Odoo ensure payment link
       const { data: resp } = await axios.get(
         `${base}/api/v1/partner/${partnerId}/sale_order/${transaction.data.id}`,
         {
@@ -230,37 +230,40 @@ const Transaction = ({ id }) => {
         }
       );
 
-      const payload = resp?.data || resp;
+      console.log('API Response:', resp); // Debug
 
-      // 2) Ambil URL dari berbagai kemungkinan field (snake_case dan camelCase)
+      // 2) Akses semua kemungkinan path
       let url =
-        payload?.payment_summary?.redirect_url ||
-        payload?.paymentSummary?.redirectUrl ||
-        payload?.paymentLinkMidtrans ||
-        payload?.payment_link_midtrans ||
+        resp?.result?.payment_summary?.redirect_url ||
+        resp?.data?.result?.payment_summary?.redirect_url ||
+        resp?.payment_summary?.redirect_url ||
+        resp?.paymentSummary?.redirectUrl ||
         '';
 
+      console.log('Extracted URL:', url); // Debug
+
       if (url) {
         window.location.href = url;
         return;
       }
 
-      // 3) Fallback: refetch detail dari hook lalu cek lagi
+      // 3) Fallback
       await transaction.refetch();
+      console.log('Transaction data:', transaction.data); // Debug
 
       url =
+        transaction?.data?.result?.payment_summary?.redirect_url ||
         transaction?.data?.paymentSummary?.redirectUrl ||
         transaction?.data?.payment_summary?.redirect_url ||
-        transaction?.data?.paymentLinkMidtrans ||
-        transaction?.data?.payment_link_midtrans ||
         '';
 
+      console.log('Fallback URL:', url); // Debug
+
       if (url) {
         window.location.href = url;
         return;
       }
 
-      // 4) Masih kosong → error
       throw new Error('Link pembayaran belum tersedia.');
     } catch (e) {
       toast.error(
-- 
cgit v1.2.3

