Jake Vanderwerf
2026-09-16 a239ef33ec489ce6d0f25ac2f256df0ac54a7e50
inc/integrations/services/Square.php
@@ -254,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(),
@@ -279,17 +284,19 @@
      }
      $data = json_decode(wp_remote_retrieve_body($response));
      if (isset($data['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');
      }
         $credentials = [
            'access_token' =>  $data['access_token'],
            'expires_at'   => time() + ($data['expires_in'] ?? 2592000) // 30 days default
         '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');
      }
      return $this->response(false, 'Something went wrong that wasn\'t caught - could not refresh access token');
   }
   protected function getRequestHeaders(): array
   {