Plugin Directory

Changeset 3470345


Ignore:
Timestamp:
02/26/2026 01:57:28 PM (5 weeks ago)
Author:
jacobo1
Message:

Fix: notify retries up to 5x, fast polls run in parallel, add debug logs

Location:
kaspa-payments-gateway-woocommerce/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kaspa-payments-gateway-woocommerce/trunk/assets/kaspa-checkout.js

    r3470335 r3470345  
    136136
    137137            // Step 3: Payment sent — start fast verification
     138            console.log('[KaspaWoo] tx broadcast at ' + new Date().toISOString() + ' txid: ' + txid);
    138139            kaswareTxid = txid;
    139140            btn.className = 'kaspa-kasware-btn success';
     
    174175    }
    175176
    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
    181189        var xhr = new XMLHttpRequest();
    182190        xhr.open('POST', ajaxUrl, true);
    183191        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        };
    185214        var data = 'action=kasppaga_kasware_confirm&order_id=' + orderId + '&txid=' + encodeURIComponent(txid) + '&nonce=' + kaswareNonce;
    186215        xhr.send(data);
     
    188217
    189218    /**
    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.
    192221     */
    193222    function startFastPaymentPolling() {
    194223        var fastPollCount = 0;
    195         var maxFastPolls = 15; // 15 polls x 1s = 15 seconds
     224        var maxFastPolls = 15;
    196225
    197226        paymentCheckActive = true;
    198         fastCheckTxid(); // Check immediately
     227        fastCheckTxid();
    199228
    200229        paymentCheckInterval = setInterval(function () {
     230            if (serverVerified) {
     231                clearInterval(paymentCheckInterval);
     232                paymentCheckInterval = null;
     233                paymentCheckActive = false;
     234                return;
     235            }
    201236            fastPollCount++;
    202237            if (fastPollCount >= maxFastPolls) {
     
    213248    /**
    214249     * 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.
    216250     */
    217251    function fastCheckTxid() {
     252        if (serverVerified) return;
     253        console.log('[KaspaWoo] fast poll at ' + new Date().toISOString());
    218254        var xhr = new XMLHttpRequest();
    219255        xhr.open('POST', ajaxUrl, true);
     
    223259                try {
    224260                    var response = JSON.parse(xhr.responseText);
     261                    console.log('[KaspaWoo] fast poll result: ' + response.data.status);
    225262                    if (response.success && response.data.status === 'completed') {
     263                        serverVerified = true;
    226264                        handlePaymentConfirmed({ txid: kaswareTxid || '', status: 'completed' });
    227265                    }
  • kaspa-payments-gateway-woocommerce/trunk/includes/kaspa-frontend-assets.php

    r3470335 r3470345  
    365365        plugin_dir_url(__DIR__) . 'assets/kaspa-checkout.js',
    366366        array(),
    367         '2.2.0',
     367        '2.3.0',
    368368        true
    369369    );
Note: See TracChangeset for help on using the changeset viewer.