Connect.php in Commerce Square Connect 8
File
src/Connect.php
View source
<?php
namespace Drupal\commerce_square;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\State\StateInterface;
use SquareConnect\ApiClient;
use SquareConnect\Configuration;
class Connect {
protected $settings;
protected $state;
public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state) {
$this->settings = $config_factory
->get('commerce_square.settings');
$this->state = $state;
}
public function getAppName() {
return $this->settings
->get('app_name');
}
public function getAppSecret() {
return $this->settings
->get('app_secret');
}
public function getAppId($mode) {
if ($mode == 'production') {
return $this->settings
->get('production_app_id');
}
return $this->settings
->get('sandbox_app_id');
}
public function getAccessToken($mode) {
if ($mode == 'production') {
return $this->state
->get('commerce_square.production_access_token');
}
return $this->settings
->get('sandbox_access_token');
}
public function getRefreshToken($mode) {
if ($mode === 'production') {
return $this->state
->get('commerce_square.production_refresh_token');
}
return '';
}
public function getAccessTokenExpiration($mode) {
if ($mode == 'production') {
return $this->state
->get('commerce_square.production_access_token_expiry');
}
return -1;
}
public function getClient($mode) {
$config = new Configuration();
if ($mode === 'sandbox') {
$config
->setHost('https://connect.squareupsandbox.com');
}
$config
->setAccessToken($this
->getAccessToken($mode));
return new ApiClient($config);
}
}
Classes
Name |
Description |
Connect |
Represents the Connect application for Square. |