Plugin Directory

Changeset 3470335


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

Fast polls use lightweight DB check instead of Kaspa API re-verification

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

Legend:

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

    r3470319 r3470335  
    212212
    213213    /**
    214      * Fast txid verification — retries the direct txid lookup instead of
    215      * scanning address balance. Much faster for KasWare payments.
     214     * 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.
    216216     */
    217217    function fastCheckTxid() {
    218         if (!kaswareTxid) {
    219             checkPaymentStatus();
    220             return;
    221         }
    222 
    223218        var xhr = new XMLHttpRequest();
    224219        xhr.open('POST', ajaxUrl, true);
     
    229224                    var response = JSON.parse(xhr.responseText);
    230225                    if (response.success && response.data.status === 'completed') {
    231                         handlePaymentConfirmed({ txid: kaswareTxid, status: 'completed' });
     226                        handlePaymentConfirmed({ txid: kaswareTxid || '', status: 'completed' });
    232227                    }
    233                     // If still pending, do nothing — next poll will retry
    234228                } catch (e) {}
    235229            }
    236230        };
    237         var data = 'action=kasppaga_kasware_confirm&order_id=' + orderId + '&txid=' + encodeURIComponent(kaswareTxid) + '&nonce=' + kaswareNonce;
     231        var data = 'action=kasppaga_order_status&order_id=' + orderId + '&nonce=' + kaswareNonce;
    238232        xhr.send(data);
    239233    }
  • kaspa-payments-gateway-woocommerce/trunk/includes/kaspa-frontend-assets.php

    r3470325 r3470335  
    365365        plugin_dir_url(__DIR__) . 'assets/kaspa-checkout.js',
    366366        array(),
    367         '2.1.0',
     367        '2.2.0',
    368368        true
    369369    );
     
    602602}
    603603
    604 // Payment checking is handled by the transaction polling system
    605 // No duplicate AJAX handler needed here
     604// Lightweight order status check — DB read only, no Kaspa API call.
     605// Used by fast polling after KasWare payment to avoid slow API round-trips.
     606add_action('wp_ajax_kasppaga_order_status', 'kasppaga_check_order_status');
     607add_action('wp_ajax_nopriv_kasppaga_order_status', 'kasppaga_check_order_status');
     608
     609function kasppaga_check_order_status()
     610{
     611    if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'kasppaga_kasware_confirm')) {
     612        wp_send_json_error('Invalid nonce');
     613        return;
     614    }
     615
     616    $order_id = isset($_POST['order_id']) ? intval(sanitize_text_field(wp_unslash($_POST['order_id']))) : 0;
     617    if (!$order_id) {
     618        wp_send_json_error('Missing order ID');
     619        return;
     620    }
     621
     622    $order = wc_get_order($order_id);
     623    if (!$order || $order->get_payment_method() !== 'kaspa') {
     624        wp_send_json_error('Invalid order');
     625        return;
     626    }
     627
     628    if (in_array($order->get_status(), array('processing', 'completed'))) {
     629        wp_send_json_success(array('status' => 'completed'));
     630    } else {
     631        wp_send_json_success(array('status' => 'pending'));
     632    }
     633}
    606634
    607635// AJAX handler for KasWare browser wallet payment confirmation
Note: See TracChangeset for help on using the changeset viewer.