Files
assetmgt/assets/mollie/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php
“VeLiTi” 0f968aac14 Add Mollie API integration and webhook for software upgrade payments
- Introduced the `CaBundle.php` class for managing CA certificates.
- Updated `installed.json` and `installed.php` to include the new `composer/ca-bundle` dependency.
- Added `platform_check.php` to enforce PHP version requirements.
- Created `initialize.php` for initializing the Mollie API client with the API key.
- Implemented `webhook_mollie.php` to handle webhook callbacks for software upgrade payments, including transaction status updates and invoice generation.
- Integrated DomPDF for generating invoices and sending them via email.
2025-12-21 14:44:37 +01:00

170 lines
6.5 KiB
PHP

<?php
namespace Mollie\Api\HttpAdapter;
use _PhpScoperf7c63b60b99d\Composer\CaBundle\CaBundle;
use _PhpScoperf7c63b60b99d\GuzzleHttp\Client;
use _PhpScoperf7c63b60b99d\GuzzleHttp\ClientInterface;
use _PhpScoperf7c63b60b99d\GuzzleHttp\Exception\GuzzleException;
use _PhpScoperf7c63b60b99d\GuzzleHttp\HandlerStack;
use _PhpScoperf7c63b60b99d\GuzzleHttp\Psr7\Request;
use _PhpScoperf7c63b60b99d\GuzzleHttp\RequestOptions as GuzzleRequestOptions;
use Mollie\Api\Exceptions\ApiException;
use _PhpScoperf7c63b60b99d\Psr\Http\Message\ResponseInterface;
final class Guzzle6And7MollieHttpAdapter implements \Mollie\Api\HttpAdapter\MollieHttpAdapterInterface
{
/**
* Default response timeout (in seconds).
*/
public const DEFAULT_TIMEOUT = 10;
/**
* Default connect timeout (in seconds).
*/
public const DEFAULT_CONNECT_TIMEOUT = 2;
/**
* HTTP status code for an empty ok response.
*/
public const HTTP_NO_CONTENT = 204;
/**
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
/**
* Whether debugging is enabled. If debugging mode is enabled, the request will
* be included in the ApiException. By default, debugging is disabled to prevent
* sensitive request data from leaking into exception logs.
*
* @var bool
*/
protected $debugging = \false;
public function __construct(\_PhpScoperf7c63b60b99d\GuzzleHttp\ClientInterface $httpClient)
{
$this->httpClient = $httpClient;
}
/**
* Instantiate a default adapter with sane configuration for Guzzle 6 or 7.
*
* @return static
*/
public static function createDefault()
{
$retryMiddlewareFactory = new \Mollie\Api\HttpAdapter\Guzzle6And7RetryMiddlewareFactory();
$handlerStack = \_PhpScoperf7c63b60b99d\GuzzleHttp\HandlerStack::create();
$handlerStack->push($retryMiddlewareFactory->retry());
$client = new \_PhpScoperf7c63b60b99d\GuzzleHttp\Client([\_PhpScoperf7c63b60b99d\GuzzleHttp\RequestOptions::VERIFY => \_PhpScoperf7c63b60b99d\Composer\CaBundle\CaBundle::getBundledCaBundlePath(), \_PhpScoperf7c63b60b99d\GuzzleHttp\RequestOptions::TIMEOUT => self::DEFAULT_TIMEOUT, \_PhpScoperf7c63b60b99d\GuzzleHttp\RequestOptions::CONNECT_TIMEOUT => self::DEFAULT_CONNECT_TIMEOUT, 'handler' => $handlerStack]);
return new \Mollie\Api\HttpAdapter\Guzzle6And7MollieHttpAdapter($client);
}
/**
* Send a request to the specified Mollie api url.
*
* @param string $httpMethod
* @param string $url
* @param array $headers
* @param string $httpBody
* @return \stdClass|null
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function send($httpMethod, $url, $headers, $httpBody)
{
$request = new \_PhpScoperf7c63b60b99d\GuzzleHttp\Psr7\Request($httpMethod, $url, $headers, $httpBody);
try {
$response = $this->httpClient->send($request, ['http_errors' => \false]);
} catch (\_PhpScoperf7c63b60b99d\GuzzleHttp\Exception\GuzzleException $e) {
// Prevent sensitive request data from ending up in exception logs unintended
if (!$this->debugging) {
$request = null;
}
// Not all Guzzle Exceptions implement hasResponse() / getResponse()
if (\method_exists($e, 'hasResponse') && \method_exists($e, 'getResponse')) {
if ($e->hasResponse()) {
throw \Mollie\Api\Exceptions\ApiException::createFromResponse($e->getResponse(), $request);
}
}
throw new \Mollie\Api\Exceptions\ApiException($e->getMessage(), $e->getCode(), null, $request, null);
}
return $this->parseResponseBody($response);
}
/**
* Whether this http adapter provides a debugging mode. If debugging mode is enabled, the
* request will be included in the ApiException.
*
* @return true
*/
public function supportsDebugging()
{
return \true;
}
/**
* Whether debugging is enabled. If debugging mode is enabled, the request will
* be included in the ApiException. By default, debugging is disabled to prevent
* sensitive request data from leaking into exception logs.
*
* @return bool
*/
public function debugging()
{
return $this->debugging;
}
/**
* Enable debugging. If debugging mode is enabled, the request will
* be included in the ApiException. By default, debugging is disabled to prevent
* sensitive request data from leaking into exception logs.
*/
public function enableDebugging()
{
$this->debugging = \true;
}
/**
* Disable debugging. If debugging mode is enabled, the request will
* be included in the ApiException. By default, debugging is disabled to prevent
* sensitive request data from leaking into exception logs.
*/
public function disableDebugging()
{
$this->debugging = \false;
}
/**
* Parse the PSR-7 Response body
*
* @param ResponseInterface $response
* @return \stdClass|null
* @throws ApiException
*/
private function parseResponseBody(\_PhpScoperf7c63b60b99d\Psr\Http\Message\ResponseInterface $response)
{
$body = (string) $response->getBody();
if (empty($body)) {
if ($response->getStatusCode() === self::HTTP_NO_CONTENT) {
return null;
}
throw new \Mollie\Api\Exceptions\ApiException("No response body found.");
}
$object = @\json_decode($body);
if (\json_last_error() !== \JSON_ERROR_NONE) {
throw new \Mollie\Api\Exceptions\ApiException("Unable to decode Mollie response: '{$body}'.");
}
if ($response->getStatusCode() >= 400) {
throw \Mollie\Api\Exceptions\ApiException::createFromResponse($response, null);
}
return $object;
}
/**
* The version number for the underlying http client, if available. This is used to report the UserAgent to Mollie,
* for convenient support.
* @example Guzzle/6.3
*
* @return string|null
*/
public function versionString()
{
if (\defined('\\GuzzleHttp\\ClientInterface::MAJOR_VERSION')) {
// Guzzle 7
return "Guzzle/" . \_PhpScoperf7c63b60b99d\GuzzleHttp\ClientInterface::MAJOR_VERSION;
} elseif (\defined('\\GuzzleHttp\\ClientInterface::VERSION')) {
// Before Guzzle 7
return "Guzzle/" . \_PhpScoperf7c63b60b99d\GuzzleHttp\ClientInterface::VERSION;
}
return null;
}
}