Changeset 3470285
- Timestamp:
- 02/26/2026 01:06:19 PM (5 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kaspa-payments-gateway-woocommerce/trunk/assets/kaspa-checkout.js
r3470198 r3470285 14 14 let paymentCheckActive = false; 15 15 let kaswarePaymentInProgress = false; 16 let kaswareTxid = null; 16 17 17 18 // Get data from WordPress … … 135 136 136 137 // Step 3: Payment sent — confirm with server 138 kaswareTxid = txid; 137 139 btn.className = 'kaspa-kasware-btn success'; 138 140 btn.textContent = 'Payment sent!'; … … 218 220 219 221 /** 220 * Fast polling after KasWare payment — 3s intervals for 30s max,221 * then falls back to normal 15s polling if still not confirmed.222 * Fast polling after KasWare payment — 2s intervals for 20s max, 223 * uses direct txid verification for speed, then falls back to normal polling. 222 224 */ 223 225 function startFastPaymentPolling() { 224 226 var fastPollCount = 0; 225 var maxFastPolls = 10; // 10 polls x 3s = 30 seconds227 var maxFastPolls = 10; // 10 polls x 2s = 20 seconds 226 228 227 229 paymentCheckActive = true; 228 checkPaymentStatus(); // Check immediately230 fastCheckTxid(); // Check immediately 229 231 230 232 paymentCheckInterval = setInterval(function () { 231 233 fastPollCount++; 232 234 if (fastPollCount >= maxFastPolls) { 233 // Switch to normal polling234 235 clearInterval(paymentCheckInterval); 235 236 paymentCheckInterval = null; 236 237 paymentCheckActive = false; 237 updatePaymentStatus('Payment sent. Waiting for confirmation...', 'checking');238 238 startPaymentMonitoring(); 239 239 return; 240 240 } 241 fastCheckTxid(); 242 }, 2000); 243 } 244 245 /** 246 * Fast txid verification — retries the direct txid lookup instead of 247 * scanning address balance. Much faster for KasWare payments. 248 */ 249 function fastCheckTxid() { 250 if (!kaswareTxid) { 241 251 checkPaymentStatus(); 242 }, 3000); 252 return; 253 } 254 255 var xhr = new XMLHttpRequest(); 256 xhr.open('POST', ajaxUrl, true); 257 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 258 xhr.onreadystatechange = function () { 259 if (xhr.readyState === 4 && xhr.status === 200) { 260 try { 261 var response = JSON.parse(xhr.responseText); 262 if (response.success && response.data.status === 'completed') { 263 handlePaymentConfirmed({ txid: kaswareTxid, status: 'completed' }); 264 } 265 // If still pending, do nothing — next poll will retry 266 } catch (e) {} 267 } 268 }; 269 var data = 'action=kasppaga_kasware_confirm&order_id=' + orderId + '&txid=' + encodeURIComponent(kaswareTxid) + '&nonce=' + kaswareNonce; 270 xhr.send(data); 243 271 } 244 272
Note: See TracChangeset
for help on using the changeset viewer.