Skip to content

Commit

Permalink
Release 3.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sauliususoniswallee committed Aug 23, 2022
1 parent 2fd0195 commit 3990276
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postfinancecheckout/sdk",
"version": "3.1.1",
"version": "3.1.2",
"description": "PostFinance Checkout SDK for PHP",
"keywords": [
"postfinancecheckout",
Expand Down
22 changes: 19 additions & 3 deletions lib/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ final class ApiClient {
*
* @var array
*/
private $defaultHeaders = [];
private $defaultHeaders = [
'x-meta-sdk-version' => "3.1.2",
'x-meta-sdk-language' => 'php',
'x-meta-sdk-provider' => "PostFinance Checkout",
];

/**
* The user agent that is sent with any request.
*
* @var string
*/
private $userAgent = 'PHP-Client/3.1.1/php';
private $userAgent = 'PHP-Client/3.1.2/php';

/**
* The path to the certificate authority file.
Expand Down Expand Up @@ -138,6 +142,8 @@ public function __construct($userId, $applicationKey) {
$this->serializer = new ObjectSerializer();
$this->isDebuggingEnabled() ? $this->serializer->enableDebugging() : $this->serializer->disableDebugging();
$this->serializer->setDebugFile($this->getDebugFile());
$this->addDefaultHeader('x-meta-sdk-language-version', phpversion());

}

/**
Expand Down Expand Up @@ -311,10 +317,20 @@ public function addDefaultHeader($key, $value) {
throw new \InvalidArgumentException('The header key must be a string.');
}

$defaultHeaders[$key] = $value;
$this->defaultHeaders[$key] = $value;
return $this;
}

/**
* Gets the default headers that will be sent in the request.
*
* @since 3.1.2
* @return string[]
*/
function getDefaultHeaders() {
return $this->defaultHeaders;
}

/**
* Returns true, when debugging is enabled.
*
Expand Down
6 changes: 3 additions & 3 deletions lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Configuration
*
* @var string
*/
protected $userAgent = 'PostFinanceCheckout\Sdk/3.1.1/php';
protected $userAgent = 'PostFinanceCheckout\Sdk/3.1.2/php';

/**
* Debug switch (default set to false)
Expand Down Expand Up @@ -388,8 +388,8 @@ public static function toDebugReport()
$report = 'PHP SDK (PostFinanceCheckout\Sdk) Debug Report:' . PHP_EOL;
$report .= ' OS: ' . php_uname() . PHP_EOL;
$report .= ' PHP Version: ' . PHP_VERSION . PHP_EOL;
$report .= ' OpenAPI Spec Version: 3.1.1' . PHP_EOL;
$report .= ' SDK Package Version: 3.1.1' . PHP_EOL;
$report .= ' OpenAPI Spec Version: 3.1.2' . PHP_EOL;
$report .= ' SDK Package Version: 3.1.2' . PHP_EOL;
$report .= ' Temp Folder Path: ' . self::getDefaultConfiguration()->getTempFolderPath() . PHP_EOL;

return $report;
Expand Down
18 changes: 18 additions & 0 deletions test/ApiClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,23 @@ public function testEmptyResponseWithCurlClient()
$this->apiClient->getTransactionService()->read($this->spaceId, 1);
}

/**
* Tests that the headers in the response contain headers with SDK information by default.
*
* @since 3.1.2
* @return void
*/
public function testSdkHeaders()
{
$headers = $this->apiClient->getDefaultHeaders();
$this->assertGreaterThanOrEqual(4, count($headers));

// Check SDK default header values.
$this->assertEquals($headers['x-meta-sdk-version'], "3.1.2");
$this->assertEquals($headers['x-meta-sdk-language'], 'php');
$this->assertEquals($headers['x-meta-sdk-provider'], "PostFinance Checkout");
$this->assertEquals($headers['x-meta-sdk-language-version'], phpversion());
}

}

0 comments on commit 3990276

Please sign in to comment.