<?php
/**
 * Afterpay Upsell Gateway Stub
 *
 * Afterpay/Clearpay cannot be used for upsell payments because each transaction
 * requires the customer to authorize via the Afterpay modal/popup.
 * This stub class exists to properly register the gateway with FunnelKit
 * and indicate that upsells are not supported.
 *
 * @package FunnelKit_Square
 * @subpackage Payment
 */

namespace FKWCSQ\Includes\Modules\Payment\Upsell;

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

/**
 * Afterpay class.
 *
 * Stub implementation that indicates Afterpay doesn't support upsells.
 */
class Afterpay extends \WFOCU_Gateway {

	/**
	 * Singleton instance.
	 *
	 * @var self
	 */
	protected static $instance = null;

	/**
	 * Payment gateway key.
	 *
	 * @var string
	 */
	public $key = 'fkwcsq_afterpay';

	/**
	 * Constructor.
	 */
	public function __construct() {
		parent::__construct();
		$this->refund_supported = false;
	}

	/**
	 * Get singleton instance.
	 *
	 * @return self Instance of this class.
	 */
	public static function get_instance() {
		if ( null === self::$instance ) {
			self::$instance = new self();
		}

		return self::$instance;
	}

	/**
	 * Check if the gateway has a token for upsell payments.
	 *
	 * Afterpay requires new authorization for each payment, so this always returns false.
	 *
	 * @param \WC_Order $order The order object.
	 * @return bool Always returns false.
	 */
	public function has_token( $order ) {
		return false;
	}

	/**
	 * Check if the gateway is available for upsells.
	 *
	 * Afterpay is not available for upsells because each payment requires
	 * the customer to go through the Afterpay authorization popup.
	 *
	 * @return bool Always returns false.
	 */
	public function is_available() {
		return false;
	}

	/**
	 * Process the upsell charge.
	 *
	 * This method should never be called since has_token() returns false.
	 *
	 * @param \WC_Order $order The order object.
	 * @return array Error response.
	 */
	public function process_charge( $order ) {
		return array(
			'result'  => 'error',
			'message' => __( 'Afterpay/Clearpay cannot be used for upsell payments.', 'funnelkit-payment-gateway-square-for-woocommerce' ),
		);
	}
}
