| Server IP : 85.158.181.41 / Your IP : 216.73.217.12 Web Server : Apache System : Linux cloud9-vm129 6.1.178+1-ph #ph SMP PREEMPT_DYNAMIC Wed Jul 29 09:00:54 UTC 2026 x86_64 User : moncbefd ( 1024) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/moncbefd/www.moneta.at/GXModules/Gambio/AdminFeed/Services/ShopInformation/ |
Upload File : |
<?php
/* --------------------------------------------------------------
HubClient.php 2018-08-10
Gambio GmbH
http://www.gambio.de
Copyright (c) 2018 Gambio GmbH
Released under the GNU General Public License (Version 2)
[http://www.gnu.org/licenses/gpl-2.0.html]
--------------------------------------------------------------
*/
namespace Gambio\AdminFeed\Services\ShopInformation;
use AuthHashCreator;
use Exception;
use Gambio\AdminFeed\Adapters\GxAdapter;
use Gambio\AdminFeed\CurlClient;
use HubPublic\Exceptions\CurlRequestException;
use HubSessionsApiClient;
use UnexpectedValueException;
/**
* Class HubClient
*
* @package Gambio\AdminFeed\Services\ShopInformation
*/
class HubClient
{
/**
* @var Settings
*/
private $settings;
/**
* @var GxAdapter
*/
private $gxAdapter;
/**
* @var CurlClient
*/
private $curl;
/**
* HubClient constructor.
*
* @param Settings $settings
* @param GxAdapter $gxAdapter
* @param CurlClient $curl
*/
public function __construct(Settings $settings, GxAdapter $gxAdapter, CurlClient $curl)
{
$this->settings = $settings;
$this->gxAdapter = $gxAdapter;
$this->curl = $curl;
}
/**
* Returns the hub modules data.
*
* @return array
*/
public function getHubModulesData()
{
try {
$hubClientKey = $this->settings->getHubClientKey();
if (empty($hubClientKey)) {
return [];
}
$hubSessionKey = $this->startHubSession();
if (empty($hubSessionKey)) {
return [];
}
$url = $this->settings->getGambioHubConfigUrl() . '/clients/' . $hubClientKey . '/sessions/'
. $hubSessionKey . '/payment_modules?language=en';
$this->curl->executeGet($url);
if ($this->curl->getStatusCode() !== 200) {
return [];
}
$modulesData = json_decode($this->curl->getContent(), true);
} catch (Exception $e) {
return [];
}
return $modulesData;
}
/**
* @return string
*/
private function startHubSession()
{
$languageCode = $this->gxAdapter->getCurrentLanguageCode();
$hubServiceFactory = $this->gxAdapter->mainFactoryCreate('HubServiceFactory');
$hubSessionKeyService = $hubServiceFactory->createHubSessionKeyService();
$hubClientKeyConfiguration = $this->gxAdapter->mainFactoryCreate('HubClientKeyConfiguration');
$curlRequest = $this->gxAdapter->getHubCurlRequest();
$logControl = $this->gxAdapter->getLogControl();
$hubSettings = $this->gxAdapter->mainFactoryCreate('HubSettings',
$this->settings->getGambioHubCurlTimeout());
/** @var HubSessionsApiClient $hubSessionsApiClient */
$hubSessionsApiClient = $this->gxAdapter->mainFactoryCreate('HubSessionsApiClient',
$this->settings->getGambioHubUrl(),
$hubSessionKeyService,
$hubClientKeyConfiguration,
$curlRequest,
$logControl,
$hubSettings);
$authHash = AuthHashCreator::create();
try {
return $hubSessionsApiClient->startSession($authHash,
$this->settings->getHttpServer()
. $this->settings->getShopDirectory(),
$languageCode);
} catch (UnexpectedValueException $e) {
AuthHashCreator::invalidate($authHash);
} catch (CurlRequestException $e) {
AuthHashCreator::invalidate($authHash);
}
return '';
}
}