<?php
/**
 * BTC/ETH polling fallback (used when no license is active).
 *
 * Loads BTC and ETH transaction checkers. Each checker takes a WC_Order
 * and updates meta (cryptoniq_is_paid / cryptoniq_is_failed) when payment
 * is detected or the window expires. With a license active these are
 * never called — the API server pushes webhooks for every coin instead.
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit();
}

require_once CRYPTONIQ_DIR_PATH . 'coins/btc.php';
require_once CRYPTONIQ_DIR_PATH . 'coins/eth.php';

/**
 * Run a polling check for the given order. Reads coin ticker from order
 * meta and calls the appropriate per-chain checker. Only BTC and ETH are
 * supported by polling; other coins require a license (webhook-based).
 */
function cryptoniq_lite_check_order( $order ) {
    if ( ! $order || ! is_a( $order, 'WC_Order' ) ) {
        return;
    }

    $coin = $order->get_meta( 'cryptoniq_coin_ticker' );
    if ( $coin === 'BTC' ) {
        cryptoniq_coin_check_btc( $order );
    } elseif ( $coin === 'ETH' ) {
        cryptoniq_coin_check_eth( $order );
    }
}
