<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
<?php
/**
 * PointOfSaleOrderUtil class file.
 */

declare( strict_types = 1 );

namespace Automattic\WooCommerce\Internal\Orders;

use WC_Abstract_Order;

/**
 * Helper class for POS order related functionality.
 *
 * @internal Just for internal use.
 */
class PointOfSaleOrderUtil {
	/**
	 * Check if the order is a POS (Point of Sale) order.
	 *
	 * This method determines if an order was created via the POS REST API
	 * by checking the 'created_via' property of the order.
	 *
	 * @param WC_Abstract_Order $order Order instance.
	 * @return bool True if the order is a POS order, false otherwise.
	 */
	public static function is_pos_order( WC_Abstract_Order $order ): bool {
		return 'pos-rest-api' === $order->get_created_via();
	}

	/**
	 * Check if the order was paid at POS, regardless of where it was created.
	 *
	 * An order is considered paid at POS if:
	 * - It was created via the POS REST API, OR
	 * - It was paid via card terminal (_wcpay_ipp_channel = mobile_pos), OR
	 * - It was paid via cash at POS (_cash_change_amount meta present).
	 *
	 * @param WC_Abstract_Order $order Order instance.
	 * @return bool
	 *
	 * @since 10.6.0
	 */
	public static function is_order_paid_at_pos( WC_Abstract_Order $order ): bool {
		if ( self::is_pos_order( $order ) ) {
			return true;
		}

		if ( 'mobile_pos' === $order->get_meta( '_wcpay_ipp_channel' ) ) {
			return true;
		}

		if ( '' !== $order->get_meta( '_cash_change_amount' ) ) {
			return true;
		}

		return false;
	}
}
