<?php
/**
 * Cash App Upsell Gateway Stub
 *
 * Cash App Pay cannot be used for upsell payments because each transaction
 * requires the customer to authorize via the Cash App button/app.
 * 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;
}

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

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

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

	/**
	 * 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.
	 *
	 * Cash App 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.
	 *
	 * Cash App is not available for upsells.
	 *
	 * @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' => __( 'Cash App Pay cannot be used for upsell payments.', 'funnelkit-payment-gateway-square-for-woocommerce' ),
		);
	}
}
