/**
* Loads the SBP token from current session
* If no valid token is available, queries the server for a new one
*
* @throws RuntimeException
*
* @return AccessTokenStruct Token to access the API
*/
private function getToken(string
$shopwareId, string
$password): AccessTokenStruct
{ $token =
Shopware()->
BackendSession()->
get('accessToken'
);
if (empty($token) ||
$token->
getExpire()->
getTimestamp() <=
strtotime('+30 seconds'
)) { if (empty($shopwareId) ||
empty($password)) { throw new RuntimeException('Could not login - missing login data'
);
} $accountManagerService =
$this->container->
get('shopware_plugininstaller.account_manager_service'
);
$token =
$accountManagerService->
getToken($shopwareId,
$password);
Shopware()->
BackendSession()->
set('accessToken',
$token);
}