Skip to content

Commit

Permalink
Release 3.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
wallee-deployment-user committed Jan 9, 2023
1 parent 3990276 commit 12c5f71
Show file tree
Hide file tree
Showing 97 changed files with 4,740 additions and 648 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2022 wallee AG
Copyright 2023 wallee AG

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ $client = new \PostFinanceCheckout\Sdk\ApiClient($userId, $secret);
$httpClientType = \PostFinanceCheckout\Sdk\Http\HttpClientFactory::TYPE_CURL; // or \PostFinanceCheckout\Sdk\Http\HttpClientFactory::TYPE_SOCKET

$client->setHttpClientType($httpClientType);

//Setup a custom connection timeout if needed. (Default value is: 25 seconds)
$client->setConnectionTimeout(20);
```

You can also specify the HTTP client via the `PFC_HTTP_CLIENT` environment variable. The possible string values are `curl` or `socket`.
Expand Down
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.2",
"version": "3.1.4",
"description": "PostFinance Checkout SDK for PHP",
"keywords": [
"postfinancecheckout",
Expand Down
36 changes: 27 additions & 9 deletions lib/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class ApiClient {
* @var array
*/
private $defaultHeaders = [
'x-meta-sdk-version' => "3.1.2",
'x-meta-sdk-version' => "3.1.4",
'x-meta-sdk-language' => 'php',
'x-meta-sdk-provider' => "PostFinance Checkout",
];
Expand All @@ -58,7 +58,7 @@ final class ApiClient {
*
* @var string
*/
private $userAgent = 'PHP-Client/3.1.2/php';
private $userAgent = 'PHP-Client/3.1.4/php';

/**
* The path to the certificate authority file.
Expand All @@ -74,13 +74,19 @@ final class ApiClient {
*/
private $enableCertificateAuthorityCheck = true;

/**
/**
* the constant for the default connection time out
*
* @var integer
*/
const INITIAL_CONNECTION_TIMEOUT = 25;

/**
* The connection timeout in seconds.
*
* @var integer
*/
private $connectionTimeout = 20;
CONST CONNECTION_TIMEOUT = 20;
private $connectionTimeout;

/**
* The http client type to use for communication.
Expand Down Expand Up @@ -138,12 +144,12 @@ public function __construct($userId, $applicationKey) {
$this->userId = $userId;
$this->applicationKey = $applicationKey;

$this->connectionTimeout = self::INITIAL_CONNECTION_TIMEOUT;
$this->certificateAuthority = dirname(__FILE__) . '/ca-bundle.crt';
$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 @@ -254,7 +260,7 @@ public function setConnectionTimeout($connectionTimeout) {
* @return ApiClient
*/
public function resetConnectionTimeout() {
$this->connectionTimeout = self::CONNECTION_TIMEOUT;
$this->connectionTimeout = self::INITIAL_CONNECTION_TIMEOUT;
return $this;
}

Expand Down Expand Up @@ -461,8 +467,8 @@ public function selectHeaderContentType($contentType) {
* @throws \PostFinanceCheckout\Sdk\Http\ConnectionException
* @throws \PostFinanceCheckout\Sdk\VersioningException
*/
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType = null, $endpointPath = null) {
$request = new HttpRequest($this->getSerializer(), $this->buildRequestUrl($resourcePath, $queryParams), $method, $this->generateUniqueToken());
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $timeOut, $responseType = null, $endpointPath = null) {
$request = new HttpRequest($this->getSerializer(), $this->buildRequestUrl($resourcePath, $queryParams), $method, $this->generateUniqueToken(), $timeOut);
$request->setUserAgent($this->getUserAgent());
$request->addHeaders(array_merge(
(array)$this->defaultHeaders,
Expand Down Expand Up @@ -576,6 +582,18 @@ public function getAccountService() {
return $this->accountService;
}

protected $analyticsQueryService;

/**
* @return \PostFinanceCheckout\Sdk\Service\AnalyticsQueryService
*/
public function getAnalyticsQueryService() {
if(is_null($this->analyticsQueryService)){
$this->analyticsQueryService = new \PostFinanceCheckout\Sdk\Service\AnalyticsQueryService($this);
}
return $this->analyticsQueryService;
}

protected $applicationUserService;

/**
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.2/php';
protected $userAgent = 'PostFinanceCheckout\Sdk/3.1.4/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.2' . PHP_EOL;
$report .= ' SDK Package Version: 3.1.2' . PHP_EOL;
$report .= ' OpenAPI Spec Version: 3.1.4' . PHP_EOL;
$report .= ' SDK Package Version: 3.1.4' . PHP_EOL;
$report .= ' Temp Folder Path: ' . self::getDefaultConfiguration()->getTempFolderPath() . PHP_EOL;

return $report;
Expand Down
4 changes: 2 additions & 2 deletions lib/Http/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function isSupported() {
public function send(ApiClient $apiClient, HttpRequest $request) {
$curl = curl_init();
// set timeout, if needed
if ($apiClient->getConnectionTimeout() !== 0) {
curl_setopt($curl, CURLOPT_TIMEOUT, $apiClient->getConnectionTimeout());
if ($request->getTimeOut() !== 0) {
curl_setopt($curl, CURLOPT_TIMEOUT, $request->getTimeOut());
}

// set life-time for DNS cache entries
Expand Down
19 changes: 18 additions & 1 deletion lib/Http/HttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ final class HttpRequest {
*/
private $logToken;

/**
* The connection time out limit in seconds.
*
* @var integer
*/
private $timeOut;

/**
* Constructor.
*
Expand All @@ -174,7 +181,7 @@ final class HttpRequest {
* @param string $method the request method (typically GET or POST)
* @param string $logToken the request's log token
*/
public function __construct(ObjectSerializer $serializer, $url, $method, $logToken) {
public function __construct(ObjectSerializer $serializer, $url, $method, $logToken, $timeOut) {
$this->serializer = $serializer;
$this->url = $url;
$this->method = strtoupper($method);
Expand All @@ -184,6 +191,7 @@ public function __construct(ObjectSerializer $serializer, $url, $method, $logTok
$this->port = parse_url($url, PHP_URL_PORT);
$this->query = parse_url($url, PHP_URL_QUERY);
$this->logToken = $logToken;
$this->timeOut = $timeOut;

$this->addHeader(self::HEADER_KEY_HOST, $this->host);
$this->addHeader(self::HEADER_LOG_TOKEN, $this->logToken);
Expand Down Expand Up @@ -334,6 +342,15 @@ public function getLogToken() {
return $this->logToken;
}

/**
* Returns the time out.
*
* @return integer
*/
public function getTimeOut() {
return $this->timeOut;
}

/**
* Returns the query part of the request as string.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Http/SocketHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private function readFromSocket(ApiClient $apiClient, HttpRequest $request, $soc
$responseMessage = '';
$chunked = false;
$chunkLength = false;
$maxTime = $this->getStartTime() + $apiClient->getConnectionTimeout();
$maxTime = $this->getStartTime() + $request->getTimeOut();
$contentLength = -1;
$endReached = false;
while ($maxTime > time() && !feof($socket) && !$endReached) {
Expand Down
Loading

0 comments on commit 12c5f71

Please sign in to comment.