Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions .github/workflows/notification.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"homepage": "https://github.com/sumup"
}
],
"scripts": {
"cs": "php-cs-fixer fix --dry-run --diff"
},
"require": {
"php": "^5.6|^7.0|^8.0"
},
Expand Down
13 changes: 13 additions & 0 deletions examples/simple.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/*
* Run with `php simple.php`, don't forget to set SUMUP_API_KEY anv variable with your API key
*/

require __DIR__ . '/../vendor/autoload.php';
$sumup = new \SumUp\SumUp([
'api_key' => getenv('SUMUP_API_KEY'),
]);

$dba = $sumup->getMerchantService()->getDoingBusinessAs();
print_r($dba->getBody());
27 changes: 23 additions & 4 deletions src/SumUp/Application/ApplicationConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ class ApplicationConfiguration implements ApplicationConfigurationInterface
*/
protected $customHeaders;

/**
* The API key for authentication.
*
* @var string|null
*/
protected $apiKey;

/**
* Create a new application configuration.
*
Expand All @@ -115,6 +122,7 @@ class ApplicationConfiguration implements ApplicationConfigurationInterface
public function __construct(array $config = [])
{
$config = array_merge([
'api_key' => null,
'app_id' => null,
'app_secret' => null,
'grant_type' => 'authorization_code',
Expand All @@ -129,6 +137,7 @@ public function __construct(array $config = [])
'custom_headers' => []
], $config);

$this->apiKey = $config['api_key'];
$this->setAppId($config['app_id']);
$this->setAppSecret($config['app_secret']);
$this->setScopes($config['scopes']);
Expand Down Expand Up @@ -273,6 +282,16 @@ public function getCustomHeaders()
return $this->customHeaders;
}

/**
* Returns the API key if set.
*
* @return string|null
*/
public function getApiKey()
{
return $this->apiKey;
}

/**
* Set application ID.
*
Expand All @@ -282,8 +301,8 @@ public function getCustomHeaders()
*/
protected function setAppId($appId)
{
if (empty($appId)) {
throw new SumUpConfigurationException('Missing mandatory parameter app_id');
if (empty($appId) && empty($this->apiKey)) {
throw new SumUpConfigurationException('Missing mandatory parameter app_id or api_key');
}
$this->appId = $appId;
}
Expand All @@ -297,8 +316,8 @@ protected function setAppId($appId)
*/
protected function setAppSecret($appSecret)
{
if (empty($appSecret)) {
throw new SumUpConfigurationException('Missing mandatory parameter app_secret');
if (empty($appSecret) && empty($this->apiKey)) {
throw new SumUpConfigurationException('Missing mandatory parameter app_secret or api_key');
}
$this->appSecret = $appSecret;
}
Expand Down
7 changes: 7 additions & 0 deletions src/SumUp/Application/ApplicationConfigurationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,11 @@ public function getForceGuzzle();
* @return array
*/
public function getCustomHeaders();

/**
* Returns the API key if set.
*
* @return string|null
*/
public function getApiKey();
}
10 changes: 10 additions & 0 deletions src/SumUp/Services/Authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public function __construct(SumUpHttpClientInterface $client, ApplicationConfigu
*/
public function getToken()
{
if (!empty($this->appConfig->getApiKey())) {
return new AccessToken(
$this->appConfig->getApiKey(),
'Bearer',
null,
[],
null
);
}

$accessToken = null;
if (!empty($this->appConfig->getAccessToken())) {
$accessToken = new AccessToken(
Expand Down
Loading