mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-08 02:28:23 +01:00
Update Stripe lib to 10.7.0
This commit is contained in:
@@ -21,6 +21,10 @@ class ApiRequestor
|
||||
* @var HttpClient\ClientInterface
|
||||
*/
|
||||
private static $_httpClient;
|
||||
/**
|
||||
* @var HttpClient\StreamingClientInterface
|
||||
*/
|
||||
private static $_streamingHttpClient;
|
||||
|
||||
/**
|
||||
* @var RequestTelemetry
|
||||
@@ -123,6 +127,26 @@ class ApiRequestor
|
||||
return [$resp, $myApiKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param callable $readBodyChunkCallable
|
||||
* @param null|array $params
|
||||
* @param null|array $headers
|
||||
*
|
||||
* @throws Exception\ApiErrorException
|
||||
*/
|
||||
public function requestStream($method, $url, $readBodyChunkCallable, $params = null, $headers = null)
|
||||
{
|
||||
$params = $params ?: [];
|
||||
$headers = $headers ?: [];
|
||||
list($rbody, $rcode, $rheaders, $myApiKey) =
|
||||
$this->_requestRawStreaming($method, $url, $params, $headers, $readBodyChunkCallable);
|
||||
if ($rcode >= 300) {
|
||||
$this->_interpretResponse($rbody, $rcode, $rheaders);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $rbody a JSON string
|
||||
* @param int $rcode
|
||||
@@ -271,9 +295,8 @@ class ApiRequestor
|
||||
/**
|
||||
* @static
|
||||
*
|
||||
* @param string $disabledFunctionsOutput - String value of the 'disable_function' setting, as output by \ini_get('disable_functions')
|
||||
* @param string $disableFunctionsOutput - String value of the 'disable_function' setting, as output by \ini_get('disable_functions')
|
||||
* @param string $functionName - Name of the function we are interesting in seeing whether or not it is disabled
|
||||
* @param mixed $disableFunctionsOutput
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -328,18 +351,7 @@ class ApiRequestor
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param array $params
|
||||
* @param array $headers
|
||||
*
|
||||
* @throws Exception\AuthenticationException
|
||||
* @throws Exception\ApiConnectionException
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _requestRaw($method, $url, $params, $headers)
|
||||
private function _prepareRequest($method, $url, $params, $headers)
|
||||
{
|
||||
$myApiKey = $this->_apiKey;
|
||||
if (!$myApiKey) {
|
||||
@@ -416,6 +428,24 @@ class ApiRequestor
|
||||
$rawHeaders[] = $header . ': ' . $value;
|
||||
}
|
||||
|
||||
return [$absUrl, $rawHeaders, $params, $hasFile, $myApiKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param array $params
|
||||
* @param array $headers
|
||||
*
|
||||
* @throws Exception\AuthenticationException
|
||||
* @throws Exception\ApiConnectionException
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _requestRaw($method, $url, $params, $headers)
|
||||
{
|
||||
list($absUrl, $rawHeaders, $params, $hasFile, $myApiKey) = $this->_prepareRequest($method, $url, $params, $headers);
|
||||
|
||||
$requestStartMs = Util\Util::currentTimeMillis();
|
||||
|
||||
list($rbody, $rcode, $rheaders) = $this->httpClient()->request(
|
||||
@@ -428,7 +458,46 @@ class ApiRequestor
|
||||
|
||||
if (isset($rheaders['request-id'])
|
||||
&& \is_string($rheaders['request-id'])
|
||||
&& \strlen($rheaders['request-id']) > 0) {
|
||||
&& '' !== $rheaders['request-id']) {
|
||||
self::$requestTelemetry = new RequestTelemetry(
|
||||
$rheaders['request-id'],
|
||||
Util\Util::currentTimeMillis() - $requestStartMs
|
||||
);
|
||||
}
|
||||
|
||||
return [$rbody, $rcode, $rheaders, $myApiKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param array $params
|
||||
* @param array $headers
|
||||
* @param callable $readBodyChunkCallable
|
||||
*
|
||||
* @throws Exception\AuthenticationException
|
||||
* @throws Exception\ApiConnectionException
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _requestRawStreaming($method, $url, $params, $headers, $readBodyChunkCallable)
|
||||
{
|
||||
list($absUrl, $rawHeaders, $params, $hasFile, $myApiKey) = $this->_prepareRequest($method, $url, $params, $headers);
|
||||
|
||||
$requestStartMs = Util\Util::currentTimeMillis();
|
||||
|
||||
list($rbody, $rcode, $rheaders) = $this->streamingHttpClient()->requestStream(
|
||||
$method,
|
||||
$absUrl,
|
||||
$rawHeaders,
|
||||
$params,
|
||||
$hasFile,
|
||||
$readBodyChunkCallable
|
||||
);
|
||||
|
||||
if (isset($rheaders['request-id'])
|
||||
&& \is_string($rheaders['request-id'])
|
||||
&& '' !== $rheaders['request-id']) {
|
||||
self::$requestTelemetry = new RequestTelemetry(
|
||||
$rheaders['request-id'],
|
||||
Util\Util::currentTimeMillis() - $requestStartMs
|
||||
@@ -502,6 +571,16 @@ class ApiRequestor
|
||||
self::$_httpClient = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
*
|
||||
* @param HttpClient\StreamingClientInterface $client
|
||||
*/
|
||||
public static function setStreamingHttpClient($client)
|
||||
{
|
||||
self::$_streamingHttpClient = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
*
|
||||
@@ -523,4 +602,16 @@ class ApiRequestor
|
||||
|
||||
return self::$_httpClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HttpClient\StreamingClientInterface
|
||||
*/
|
||||
private function streamingHttpClient()
|
||||
{
|
||||
if (!self::$_streamingHttpClient) {
|
||||
self::$_streamingHttpClient = HttpClient\CurlClient::instance();
|
||||
}
|
||||
|
||||
return self::$_streamingHttpClient;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user