From 308563b3f45255450206decc03329dcc64c4bc50 Mon Sep 17 00:00:00 2001
From: Miqdad <ahmadmiqdad27@gmail.com>
Date: Fri, 29 Aug 2025 10:42:05 +0700
Subject: <MIqdad> Fix payment

---
 src/lib/transaction/components/Transactions.jsx | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

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

diff --git a/src/lib/transaction/components/Transactions.jsx b/src/lib/transaction/components/Transactions.jsx
index 79ccdcb4..e22cd490 100644
--- a/src/lib/transaction/components/Transactions.jsx
+++ b/src/lib/transaction/components/Transactions.jsx
@@ -70,9 +70,7 @@ const Transactions = ({ context = '' }) => {
   const [isOpenCalender, setIsOpenCalender] = useState(false);
   const calendarRef = useRef(null);
   const isUnpaid = (s) =>
-    ['belum_bayar'].includes(
-      String(s || '').toLowerCase()
-    );
+    ['belum_bayar'].includes(String(s || '').toLowerCase());
 
   // loading id utk tombol lanjutkan transaksi
   const [contLoadingId, setContLoadingId] = useState(null);
@@ -381,13 +379,22 @@ const Transactions = ({ context = '' }) => {
     return `${day} ${months[parseInt(month, 10) - 1]} ${year}`;
   };
 
-  // ==== Lanjutkan Transaksi (tanpa endpoint baru) ====
   const handleContinuePayment = async (saleOrder) => {
     try {
       setContLoadingId(saleOrder.id);
 
-      // 1) pakai URL yang dikirim server di list
+      // (0) Minta backend pastikan/generate link terbaru
+      let ensuredUrl = '';
+      try {
+        const { data } = await axios.post(
+          `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/so-payment-link?soId=${saleOrder.id}`
+        );
+        ensuredUrl = data?.redirectUrl || '';
+      } catch (e) {
+      }
+
       const existingUrl =
+        ensuredUrl ||
         saleOrder?.paymentSummary?.redirectUrl ||
         saleOrder?.paymentLinkMidtrans ||
         '';
@@ -398,12 +405,13 @@ const Transactions = ({ context = '' }) => {
         return;
       }
 
-      // 2) kalau masih kosong, refetch list (server bisa auto-generate saat list)
+      // (2) Fallback: refetch list (kalau backend auto-generate saat list)
       await transactions.refetch();
       const updated =
         transactions?.data?.saleOrders?.find((s) => s.id === saleOrder.id) ||
         null;
       const updatedUrl =
+        ensuredUrl || // kalau step (0) akhirnya sukses
         updated?.paymentSummary?.redirectUrl ||
         updated?.paymentLinkMidtrans ||
         '';
-- 
cgit v1.2.3

