Changeset 3470345
- Timestamp:
- 02/26/2026 01:57:28 PM (5 weeks ago)
- Location:
- kaspa-payments-gateway-woocommerce/trunk
- Files:
-
- 2 edited
-
assets/kaspa-checkout.js (modified) (5 diffs)
-
includes/kaspa-frontend-assets.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
kaspa-payments-gateway-woocommerce/trunk/assets/kaspa-checkout.js
r3470335 r3470345 136 136 137 137 // Step 3: Payment sent — start fast verification 138 console.log('[KaspaWoo] tx broadcast at ' + new Date().toISOString() + ' txid: ' + txid); 138 139 kaswareTxid = txid; 139 140 btn.className = 'kaspa-kasware-btn success'; … … 174 175 } 175 176 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) { 177 // Track whether the server has confirmed the order yet 178 var serverVerified = false; 179 180 /** 181 * Notify server of the KasWare txid. If the Kaspa API hasn't indexed the tx 182 * yet, it retries up to 5 times at 1s intervals until verification succeeds. 183 */ 184 function notifyServerTxid(txid, attempt) { 185 attempt = attempt || 1; 186 var maxAttempts = 5; 187 console.log('[KaspaWoo] notify attempt ' + attempt + ' at ' + new Date().toISOString()); 188 181 189 var xhr = new XMLHttpRequest(); 182 190 xhr.open('POST', ajaxUrl, true); 183 191 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 184 // No onreadystatechange — fire and forget 192 xhr.onreadystatechange = function () { 193 if (xhr.readyState === 4) { 194 console.log('[KaspaWoo] notify response: ' + xhr.status + ' at ' + new Date().toISOString()); 195 if (xhr.status === 200) { 196 try { 197 var response = JSON.parse(xhr.responseText); 198 console.log('[KaspaWoo] notify result: ' + JSON.stringify(response.data)); 199 if (response.success && response.data.status === 'completed') { 200 serverVerified = true; 201 handlePaymentConfirmed({ txid: txid, status: 'completed' }); 202 return; 203 } 204 } catch (e) {} 205 } 206 // Not verified yet — retry after 1s 207 if (attempt < maxAttempts && !serverVerified) { 208 setTimeout(function () { 209 notifyServerTxid(txid, attempt + 1); 210 }, 1000); 211 } 212 } 213 }; 185 214 var data = 'action=kasppaga_kasware_confirm&order_id=' + orderId + '&txid=' + encodeURIComponent(txid) + '&nonce=' + kaswareNonce; 186 215 xhr.send(data); … … 188 217 189 218 /** 190 * Fast polling after KasWare payment — 1s intervals for 15s max,191 * uses direct txid verification for speed, then falls back to normal polling.219 * Fast polling after KasWare payment — 1s lightweight DB checks for 15s. 220 * Runs in parallel with notify retries. Whichever confirms first wins. 192 221 */ 193 222 function startFastPaymentPolling() { 194 223 var fastPollCount = 0; 195 var maxFastPolls = 15; // 15 polls x 1s = 15 seconds224 var maxFastPolls = 15; 196 225 197 226 paymentCheckActive = true; 198 fastCheckTxid(); // Check immediately227 fastCheckTxid(); 199 228 200 229 paymentCheckInterval = setInterval(function () { 230 if (serverVerified) { 231 clearInterval(paymentCheckInterval); 232 paymentCheckInterval = null; 233 paymentCheckActive = false; 234 return; 235 } 201 236 fastPollCount++; 202 237 if (fastPollCount >= maxFastPolls) { … … 213 248 /** 214 249 * Lightweight order status check — just reads DB, no Kaspa API call. 215 * The fire-and-forget notify handles actual verification; we just wait for it.216 250 */ 217 251 function fastCheckTxid() { 252 if (serverVerified) return; 253 console.log('[KaspaWoo] fast poll at ' + new Date().toISOString()); 218 254 var xhr = new XMLHttpRequest(); 219 255 xhr.open('POST', ajaxUrl, true); … … 223 259 try { 224 260 var response = JSON.parse(xhr.responseText); 261 console.log('[KaspaWoo] fast poll result: ' + response.data.status); 225 262 if (response.success && response.data.status === 'completed') { 263 serverVerified = true; 226 264 handlePaymentConfirmed({ txid: kaswareTxid || '', status: 'completed' }); 227 265 } -
kaspa-payments-gateway-woocommerce/trunk/includes/kaspa-frontend-assets.php
r3470335 r3470345 365 365 plugin_dir_url(__DIR__) . 'assets/kaspa-checkout.js', 366 366 array(), 367 '2. 2.0',367 '2.3.0', 368 368 true 369 369 );
Note: See TracChangeset
for help on using the changeset viewer.