Payment Gateway Performance Analyzer

Payment Gateway Performance Analyzer

Analyze and compare the performance of your payment gateways.

${formatPercent(bestSuccessRate.successRate)}

Highest Volume

${highestVolume.name}

${formatCurrency(highestVolume.totalValue)}

Gateway Success Rate Comparison

Transaction Volume Distribution

Detailed Performance Data

${gatewayRows}
Gateway Success Rate Avg. Value Total Volume Chargeback Rate
`; renderCharts(); document.getElementById('download-pdf-btn').addEventListener('click', generatePdf); }; const renderCharts = () => { const { gateways } = analysisResult; const comparisonCtx = document.getElementById('comparison-chart').getContext('2d'); if (comparisonChartInstance) comparisonChartInstance.destroy(); comparisonChartInstance = new Chart(comparisonCtx, { type: 'bar', data: { labels: gateways.map(g => g.name), datasets: [{ label: 'Success Rate (%)', data: gateways.map(g => g.successRate), backgroundColor: '#14b8a6', // teal-500 borderColor: '#0d9488', // teal-600 borderWidth: 1 }] }, options: { responsive: true, maintainAspectRatio: false, scales: { y: { beginAtZero: true, max: 100 } }, plugins: { legend: { display: false } } } }); const distributionCtx = document.getElementById('distribution-chart').getContext('2d'); if (distributionChartInstance) distributionChartInstance.destroy(); distributionChartInstance = new Chart(distributionCtx, { type: 'doughnut', data: { labels: gateways.map(g => g.name), datasets: [{ data: gateways.map(g => g.totalValue), backgroundColor: ['#14b8a6', '#2dd4bf', '#5eead4', '#99f6e4'] }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom' } } } }); }; const renderConfig = () => { const configContent = document.getElementById('content-data-configuration'); if (!configContent) return; const gatewayRows = appData.gateways.map((gw, index) => `
`).join(''); configContent.innerHTML = `
Gateway Name Total Trans. Successful Total Value Chargebacks
${gatewayRows}
`; attachConfigListeners(); }; const attachConfigListeners = () => { document.getElementById('add-gateway-btn').addEventListener('click', () => { appData.gateways.push({ name: '', totalTransactions: 0, successfulTransactions: 0, totalValue: 0, chargebacks: 0 }); renderConfig(); }); document.getElementById('update-data-btn').addEventListener('click', handleConfigUpdate); document.querySelectorAll('.remove-gateway-btn').forEach(btn => { btn.addEventListener('click', (e) => { const index = parseInt(e.currentTarget.dataset.index); appData.gateways.splice(index, 1); renderConfig(); }); }); }; const handleConfigUpdate = () => { const newGateways = []; document.querySelectorAll('.gateway-row').forEach(row => { newGateways.push({ name: row.querySelector('[data-field="name"]').value, totalTransactions: parseInt(row.querySelector('[data-field="totalTransactions"]').value) || 0, successfulTransactions: parseInt(row.querySelector('[data-field="successfulTransactions"]').value) || 0, totalValue: parseFloat(row.querySelector('[data-field="totalValue"]').value) || 0, chargebacks: parseInt(row.querySelector('[data-field="chargebacks"]').value) || 0 }); }); appData.gateways = newGateways; analysisResult = null; // Force recalculation alert('Data updated! Switching to dashboard.'); renderDashboard(); switchTab(0); }; const generatePdf = () => { loadingOverlay.style.display = 'flex'; const { jsPDF } = window.jspdf; const pdfContent = document.getElementById('pdf-content-area'); const pdfHeader = document.getElementById('pdf-header'); document.getElementById('pdf-generated-date').textContent = new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }); pdfHeader.classList.remove('hidden'); html2canvas(pdfContent, { scale: 2, useCORS: true, logging: false }) .then(canvas => { pdfHeader.classList.add('hidden'); const imgData = canvas.toDataURL('image/jpeg', 0.95); const pdf = new jsPDF({ orientation: 'landscape', unit: 'px', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const imgProps = pdf.getImageProperties(imgData); const imgHeight = (imgProps.height * pdfWidth) / imgProps.width; let heightLeft = imgHeight; let position = 0; pdf.addImage(imgData, 'JPEG', 0, position, pdfWidth, imgHeight); heightLeft -= pdfHeight; while (heightLeft >= 0) { position = heightLeft - imgHeight; pdf.addPage(); pdf.addImage(imgData, 'JPEG', 0, position, pdfWidth, imgHeight); heightLeft -= pdfHeight; } pdf.save('Gateway-Performance-Report.pdf'); loadingOverlay.style.display = 'none'; }).catch(err => { console.error("PDF generation failed:", err); pdfHeader.classList.add('hidden'); loadingOverlay.style.display = 'none'; alert('An error occurred generating the PDF.'); }); }; // --- TAB NAVIGATION & INITIALIZATION --- const switchTab = (tabIndex) => { activeTabIndex = tabIndex; document.querySelectorAll('.tab-btn').forEach((btn, i) => btn.classList.toggle('active', i === tabIndex)); document.querySelectorAll('.tab-content').forEach((content, i) => content.classList.toggle('hidden', i !== tabIndex)); updateNavButtons(); }; const updateNavButtons = () => { prevTabBtn.disabled = activeTabIndex === 0; nextTabBtn.disabled = activeTabIndex === tabIdentifiers.length - 1; }; const initializeUI = () => { const tabs = [ { name: 'Performance Dashboard', id: 'performance-dashboard' }, { name: 'Data Configuration', id: 'data-configuration' }, ]; tabIdentifiers = tabs.map(t => t.id); tabsContainer.innerHTML = tabs.map(tab => ``).join(''); mainContent.innerHTML = tabs.map(tab => `
`).join(''); tabs.forEach((tab, index) => { document.getElementById(`tab-${tab.id}`).addEventListener('click', () => switchTab(index)); }); renderDashboard(); renderConfig(); switchTab(0); lucide.createIcons(); }; initializeUI(); prevTabBtn.addEventListener('click', () => { if (activeTabIndex > 0) switchTab(activeTabIndex - 1); }); nextTabBtn.addEventListener('click', () => { if (activeTabIndex < tabIdentifiers.length - 1) switchTab(activeTabIndex + 1); }); });
Scroll to Top