Skip to content

Commit

Permalink
Merge pull request #11 from OXID-eSales/PSPAYPAL_AddDebugLog
Browse files Browse the repository at this point in the history
add Debug-Logging for send-Requests
  • Loading branch information
mariolorenz authored Feb 22, 2024
2 parents 25f51b2 + ce6e92c commit da2d8a1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.0.10] -2024-01-26

- add Vaulting to API-Calls
- add Debug-Logging for send-Requests

## [2.0.9] -2023-11-17

- add PartnerAttributionId to API-Calls
Expand All @@ -15,7 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [2.0.7] - 2023-01-02

- split Version to be compatible PHP >= 7.1
- cache the token
- cache the token

## [1.0.6] - 2022-06-01

Expand Down
23 changes: 21 additions & 2 deletions src/Service/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
namespace OxidSolutionCatalysts\PayPalApi\Service;

use GuzzleHttp\Exception\GuzzleException;
use OxidSolutionCatalysts\PayPal\Service\Logger;
use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer;
use OxidSolutionCatalysts\PayPalApi\Client;
use OxidSolutionCatalysts\PayPalApi\Exception\ApiException;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Psr7\Query;

class BaseService
{
use ServiceContainer;

/** @var Client */
public $client;

Expand All @@ -32,18 +36,33 @@ public function __construct(Client $client)
*/
protected function send($method, $path, $params = [], $headers = [], $body = null): ResponseInterface
{
/** @var Logger $logger */
$logger = $this->getServiceFromContainer(Logger::class);

$params = array_filter($params);
if ($params) {
$q = Query::build($params);
$path = "$path?$q";
}
$fullPath = $this->basePath . $path;
$request = $this->client->createRequest($method, $fullPath, $headers, $body);

$logger->log('debug', 'PayPal SEND path ' . $path);
$logger->log('debug', 'PayPal SEND request ' . $request->getBody());
$logger->log('debug', 'PayPal SEND headers ' . serialize($request->getHeaders()));

try {
$response = $this->client->send($request);
} catch (GuzzleException $e) {
throw new ApiException($e);
} catch (GuzzleException $exception) {
$logger->log('error', $exception->getMessage(), [$exception]);
$this->sendErrorResponse();
}
return $response;
}

private function sendErrorResponse(): void
{
header('Content-Type: text/html', true, 500);
exit;
}
}

0 comments on commit da2d8a1

Please sign in to comment.