diff options
Diffstat (limited to 'src/lib/transaction/components/Transactions.jsx')
| -rw-r--r-- | src/lib/transaction/components/Transactions.jsx | 88 |
1 files changed, 13 insertions, 75 deletions
diff --git a/src/lib/transaction/components/Transactions.jsx b/src/lib/transaction/components/Transactions.jsx index cdac4036..2e3eaaa2 100644 --- a/src/lib/transaction/components/Transactions.jsx +++ b/src/lib/transaction/components/Transactions.jsx @@ -388,7 +388,6 @@ const Transactions = ({ context = '' }) => { const handleContinuePayment = async (saleOrder) => { try { setContLoadingId(saleOrder.id); - console.log('🚀 START PAYMENT PROCESS'); const base = (process.env.NEXT_PUBLIC_ODOO_API_HOST || '').replace( /\/$/, @@ -397,88 +396,33 @@ const Transactions = ({ context = '' }) => { const token = auth?.token; const partnerId = auth?.partnerId; - // 1. TRIGGER GENERATE + GET URL SEKALIGUS - console.log('🔹 Step 1: Trigger generate + get URL'); + // 1. TRIGGER GENERATE + GET URL const { data: response } = await axios.get( `${base}/api/v1/partner/${partnerId}/sale_order/${saleOrder.id}`, { - params: { - ensure_payment_link: 1, - ts: Date.now(), - }, - headers: { - Token: token, - 'Cache-Control': 'no-cache', - }, - timeout: 10000, // 10 second timeout + params: { ensure_payment_link: 1, ts: Date.now() }, + headers: { Token: token, 'Cache-Control': 'no-cache' }, + timeout: 10000, } ); - console.log('📦 Full API Response:', response); - - // 2. EKSTRAK URL DENGAN CARA YANG BENAR - let paymentUrl = ''; - - // Cara 1: Langsung dari response.result - if (response?.result?.payment_summary?.redirect_url) { - paymentUrl = response.result.payment_summary.redirect_url; - console.log('✅ URL found in response.result'); - } - // Cara 2: Mungkin nested di data.result - else if (response?.data?.result?.payment_summary?.redirect_url) { - paymentUrl = response.data.result.payment_summary.redirect_url; - console.log('✅ URL found in response.data.result'); - } - // Cara 3: Coba variasi lain - else { - console.log( - '❌ URL not found in usual places, checking all possibilities...' - ); - - // Debug: Log semua keys yang ada - console.log('🔍 Response keys:', Object.keys(response)); - if (response.result) - console.log('🔍 Result keys:', Object.keys(response.result)); - - // Manual search untuk redirect_url - const searchForUrl = (obj) => { - for (const key in obj) { - if ( - key.toLowerCase().includes('redirect') && - typeof obj[key] === 'string' && - obj[key].includes('http') - ) { - return obj[key]; - } - if (typeof obj[key] === 'object' && obj[key] !== null) { - const found = searchForUrl(obj[key]); - if (found) return found; - } - } - return null; - }; - - paymentUrl = searchForUrl(response); - console.log('🔍 Manual search result:', paymentUrl); - } + // 2. EKSTRAK URL + let paymentUrl = + response?.result?.payment_summary?.redirect_url || + response?.data?.result?.payment_summary?.redirect_url; // 3. JIKA DAPAT URL, BUKA if (paymentUrl) { - console.log('🎯 Opening URL:', paymentUrl); - window.open(paymentUrl, '_blank', 'noopener,noreferrer'); + window.location.href = paymentUrl; toast.success('Membuka halaman pembayaran…'); return; } - // 4. FALLBACK: COBA LAGI TANPA ensure_payment_link - console.log('🔹 Step 2: Fallback - try without ensure'); + // 4. FALLBACK: COBA TANPA ensure_payment_link try { const { data: fallbackResponse } = await axios.get( `${base}/api/v1/partner/${partnerId}/sale_order/${saleOrder.id}`, - { - headers: { Token: token }, - timeout: 5000, - } + { headers: { Token: token }, timeout: 5000 } ); const fallbackUrl = @@ -486,36 +430,30 @@ const Transactions = ({ context = '' }) => { fallbackResponse?.data?.result?.payment_summary?.redirect_url; if (fallbackUrl) { - console.log('✅ Fallback URL found:', fallbackUrl); - window.open(fallbackUrl, '_blank', 'noopener,noreferrer'); + window.location.href = fallbackUrl; toast.success('Membuka halaman pembayaran…'); return; } } catch (fallbackError) { - console.error('Fallback error:', fallbackError); + // Continue to next fallback } // 5. ULTIMATE FALLBACK: PAKAI URL DARI DATA LAMA - console.log('🔹 Step 3: Ultimate fallback - use existing data'); const existingUrl = saleOrder?.paymentSummary?.redirectUrl || saleOrder?.payment_summary?.redirect_url; if (existingUrl) { - console.log('✅ Using existing URL:', existingUrl); window.open(existingUrl, '_blank', 'noopener,noreferrer'); toast.success('Membuka halaman pembayaran…'); } else { - console.error('❌ No URL found in any method'); toast.error('Link pembayaran tidak ditemukan. Silakan coba lagi.'); } } catch (error) { - console.error('💥 Payment error:', error); toast.error( error.response?.data?.description || 'Gagal memproses pembayaran' ); } finally { - console.log('🏁 END PAYMENT PROCESS'); setContLoadingId(null); } }; |
