// Proses pembayaran dengan Tripay function processPayment(productId, productName, productPrice) { var qty = document.getElementById('qty_' + productId).value; if(!qty || qty < 1) { alert('Masukkan jumlah pembelian!'); return; } currentProductId = productId; currentQty = qty; currentPrice = productPrice; currentProductName = productName; var total = productPrice * qty; document.getElementById('pay_product_name').innerText = productName; document.getElementById('pay_quantity').innerText = qty; document.getElementById('pay_total').innerText = total.toLocaleString('id-ID'); document.getElementById('pay_product_id').value = productId; document.getElementById('pay_qty_val').value = qty; document.getElementById('pay_price_val').value = productPrice; paymentModal.style.display = 'block'; } function processPaymentSubmit() { var customerName = document.getElementById('pay_customer_name').value; var customerEmail = document.getElementById('pay_customer_email').value; var customerPhone = document.getElementById('pay_customer_phone').value; var paymentMethod = document.querySelector('input[name="payment_method"]:checked').value; if(!customerName || !customerPhone) { alert('Lengkapi data diri!'); return; } var total = currentPrice * currentQty; var paymentMethodCode = ''; // Mapping metode pembayaran ke kode Tripay [citation:6] switch(paymentMethod) { case 'bank_transfer': paymentMethodCode = 'BCAVA'; // BCA Virtual Account break; case 'gopay': paymentMethodCode = 'GOPAY'; break; case 'shopeepay': paymentMethodCode = 'SHOPEEPAY'; break; case 'qris': paymentMethodCode = 'QRIS'; break; default: paymentMethodCode = 'QRIS'; } // Loading state var submitBtn = event.target; var originalText = submitBtn.innerText; submitBtn.innerText = 'Memproses...'; submitBtn.disabled = true; // Proses ke Tripay fetch('process-payment.php', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ product_id: currentProductId, product_name: currentProductName, quantity: currentQty, amount: total, customer_name: customerName, customer_email: customerEmail, customer_phone: customerPhone, payment_method: paymentMethodCode }) }) .then(response => response.json()) .then(data => { if(data.success && data.payment_url) { // Redirect ke halaman pembayaran Tripay window.open(data.payment_url, '_blank'); paymentModal.style.display = 'none'; alert('Silakan selesaikan pembayaran Anda di halaman yang terbuka.'); // Reset form document.getElementById('pay_customer_name').value = ''; document.getElementById('pay_customer_email').value = ''; document.getElementById('pay_customer_phone').value = ''; } else { alert('Error: ' + (data.error || 'Gagal memproses pembayaran')); } }) .catch(error => { console.error('Error:', error); alert('Terjadi kesalahan. Silakan coba lagi.'); }) .finally(() => { submitBtn.innerText = originalText; submitBtn.disabled = false; }); }