forked from PayU-EMEA/openpayu_php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
345 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
/** | ||
* OpenPayU Examples | ||
* | ||
* @copyright Copyright (c) PayU | ||
* @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0) | ||
* http://www.payu.com | ||
* http://developers.payu.com | ||
*/ | ||
|
||
require_once realpath(dirname(__FILE__)) . '/../../../lib/openpayu.php'; | ||
require_once realpath(dirname(__FILE__)) . '/../../config.php'; | ||
|
||
if (isset($_POST['publicShopId'])) { | ||
$publicShopId = trim($_POST['publicShopId']); | ||
} | ||
?> | ||
<!doctype html> | ||
<html lang="en-US"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Retrieving shop data</title> | ||
<link rel="stylesheet" href="../../layout/css/bootstrap.min.css"> | ||
<link rel="stylesheet" href="../../layout/css/style.css"> | ||
<script type="text/javascript" src="../../layout/js/jquery.min.js"></script> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<div class="page-header"> | ||
<h1>Retrieving shop data</h1> | ||
</div> | ||
|
||
<?php | ||
if (!empty($publicShopId)) { | ||
try { | ||
$shop = OpenPayU_Shop::get($publicShopId); | ||
echo '<pre>'.$shop.'</pre>'; | ||
} catch (OpenPayU_Exception $e) { | ||
echo '<pre>'; | ||
echo 'Error code: ' . $e->getCode(); | ||
echo '<br>'; | ||
echo 'Error message: ' . $e->getMessage(); | ||
echo '<br>'; | ||
echo '</pre>'; | ||
} | ||
} else { | ||
?> | ||
<form action="" method="post" class="form-horizontal"> | ||
<div class="control-group"> | ||
<label class="control-label" for="publicShopId">Public Shop Id</label> | ||
<div class="controls"> | ||
<input class="span5" name="publicShopId" id="publicShopId" type="text" value=""/> | ||
</div> | ||
</div> | ||
|
||
<div class="control-group"> | ||
<label class="control-label" for="pay-button"></label> | ||
|
||
<div id="msg"></div> | ||
<div class="controls"> | ||
<button class="btn btn-success" id="pay-button" type="submit">Get shop</button> | ||
</div> | ||
</div> | ||
</form> | ||
<?php | ||
} | ||
?> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
class Shop | ||
{ | ||
/** @var string */ | ||
private $shopId; | ||
|
||
/** @var string */ | ||
private $name; | ||
|
||
/** @var string */ | ||
private $currencyCode; | ||
|
||
/** @var Balance */ | ||
private $balance; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getShopId() | ||
{ | ||
return $this->shopId; | ||
} | ||
|
||
/** | ||
* @param string $shopId | ||
* @return Shop | ||
*/ | ||
public function setShopId($shopId) | ||
{ | ||
$this->shopId = $shopId; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @return Shop | ||
*/ | ||
public function setName($name) | ||
{ | ||
$this->name = $name; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCurrencyCode() | ||
{ | ||
return $this->currencyCode; | ||
} | ||
|
||
/** | ||
* @param string $currencyCode | ||
* @return Shop | ||
*/ | ||
public function setCurrencyCode($currencyCode) | ||
{ | ||
$this->currencyCode = $currencyCode; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return Balance | ||
*/ | ||
public function getBalance() | ||
{ | ||
return $this->balance; | ||
} | ||
|
||
/** | ||
* @param Balance $balance | ||
* @return Shop | ||
*/ | ||
public function setBalance($balance) | ||
{ | ||
$this->balance = $balance; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return 'Shop [currencyCode=' . $this->shopId . | ||
', name=' . $this->name . | ||
', currencyCode=' . $this->currencyCode . | ||
', balance=' . $this->balance . | ||
']'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
class Balance | ||
{ | ||
/** @var string */ | ||
private $currencyCode; | ||
|
||
/** @var int */ | ||
private $total; | ||
|
||
/** @var int */ | ||
private $available; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCurrencyCode() | ||
{ | ||
return $this->currencyCode; | ||
} | ||
|
||
/** | ||
* @param string $currencyCode | ||
* @return Balance | ||
*/ | ||
public function setCurrencyCode($currencyCode) | ||
{ | ||
$this->currencyCode = $currencyCode; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getTotal() | ||
{ | ||
return $this->total; | ||
} | ||
|
||
/** | ||
* @param int $total | ||
* @return Balance | ||
*/ | ||
public function setTotal($total) | ||
{ | ||
$this->total = $total; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getAvailable() | ||
{ | ||
return $this->available; | ||
} | ||
|
||
/** | ||
* @param int $available | ||
* @return Balance | ||
*/ | ||
public function setAvailable($available) | ||
{ | ||
$this->available = $available; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return 'Balance [currencyCode=' . $this->currencyCode . | ||
', total=' . $this->total . | ||
', available=' . $this->available . | ||
']'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
/** | ||
* OpenPayU Standard Library | ||
* | ||
* @copyright Copyright (c) PayU | ||
* @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0) | ||
* http://www.payu.com | ||
* http://developers.payu.com | ||
*/ | ||
|
||
class OpenPayU_Shop extends OpenPayU | ||
{ | ||
const SHOPS_SERVICE = 'shops'; | ||
|
||
/** | ||
* Retrieving shop data | ||
* @param string $publicShopId | ||
* @return Shop | ||
* @throws OpenPayU_Exception | ||
* @throws OpenPayU_Exception_Configuration | ||
*/ | ||
public static function get($publicShopId) | ||
{ | ||
try { | ||
$authType = self::getAuth(); | ||
} catch (OpenPayU_Exception $e) { | ||
throw new OpenPayU_Exception($e->getMessage(), $e->getCode()); | ||
} | ||
|
||
if (!$authType instanceof AuthType_Oauth) { | ||
throw new OpenPayU_Exception_Configuration('Get shop works only with OAuth'); | ||
} | ||
|
||
$pathUrl = OpenPayU_Configuration::getServiceUrl() . self::SHOPS_SERVICE . '/' . $publicShopId; | ||
|
||
return self::verifyResponse(OpenPayU_Http::doGet($pathUrl, $authType)); | ||
} | ||
|
||
/** | ||
* @param array $response | ||
* @return Shop | ||
* @throws OpenPayU_Exception | ||
*/ | ||
public static function verifyResponse($response) | ||
{ | ||
$httpStatus = $response['code']; | ||
|
||
if ($httpStatus == 500) { | ||
$result = (new ResultError()) | ||
->setErrorDescription($response['response']); | ||
OpenPayU_Http::throwErrorHttpStatusException($httpStatus, $result); | ||
} | ||
|
||
$message = json_decode($response['response'], true); | ||
|
||
if (json_last_error() === JSON_ERROR_SYNTAX) { | ||
throw new OpenPayU_Exception_ServerError('Incorrect json response. Response: [' . $response['response'] . ']'); | ||
} | ||
|
||
if ($httpStatus == 200) { | ||
return (new Shop()) | ||
->setShopId($message['shopId']) | ||
->setName($message['name']) | ||
->setCurrencyCode($message['currencyCode']) | ||
->setBalance( | ||
(new Balance()) | ||
->setCurrencyCode($message['balance']['currencyCode']) | ||
->setTotal($message['balance']['total']) | ||
->setAvailable($message['balance']['available']) | ||
); | ||
} | ||
|
||
$result = (new ResultError()) | ||
->setError($message['error']) | ||
->setErrorDescription($message['error_description']); | ||
|
||
OpenPayU_Http::throwErrorHttpStatusException($httpStatus, $result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters