Jake Vanderwerf
2026-09-16 a239ef33ec489ce6d0f25ac2f256df0ac54a7e50
inc/integrations/services/Square.php
@@ -14,7 +14,9 @@
use JVBase\integrations\SyncFrom;
use JVBase\integrations\SyncTo;
use JVBase\integrations\Webhooks;
use JVBase\managers\Dashboard\Dashboard;
use JVBase\managers\queue\executors\IntegrationExecutor;
use JVBase\managers\queue\Queue;
use JVBase\managers\queue\TypeConfig;
use JVBase\meta\Sanitizer;
use JVBase\registrar\Registrar;
@@ -252,10 +254,15 @@
   protected function refreshAccessToken(OAuthCredentials $credentials): array
   {
      if (!$this->getClientID() || !$this->getClientSecret())
      if (!$this->getClientID() || !$this->getClientSecret() || empty($credentials->refresh_token)) {
         $this->logError('refreshAccessToken', 'Missing client credentials or refresh token');
         return $this->response(false, 'No client ID or client secret provided');
      }
      $response = wp_remote_post(
         $this->oauth->getToken(),
         [
            'timeout'   => 15,
            'body'   => [
               'client_id'    => $this->getClientID(),
               'client_secret' => $this->getClientSecret(),
@@ -277,16 +284,18 @@
      }
      $data = json_decode(wp_remote_retrieve_body($response));
      if (isset($data['access_token'])) {
         $credentials = [
            'access_token' =>  $data['access_token'],
            'expires_at'   => time() + ($data['expires_in'] ?? 2592000) // 30 days default
         ];
         $this->saveCredentials($credentials);
         return $this->response(true, 'Successfully refreshed access token');
      if (empty($data['access_token'])) {
         $this->logError('refreshAccessToken', 'No access_token in refresh response', ['body' => $data]);
         return $this->response(false, 'No Access Token in Response');
      }
      return $this->response(false, 'Something went wrong that wasn\'t caught - could not refresh access token');
      $credentials = [
         'access_token'  => $data['access_token'],
         'expires_at'    => strtotime($data['expires_at'] ?? '') ?: (time() + 2592000),
         'refresh_token' => $data['refresh_token'] ?? $credentials->refresh_token,
      ];
      $this->saveCredentials($credentials);
      return $this->response(true, 'Successfully refreshed access token');
   }
   protected function getRequestHeaders(): array
@@ -298,7 +307,7 @@
      ];
   }
   protected function handleResponse(\WP_Error|array $response, string $method, string $endpoint): array
   protected function handleResponse(WP_Error|array $response, string $method, string $endpoint): array
   {
      if (is_wp_error($response) && $response->get_error_message() === 'rate_limit_exceeded') {
         return $this->response(false, 'Rate limit exceeded');