diff --git a/.gitignore b/.gitignore index a0787251a..3dd761b9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # ignore config file -/tests/config/* +tests/config # Ignore the /vendor/ directory /vendor/ @@ -11,4 +11,4 @@ composer.lock .DS_Store # ignore PhpStorm .idea folder -.idea \ No newline at end of file +.idea diff --git a/src/Adyen/AdyenException.php b/src/Adyen/AdyenException.php index 35ddaa58c..6726ccc72 100644 --- a/src/Adyen/AdyenException.php +++ b/src/Adyen/AdyenException.php @@ -16,19 +16,32 @@ class AdyenException extends Exception */ protected $errorType; - /** - * AdyenException constructor. - * - * @param string $message - * @param int $code - * @param Exception|null $previous - * @param null $status - * @param null $errorType - */ - public function __construct($message = "", $code = 0, Exception $previous = null, $status = null, $errorType = null) - { + /** + * @var string + */ + protected $pspReference; + + /** + * AdyenException constructor. + * + * @param string $message + * @param int $code + * @param Exception|null $previous + * @param null $status + * @param null $errorType + * @param null $pspReference + */ + public function __construct( + $message = "", + $code = 0, + Exception $previous = null, + $status = null, + $errorType = null, + $pspReference = null + ) { $this->status = $status; $this->errorType = $errorType; + $this->pspReference = $pspReference; parent::__construct($message, (int)$code, $previous); } @@ -49,4 +62,12 @@ public function getErrorType() { return $this->errorType; } + + /** + * @return string + */ + public function getPspReference() + { + return $this->pspReference; + } } diff --git a/src/Adyen/HttpClient/CurlClient.php b/src/Adyen/HttpClient/CurlClient.php index 2cb226f2b..a3d9fd7aa 100644 --- a/src/Adyen/HttpClient/CurlClient.php +++ b/src/Adyen/HttpClient/CurlClient.php @@ -2,6 +2,8 @@ namespace Adyen\HttpClient; +use Adyen\AdyenException; + class CurlClient implements ClientInterface { /** @@ -11,7 +13,7 @@ class CurlClient implements ClientInterface * @param $requestUrl * @param $params * @return mixed - * @throws \Adyen\AdyenException + * @throws AdyenException */ public function requestJson(\Adyen\Service $service, $requestUrl, $params) { @@ -51,7 +53,7 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params) $headers[] = 'x-api-key: ' . $xApiKey; } elseif ($service->requiresApiKey()) { $msg = "Please provide a valid Checkout API Key"; - throw new \Adyen\AdyenException($msg); + throw new AdyenException($msg); } else { //Set the basic auth credentials @@ -108,7 +110,7 @@ public function requestJson(\Adyen\Service $service, $requestUrl, $params) * @param $requestUrl * @param $params * @return mixed - * @throws \Adyen\AdyenException + * @throws AdyenException */ public function requestPost(\Adyen\Service $service, $requestUrl, $params) { @@ -173,7 +175,7 @@ public function requestPost(\Adyen\Service $service, $requestUrl, $params) if (!$result) { $msg = "The result is empty, looks like your request is invalid"; $logger->error($msg); - throw new \Adyen\AdyenException($msg); + throw new AdyenException($msg); } // log the array result @@ -224,18 +226,24 @@ protected function handleCurlError($url, $errno, $message, $logger) * * @param $result * @param $logger - * @throws \Adyen\AdyenException + * @throws AdyenException */ protected function handleResultError($result, $logger) { $decodeResult = json_decode($result, true); if (isset($decodeResult['message']) && isset($decodeResult['errorCode'])) { $logger->error($decodeResult['errorCode'] . ': ' . $decodeResult['message']); - throw new \Adyen\AdyenException($decodeResult['message'], $decodeResult['errorCode'], null, - $decodeResult['status'], $decodeResult['errorType']); + throw new AdyenException( + $decodeResult['message'], + $decodeResult['errorCode'], + null, + $decodeResult['status'], + $decodeResult['errorType'], + isset($decodeResult['pspReference']) ? $decodeResult['pspReference'] : null + ); } $logger->error($result); - throw new \Adyen\AdyenException($result); + throw new AdyenException($result); } /**