jQuery(document).ready(function ($) {
    function checkPaymentStatus() {
        $.ajax({
            url: walletUpCheckout.ajaxUrl,
            type: 'POST',
            data: { action: 'wallet_up_check_payment', nonce: walletUpCheckout.nonce },
            success: function (response) {
                console.log('AJAX Success:', response);
            },
            error: function (xhr, status, error) {
                console.error('AJAX Error:', { status, error, responseText: xhr.responseText });
            }
        });
    }

    // Run the check on page load and on payment method selection
    checkPaymentStatus();
    $(document.body).on('updated_checkout', checkPaymentStatus);
});
