class Connect in Commerce Square Connect 8
Represents the Connect application for Square.
Hierarchy
- class \Drupal\commerce_square\Connect
Expanded class hierarchy of Connect
1 file declares its use of Connect
- Square.php in src/
Plugin/ Commerce/ PaymentGateway/ Square.php
1 string reference to 'Connect'
1 service uses Connect
File
- src/
Connect.php, line 13
Namespace
Drupal\commerce_squareView source
class Connect {
/**
* The application settings.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $settings;
/**
* The state.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* Constructs a new Connect object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\State\StateInterface $state
* The state.
*/
public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state) {
$this->settings = $config_factory
->get('commerce_square.settings');
$this->state = $state;
}
/**
* Gets the application name.
*
* @return string
* The application name.
*/
public function getAppName() {
return $this->settings
->get('app_name');
}
/**
* Gets the application secret.
*
* @return string
* The secret.
*/
public function getAppSecret() {
return $this->settings
->get('app_secret');
}
/**
* Gets the application ID.
*
* @param string $mode
* The mode.
*
* @return string
* The application ID.
*/
public function getAppId($mode) {
if ($mode == 'production') {
return $this->settings
->get('production_app_id');
}
return $this->settings
->get('sandbox_app_id');
}
/**
* Gets the access token.
*
* @param string $mode
* The mode.
*
* @return string
* The access token.
*/
public function getAccessToken($mode) {
if ($mode == 'production') {
return $this->state
->get('commerce_square.production_access_token');
}
return $this->settings
->get('sandbox_access_token');
}
/**
* Gets the refresh token.
*
* @param string $mode
* The mode.
*
* @return string
* The refresh token.
*/
public function getRefreshToken($mode) {
if ($mode === 'production') {
return $this->state
->get('commerce_square.production_refresh_token');
}
return '';
}
/**
* Gets the access token expiration timestamp.
*
* @param string $mode
* The mode.
*
* @return int
* The expiration timestamp. Or -1 if sandbox.
*/
public function getAccessTokenExpiration($mode) {
if ($mode == 'production') {
return $this->state
->get('commerce_square.production_access_token_expiry');
}
return -1;
}
/**
* Gets a Square API client.
*
* @param string $mode
* The mode.
*
* @return \SquareConnect\ApiClient
* A configured API client for the Connect application.
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Connect:: |
protected | property | The application settings. | |
Connect:: |
protected | property | The state. | |
Connect:: |
public | function | Gets the access token. | |
Connect:: |
public | function | Gets the access token expiration timestamp. | |
Connect:: |
public | function | Gets the application ID. | |
Connect:: |
public | function | Gets the application name. | |
Connect:: |
public | function | Gets the application secret. | |
Connect:: |
public | function | Gets a Square API client. | |
Connect:: |
public | function | Gets the refresh token. | |
Connect:: |
public | function | Constructs a new Connect object. |