From a239ef33ec489ce6d0f25ac2f256df0ac54a7e50 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 16 Sep 2026 00:07:34 +0000
Subject: [PATCH] =Tackling the integrations again. This time Helcim, with some minnor edits to GMB and Square
---
inc/integrations/services/GoogleMyBusiness.php | 69 ++++++++++++++++++++++++++++++++++
1 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/inc/integrations/services/GoogleMyBusiness.php b/inc/integrations/services/GoogleMyBusiness.php
index 17d7df1..694285e 100644
--- a/inc/integrations/services/GoogleMyBusiness.php
+++ b/inc/integrations/services/GoogleMyBusiness.php
@@ -169,12 +169,81 @@
protected function refreshAccessToken(OAuthCredentials $credentials): array
{
+ if (empty($this->getClientID()) || empty($this->getClientSecret()) || empty($credentials->refresh_token)) {
+ $this->logError('refreshAccessToken', 'Missing refresh token');
+ return $this->response(false, 'Missing client ID, client Secret, or refresh token');
+ }
+ $response = wp_remote_post(
+ $this->oauth->getToken(),
+ [
+ 'timeout' => 15,
+ 'body' => [
+ 'grant_type' => 'refresh_token',
+ 'refresh_token' => $credentials->refresh_token,
+ 'client_id' =>$this->getClientID(),
+ 'client_secret' =>$this->getClientSecret()
+ ],
+ 'headers' => $this->getOAuthRequestHeaders()
+ ]
+ );
+ if (is_wp_error($response)) {
+ $this->logError(
+ 'refreshAccessToken',
+ 'Failed to refresh GMB Token',
+ [
+ 'error' => $response->get_error_message()
+ ]
+ );
+ return $this->response(false, 'Failed to refresh GMB Token');
+ }
+ $data = json_decode(wp_remote_retrieve_body($response), true);
+ if (empty($data['access_token'])) {
+ $this->logError('refreshAccessToken', 'No access token in response');
+ return $this->response(false, 'No access token in response');
+ }
+ $credentials = [
+ 'access_token' => $data['access_token'],
+ 'expires_at' => time() + (int)($data['expires_in']??3600),
+ // Google usually omits refresh_token on refresh — keep the old one
+ 'refresh_token' => $body['refresh_token'] ?? $credentials->refresh_token,
+ ];
+ $this->saveCredentials($credentials);
+
+ return $this->response(true, 'Successfully refreshed token');
}
/*********************************************************
* UTILITY
*********************************************************/
+ protected function getClientID():string|false
+ {
+ $switch = false;
+ if ($this->userID !== null) {
+ $switch = $this->userID;
+ $this->switchUser(null);
+ }
+
+ $ID = $this->loadCredentials()['client_id']??false;
+ if ($switch) {
+ $this->switchUser($switch);
+ }
+ return $ID;
+ }
+ protected function getClientSecret():string|false
+ {
+ $switch = false;
+ if ($this->userID !== null) {
+ $switch = $this->userID;
+ $this->switchUser(null);
+ }
+
+ $ID = $this->loadCredentials()['client_secret']??false;
+ if ($switch) {
+ $this->switchUser($switch);
+ }
+ return $ID;
+ }
protected function getAccountID():string|false
{
return $this->loadCredentials()['account_id']??false;
--
Gitblit v1.10.0