Skip to content

Commit

Permalink
Update SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
regdos committed Aug 3, 2018
1 parent 7849d80 commit 5e66bb3
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/OpenPayU/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/OpenPayU/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions lib/OpenPayU/OpenPayUException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

Expand Down
6 changes: 2 additions & 4 deletions lib/OpenPayU/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
45 changes: 39 additions & 6 deletions lib/OpenPayU/v2/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,6 +15,7 @@
class OpenPayU_Order extends OpenPayU
{
const ORDER_SERVICE = 'orders/';
const ORDER_TRANSACTION_SERVICE = 'transactions';
const SUCCESS = 'SUCCESS';

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand All @@ -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)
{
Expand All @@ -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);
}

/**
Expand All @@ -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())
{
Expand Down

0 comments on commit 5e66bb3

Please sign in to comment.