// 1. Centralized Pricing Configuration (Filename : Price in KES Cents) const topicPrices = { "Thermochemistry.html": 15000, // KES 150 "Solubility.html": 15000, // KES 150 "Reaction Rate.html": 20000, // KES 200 "The Cell.html": 10000, // KES 100 "Gaseous exchange.html": 12000, // KES 120 "InorganicQAsampleTest1.html": 20000, // KES 200 "InorganicQAsampleTest2.html": 20000 // KES 200 }; const DEFAULT_PRICE_CENTS = 10000; // Fallback Price: KES 100 // Helper function to extract targeted practical name from URL query parameters function getTargetFile() { const urlParams = new URLSearchParams(window.location.search); return urlParams.get('returnTo') || "InorganicQAsampleTest1.html"; } // 2. Page Initialization: Display Topic Info Immediately upon loading page document.addEventListener("DOMContentLoaded", function() { const targetFile = getTargetFile(); let cleanName = targetFile.replace(".html", "").replace(/[-_]/g, " "); const priceCents = topicPrices[targetFile] || DEFAULT_PRICE_CENTS; const priceKES = priceCents / 100; document.getElementById("displayName").innerText = cleanName; document.getElementById("displayPrice").innerText = priceKES.toFixed(2); }); // 3. Execution Layer: Trigger Payment API Interface function payWithPaystack() { const phone = document.getElementById('phoneNumber').value.trim(); if (!phone || phone.length < 10) { alert("Please enter a valid M-Pesa phone number."); return; } const targetFile = getTargetFile(); const finalAmountCents = topicPrices[targetFile] || DEFAULT_PRICE_CENTS; const cleanPhone = phone.replace(/[^0-9]/g, ""); const generatedEmail = `mpesa_${cleanPhone}@vsl-simulations.com`; const popup = new PaystackPop(); popup.newTransaction({ key: 'pk_test_f9804874de89577124d605a1ec7a9a3a2458aadb', // ⚠️ REMEMBER TO PASTE YOUR ACTUAL PAYSTACK PUBLIC KEY HERE email: generatedEmail, amount: finalAmountCents, currency: 'KES', onSuccess: function(transaction) { // 1. Calculate expiration parameters matching target access profile (e.g. 24 Hours) let expiryDate = new Date(); expiryDate.setTime(expiryDate.getTime() + (24 * 60 * 60 * 1000)); // 2. Save individual strict authorization state token parameters targeting specific file document.cookie = `access_${targetFile}=true; expires=${expiryDate.toUTCString()}; path=/; secure; samesite=strict`; alert("Payment Verified! Loading your simulation now..."); // 3. Transform current tab directly into the premium simulation file! window.location.href = "/" + targetFile; }, onCancel: function() { alert("Transaction cancelled. Your account has not been charged."); } }); }