diff --git a/lib/OpenPayU/Configuration.php b/lib/OpenPayU/Configuration.php index 92d2896..c145d63 100644 --- a/lib/OpenPayU/Configuration.php +++ b/lib/OpenPayU/Configuration.php @@ -86,7 +86,7 @@ class OpenPayU_Configuration const API_VERSION = '2.1'; const COMPOSER_JSON = "/composer.json"; - const DEFAULT_SDK_VERSION = 'PHP SDK 2.2.7'; + const DEFAULT_SDK_VERSION = 'PHP SDK 2.2.10'; const OAUTH_CONTEXT = 'pl/standard/user/oauth/authorize'; /** diff --git a/lib/OpenPayU/Http.php b/lib/OpenPayU/Http.php index 758ab2e..abc89d4 100644 --- a/lib/OpenPayU/Http.php +++ b/lib/OpenPayU/Http.php @@ -73,6 +73,7 @@ public static function doPut($pathUrl, $data, $authType) * @param $statusCode * @param null $message * @throws OpenPayU_Exception + * @throws OpenPayU_Exception_Request * @throws OpenPayU_Exception_Authorization * @throws OpenPayU_Exception_Network * @throws OpenPayU_Exception_ServerMaintenance @@ -86,7 +87,7 @@ public static function throwHttpStatusException($statusCode, $message = null) switch ($statusCode) { case 400: - throw new OpenPayU_Exception($message->getStatus().' - '.$statusDesc, $statusCode); + throw new OpenPayU_Exception_Request($message, $message->getStatus().' - '.$statusDesc, $statusCode); break; case 401: diff --git a/lib/OpenPayU/OpenPayUException.php b/lib/OpenPayU/OpenPayUException.php index a83f7c2..52401d6 100644 --- a/lib/OpenPayU/OpenPayUException.php +++ b/lib/OpenPayU/OpenPayUException.php @@ -13,6 +13,25 @@ class OpenPayU_Exception extends \Exception } +class OpenPayU_Exception_Request extends OpenPayU_Exception +{ + /** @var stdClass|null */ + private $originalResponseMessage; + + public function __construct($originalResponseMessage, $message = "", $code = 0, $previous = null) + { + $this->originalResponseMessage = $originalResponseMessage; + + parent::__construct($message, $code, $previous); + } + + /** @return null|stdClass */ + public function getOriginalResponse() + { + return $this->originalResponseMessage; + } +} + class OpenPayU_Exception_Configuration extends OpenPayU_Exception { diff --git a/lib/OpenPayU/Util.php b/lib/OpenPayU/Util.php index 34c481b..c33b745 100644 --- a/lib/OpenPayU/Util.php +++ b/lib/OpenPayU/Util.php @@ -98,14 +98,12 @@ public static function parseSignature($data) */ public static function verifySignature($message, $signature, $signatureKey, $algorithm = 'MD5') { - $hash = ''; - if (isset($signature)) { - if ($algorithm == 'MD5') { + if ($algorithm === 'MD5') { $hash = md5($message . $signatureKey); } else if (in_array($algorithm, array('SHA', 'SHA1', 'SHA-1'))) { $hash = sha1($message . $signatureKey); - } else if (in_array($algorithm, array('SHA-256', 'SHA256', 'SHA_256'))) { + } else { $hash = hash('sha256', $message . $signatureKey); } diff --git a/lib/OpenPayU/v2/Order.php b/lib/OpenPayU/v2/Order.php index c468978..ba811f7 100644 --- a/lib/OpenPayU/v2/Order.php +++ b/lib/OpenPayU/v2/Order.php @@ -3,7 +3,7 @@ /** * OpenPayU Standard Library * - * @copyright Copyright (c) 2011-2016 PayU + * @copyright Copyright (c) 2011-2018 PayU * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0) * http://www.payu.com * http://developers.payu.com @@ -15,6 +15,7 @@ class OpenPayU_Order extends OpenPayU { const ORDER_SERVICE = 'orders/'; + const ORDER_TRANSACTION_SERVICE = 'transactions'; const SUCCESS = 'SUCCESS'; /** @@ -85,6 +86,33 @@ public static function retrieve($orderId) return $result; } + /** + * Retrieves information about the order transaction + * - Sends to PayU TransactionRetrieveRequest + * + * @param string $orderId PayU OrderId sent back in OrderCreateResponse + * @return OpenPayU_Result $result Response array with TransactionRetrieveResponse + * @throws OpenPayU_Exception + */ + public static function retrieveTransaction($orderId) + { + if (empty($orderId)) { + throw new OpenPayU_Exception('Empty value of orderId'); + } + + try { + $authType = self::getAuth(); + } catch (OpenPayU_Exception $e) { + throw new OpenPayU_Exception($e->getMessage(), $e->getCode()); + } + + $pathUrl = OpenPayU_Configuration::getServiceUrl() . self::ORDER_SERVICE . $orderId . '/' . self::ORDER_TRANSACTION_SERVICE; + + $result = self::verifyResponse(OpenPayU_Http::doGet($pathUrl, $authType), 'TransactionRetrieveResponse'); + + return $result; + } + /** * Cancels Order * - Sends to PayU OrderCancelRequest @@ -143,7 +171,7 @@ public static function statusUpdate($orderStatusUpdate) * Consume notification message * * @access public - * @param $data Request array received from with PayU OrderNotifyRequest + * @param $data string Request array received from with PayU OrderNotifyRequest * @return null|OpenPayU_Result Response array with OrderNotifyRequest * @throws OpenPayU_Exception */ @@ -167,6 +195,11 @@ public static function consumeNotification($data) * @param string $response * @param string $messageName * @return null|OpenPayU_Result + * @throws OpenPayU_Exception + * @throws OpenPayU_Exception_Authorization + * @throws OpenPayU_Exception_Network + * @throws OpenPayU_Exception_ServerError + * @throws OpenPayU_Exception_ServerMaintenance */ public static function verifyResponse($response, $messageName) { @@ -189,12 +222,11 @@ public static function verifyResponse($response, $messageName) $result = self::build($data); - if ($httpStatus == 200 || $httpStatus == 201 || $httpStatus == 422 || $httpStatus == 301 || $httpStatus == 302) - { + if ($httpStatus == 200 || $httpStatus == 201 || $httpStatus == 422 || $httpStatus == 301 || $httpStatus == 302) { return $result; - } else { - OpenPayU_Http::throwHttpStatusException($httpStatus, $result); } + + OpenPayU_Http::throwHttpStatusException($httpStatus, $result); } /** @@ -204,6 +236,7 @@ public static function verifyResponse($response, $messageName) * @param array $order an array containing full Order * @param array $params an optional array with form elements' params * @return string Response html form + * @throws OpenPayU_Exception_Configuration */ public static function hostedOrderForm($order, $params = array()) {