| | |
| | | */ |
| | | protected function exchangeOAuthCode(string $code): ?array |
| | | { |
| | | error_log('Exchanging tokens with credentials: '.print_r($this->credentials, true)); |
| | | |
| | | $this->ensureInitialized(); |
| | | |
| | | // Prepare the request body as an array |
| | |
| | | } |
| | | |
| | | $data = json_decode(wp_remote_retrieve_body($response), true); |
| | | error_log('OAuth Response: '.print_r($data, true)); |
| | | if (isset($data['access_token'])) { |
| | | return [ |
| | | 'access_token' => $data['access_token'], |
| | |
| | | |
| | | $data = json_decode(wp_remote_retrieve_body($response), true); |
| | | |
| | | error_log('RefreshAccessToken Response: '.print_r($data, true)); |
| | | if (isset($data['access_token'])) { |
| | | $this->credentials['access_token'] = $data['access_token']; |
| | | $this->credentials['expires_at'] = time() + ($data['expires_in'] ?? 2592000); // 30 days |
| | |
| | | { |
| | | // Skip if we don't have credentials yet (during OAuth flow) |
| | | if (empty($this->credentials['access_token'])) { |
| | | error_log('[Square] Skipping loadLocations - no access token yet'); |
| | | return; |
| | | } |
| | | try { |
| | |
| | | */ |
| | | protected function handleTheSavePost(int $postID, \WP_Post $post, bool $update, array $settings): void |
| | | { |
| | | error_log('Queuing Sync to Square'); |
| | | // Queue the sync operation |
| | | $this->queueOperation('sync_to_square', [ |
| | | 'items' => [$postID], |
| | |
| | | |
| | | // Validate environment setting |
| | | if (isset($credentials['environment'])) { |
| | | error_log('Environment: '.print_r($credentials['environment'], true)); |
| | | $validEnvironments = ['sandbox', 'production']; |
| | | if (!in_array($credentials['environment'], $validEnvironments)) { |
| | | $this->logError('Invalid environment setting', [ |