Jake Vanderwerf
2026-07-12 c204185ae86a98994f80010abf35a190c9406739
inc/integrations/services/Square.php
File was renamed from inc/integrations/Square.php
@@ -1,18 +1,19 @@
<?php
namespace JVBase\integrations;
namespace JVBase\integrations\services;
use Exception;
use JVBase\integrations\Integrations;
use JVBase\managers\queue\executors\IntegrationExecutor;
use JVBase\managers\queue\TypeConfig;
use JVBase\meta\Form;
use JVBase\meta\Meta;
use Exception;
use JVBase\registrar\Fields;
use JVBase\registrar\Posts;
use JVBase\registrar\Registrar;
use JVBase\ui\Checkout;
use JVBase\ui\CRUDSkeleton;
use WP_Error;
use JVBase\ui\Checkout;
use JVBase\managers\queue\TypeConfig;
use JVBase\managers\queue\executors\IntegrationExecutor;
use WP_Post;
use WP_Query;
use WP_User;
if (!defined('ABSPATH')) {
   exit;
@@ -86,16 +87,14 @@
   protected string $locationId = '';
   protected array $locations = [];
   protected static array $instances = [];
   protected static Square $instance;
   public static function getInstance(?int $userID = null):self
   public static function getInstance():self
   {
      $key = is_null($userID) ? 'base' : $userID;
      if (!array_key_exists($key, self::$instances)) {
         self::$instances[$key] = new self($userID);
      if (!isset(self::$instance)) {
         self::$instance = new self();
      }
      return self::$instances[$key];
      return self::$instance;
   }
   protected function __construct(?int $userID = null)
@@ -190,9 +189,9 @@
         'delete' => true
      ];
      $this->supportsWebp = false;
      $this->handleWebhooks = true;
      $this->hasWebhooks = true;
      parent::__construct($userID);
      parent::__construct();
      // Add Square-specific actions
      $this->actions = array_merge(
@@ -858,6 +857,7 @@
   protected function registerAdditionalHooks(): void
   {
      if (!$this->isSetUp()) {
         error_log('Square is not setup');
         return;
      }
@@ -932,7 +932,7 @@
   /**
    * Handle post save for Square sync
    */
   protected function handleTheSavePost(int $postID, \WP_Post $post, bool $update, array $settings): void
   protected function handleTheSavePost(int $postID, WP_Post $post, bool $update, array $settings): void
   {
      error_log('==== [Square]::handleTheSavePost ====');
      $this->queueOperation(self::$syncTo, [
@@ -1113,7 +1113,7 @@
         if (!in_array($post_id, $success)) {
            $found_in_errors = false;
            foreach ($errors as $error) {
               if (strpos($error, "Post $post_id") !== false) {
               if (str_contains($error, "Post $post_id")) {
                  $found_in_errors = true;
                  break;
               }
@@ -1542,7 +1542,7 @@
      }
      // Set user role (assuming you have a customer role defined)
      $user = new \WP_User($user_id);
      $user = new WP_User($user_id);
      $user->set_role(BASE.'foodie');
      // Generate password reset key
@@ -1576,7 +1576,7 @@
   /**
    * Send welcome email with password setup
    */
   private function sendWelcomeEmail(\WP_User $user, string $reset_key): void
   private function sendWelcomeEmail(WP_User $user, string $reset_key): void
   {
      $site_name = get_bloginfo('name');
      $reset_url = get_home_url(null, "wp-login.php?action=rp&key=$reset_key&login=" . rawurlencode($user->user_login), 'login');
@@ -2450,7 +2450,7 @@
            $sanitized[$key] = sanitize_key($value);
         }
         // Handle boolean fields
         elseif ($key === 'use_sandbox' || strpos($key, 'enable_') === 0) {
         elseif ($key === 'use_sandbox' || str_starts_with($key, 'enable_')) {
            $sanitized[$key] = (bool) $value;
         }
         // Handle numeric fields
@@ -3346,8 +3346,7 @@
      // Fetch from Square
      $response = $this->getRequest('orders/' . $order_id);
      if (!is_wp_error($response)) {
         $state = $response['order']['state'] ?? null;
         return $state;
         return $response['order']['state'] ?? null;
      }
      return null;
@@ -3430,7 +3429,7 @@
   }
   public function renderDashPage():void
   {
      $instance = $this->determineInstance();
      $this->determineUser();
      $crud = new CRUDSkeleton();
      $crud->icon('receipt');
@@ -3452,13 +3451,7 @@
      $crud->render();
   }
   protected function determineInstance():self
   {
      if (current_user_can('manage_options')) {
         return self::$instances['base'];
      }
      return self::getInstance(get_current_user_id());
   }
   public function getOrderPost(string $order_id):int|false
   {