Changeset 3470315
- Timestamp:
- 02/26/2026 01:35:12 PM (5 weeks ago)
- Location:
- kaspa-payments-gateway-woocommerce/trunk
- Files:
-
- 2 edited
-
assets/kaspa-checkout.js (modified) (6 diffs)
-
includes/kaspa-transaction-polling.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
kaspa-payments-gateway-woocommerce/trunk/assets/kaspa-checkout.js
r3470285 r3470315 135 135 } 136 136 137 // Step 3: Payment sent — confirm with server137 // Step 3: Payment sent — start fast verification 138 138 kaswareTxid = txid; 139 139 btn.className = 'kaspa-kasware-btn success'; … … 144 144 } 145 145 146 // Stop polling — we have the txid146 // Stop any existing polling 147 147 stopPaymentChecking(); 148 updatePaymentStatus('Payment sent via KasWare. Verifying on blockchain...', 'checking'); 149 150 // Notify server and verify 151 confirmKasWarePayment(txid); 148 updatePaymentStatus('Payment sent! Confirming on blockchain...', 'checking'); 149 150 // Notify server of txid (fire-and-forget, don't wait) 151 notifyServerTxid(txid); 152 153 // Start fast 1s polling immediately — don't wait for server response 154 startFastPaymentPolling(); 152 155 153 156 } catch (err) { … … 163 166 } else if (errorMsg.toLowerCase().includes('insufficient')) { 164 167 if (statusEl) statusEl.textContent = 'Insufficient funds in your KasWare wallet.'; 168 } else if (errorMsg.toLowerCase().includes('storage mass')) { 169 if (statusEl) statusEl.textContent = 'Wallet has too many small UTXOs. Send your full balance to yourself in KasWare to consolidate, then try again.'; 165 170 } else { 166 171 if (statusEl) statusEl.textContent = 'Error: ' + errorMsg; … … 169 174 } 170 175 171 function confirmKasWarePayment(txid) { 176 /** 177 * Fire-and-forget: notify server of the KasWare txid so it's stored on the order. 178 * Does not block — fast polling handles verification separately. 179 */ 180 function notifyServerTxid(txid) { 172 181 var xhr = new XMLHttpRequest(); 173 182 xhr.open('POST', ajaxUrl, true); 174 183 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 175 176 xhr.onreadystatechange = function () { 177 if (xhr.readyState === 4) { 178 if (xhr.status === 200) { 179 try { 180 var response = JSON.parse(xhr.responseText); 181 if (response.success && response.data.status === 'completed') { 182 // Verified on-chain — order confirmed 183 handlePaymentConfirmed({ txid: txid, status: 'completed' }); 184 } else if (response.success && response.data.status === 'pending_verification') { 185 // Transaction broadcast but not yet confirmed on-chain. 186 // Poll aggressively at 3s — Kaspa confirms in ~1s, we just 187 // need the API to index it. 188 updatePaymentStatus('Payment sent! Confirming on blockchain...', 'checking'); 189 var btn = document.getElementById('kaspa-kasware-btn'); 190 if (btn) { 191 btn.className = 'kaspa-kasware-btn success'; 192 btn.textContent = 'Payment sent!'; 193 } 194 var statusEl = document.getElementById('kaspa-kasware-status'); 195 if (statusEl) { 196 statusEl.className = 'kaspa-kasware-status verifying'; 197 statusEl.innerHTML = '<span class="kaspa-kasware-spinner"></span> Confirming: ' + txid.substring(0, 16) + '...'; 198 } 199 // Fast polling — 3s intervals for 30s, then fall back to normal 200 paymentCheckActive = false; 201 startFastPaymentPolling(); 202 } else { 203 updatePaymentStatus('Payment sent. Waiting for blockchain confirmation...', 'checking'); 204 startPaymentMonitoring(); 205 } 206 } catch (e) { 207 updatePaymentStatus('Payment sent. Waiting for blockchain confirmation...', 'checking'); 208 startPaymentMonitoring(); 209 } 210 } else { 211 updatePaymentStatus('Payment sent. Waiting for blockchain confirmation...', 'checking'); 212 startPaymentMonitoring(); 213 } 214 } 215 }; 216 184 // No onreadystatechange — fire and forget 217 185 var data = 'action=kasppaga_kasware_confirm&order_id=' + orderId + '&txid=' + encodeURIComponent(txid) + '&nonce=' + kaswareNonce; 218 186 xhr.send(data); … … 220 188 221 189 /** 222 * Fast polling after KasWare payment — 2s intervals for 20s max,190 * Fast polling after KasWare payment — 1s intervals for 15s max, 223 191 * uses direct txid verification for speed, then falls back to normal polling. 224 192 */ 225 193 function startFastPaymentPolling() { 226 194 var fastPollCount = 0; 227 var maxFastPolls = 1 0; // 10 polls x 2s = 20seconds195 var maxFastPolls = 15; // 15 polls x 1s = 15 seconds 228 196 229 197 paymentCheckActive = true; … … 240 208 } 241 209 fastCheckTxid(); 242 }, 2000);210 }, 1000); 243 211 } 244 212 -
kaspa-payments-gateway-woocommerce/trunk/includes/kaspa-transaction-polling.php
r3470079 r3470315 75 75 76 76 $response = wp_remote_get($url, array( 77 'timeout' => 10,77 'timeout' => 3, 78 78 'headers' => array( 79 'User-Agent' => 'Kaspa-Payments-Gateway-WooCommerce/1. 1',79 'User-Agent' => 'Kaspa-Payments-Gateway-WooCommerce/1.2', 80 80 'Accept' => 'application/json' 81 81 )
Note: See TracChangeset
for help on using the changeset viewer.