This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from PayU/retrieve
Retrieve paymethods
- Loading branch information
Showing
27 changed files
with
752 additions
and
185 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
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
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 |
---|---|---|
@@ -1,129 +1,145 @@ | ||
<?php | ||
|
||
/** | ||
* PayU Config Model | ||
* | ||
* @copyright Copyright (c) 2011-2016 PayU | ||
* @license http://opensource.org/licenses/GPL-3.0 Open Software License (GPL 3.0) | ||
*/ | ||
class PayU_Account_Model_Config | ||
{ | ||
/** | ||
* @var string self version | ||
* Sanbox code | ||
*/ | ||
protected $_pluginVersion = '2.3.1'; | ||
const ENVIRONMENT_SANBOX = 'sandbox'; | ||
|
||
/** | ||
* @var string minimum Magento e-commerce version | ||
* Secure code | ||
*/ | ||
protected $_minimumMageVersion = '1.6.0'; | ||
const ENVIRONMENT_SECURE = 'secure'; | ||
|
||
/** | ||
* Plugin version | ||
*/ | ||
const PLUGIN_VERSION = '2.4.0'; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $_storeId; | ||
private $storeId; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $_method; | ||
private $method; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param $params | ||
* @param array $params | ||
* @param int|null $storeId | ||
* @throws Mage_Core_Model_Store_Exception | ||
*/ | ||
public function __construct($params = array()) | ||
public function __construct($params = array(), $storeId = null) | ||
{ | ||
// assign current store id | ||
$this->setStoreId(Mage::app()->getStore()->getId()); | ||
if ($storeId !== null) { | ||
$this->storeId = $storeId; | ||
} else { | ||
$this->storeId = Mage::app()->getStore()->getId(); | ||
} | ||
|
||
$this->_method = $params['method']; | ||
$this->method = $params['method']; | ||
} | ||
|
||
/** | ||
* @param int $storeId | ||
* @return $this | ||
* @param string $action | ||
* @param array $params | ||
* | ||
* @return string base module url | ||
*/ | ||
public function setStoreId($storeId) | ||
{ | ||
$this->_storeId = $storeId; | ||
return $this; | ||
} | ||
|
||
/** @return string get Merchant POS Id */ | ||
public function getMerchantPosId() | ||
public function getUrl($action, $params = array()) | ||
{ | ||
return $this->getStoreConfig('pos_id'); | ||
$params['_secure'] = true; | ||
return Mage::getUrl('payu/payment/' . $action, $params); | ||
} | ||
|
||
/** | ||
* @return string get Signature Key | ||
* @return string | ||
*/ | ||
public function getSignatureKey() | ||
public function getPluginVersion() | ||
{ | ||
return $this->getStoreConfig('signature_key'); | ||
return self::PLUGIN_VERSION; | ||
} | ||
|
||
/** | ||
* @return string get OAuth Client Id | ||
* Initialize PayU configuration | ||
*/ | ||
public function getClientId() | ||
public function initializeOpenPayUConfiguration() | ||
{ | ||
return $this->getStoreConfig('oauth_client_id'); | ||
OpenPayU_Configuration::setEnvironment($this->getEnvironment()); | ||
OpenPayU_Configuration::setMerchantPosId($this->getStoreConfig('pos_id')); | ||
OpenPayU_Configuration::setSignatureKey($this->getStoreConfig('signature_key')); | ||
OpenPayU_Configuration::setOauthClientId($this->getStoreConfig('oauth_client_id')); | ||
OpenPayU_Configuration::setOauthClientSecret($this->getStoreConfig('oauth_client_secret')); | ||
OpenPayU_Configuration::setOauthTokenCache(new OauthCacheFile(Mage::getBaseDir('cache'))); | ||
OpenPayU_Configuration::setSender('Magento ver ' . Mage::getVersion() . '/Plugin ver ' . $this->getPluginVersion()); | ||
} | ||
|
||
/** | ||
* @return string get OAuth Client Secret | ||
* @return string | ||
*/ | ||
public function getClientSecret() | ||
public function getMerchantPosId() | ||
{ | ||
return $this->getStoreConfig('oauth_client_secret'); | ||
return \OpenPayU_Configuration::getMerchantPosId(); | ||
} | ||
|
||
/** | ||
* @return string get Sandbox | ||
* @return bool | ||
*/ | ||
public function isSandbox() | ||
public function isShowPaytypes() | ||
{ | ||
return (bool)Mage::getStoreConfig('payment/' . $this->_method . '/sandbox', $this->_storeId); | ||
return (bool)Mage::getStoreConfig('payment/' . $this->method . '/paytypes', $this->storeId); | ||
} | ||
|
||
/** | ||
* @param string $action | ||
* @param array $params | ||
* | ||
* @return string base module url | ||
* @return bool | ||
*/ | ||
public function getUrl($action, $params = array()) | ||
public function isActive() | ||
{ | ||
$params['_secure'] = true; | ||
return Mage::getUrl('payu/payment/' . $action, $params); | ||
return (bool)Mage::getStoreConfig('payment/' . $this->method . '/active', $this->storeId); | ||
} | ||
|
||
/** | ||
* @return string get current plugin version | ||
* @return array | ||
*/ | ||
public function getPluginVersion() | ||
{ | ||
return $this->_pluginVersion; | ||
public function getPaytypesOrder() { | ||
return explode( | ||
',', | ||
str_replace( | ||
' ', | ||
'', | ||
Mage::getStoreConfig('payment/' . $this->method . '/paytypes_order', $this->storeId) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @return string get minimum mage version for the plugin to work on | ||
* @return string | ||
*/ | ||
public function getMinimumMageVersion() | ||
{ | ||
return $this->_minimumMageVersion; | ||
private function getEnvironment() { | ||
return $this->isSandbox() ? self::ENVIRONMENT_SANBOX : self::ENVIRONMENT_SECURE; | ||
} | ||
|
||
/** | ||
* get Store Config variable | ||
* @param $name | ||
* @return string | ||
*/ | ||
protected function getStoreConfig($name) | ||
private function getStoreConfig($name) | ||
{ | ||
return Mage::getStoreConfig('payment/' . $this->_method . '/' . ($this->isSandbox() ? 'sandbox_' : '') . $name, $this->_storeId); | ||
return Mage::getStoreConfig('payment/' . $this->method . '/' . ($this->isSandbox() ? 'sandbox_' : '') . $name, $this->storeId); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
private function isSandbox() | ||
{ | ||
return (bool)Mage::getStoreConfig('payment/' . $this->method . '/sandbox', $this->storeId); | ||
} | ||
|
||
} |
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,48 @@ | ||
<?php | ||
|
||
class PayU_Account_Model_CreateOrder | ||
{ | ||
/** @var PayU_Account_Model_Config */ | ||
private $payuConfig; | ||
|
||
/** | ||
* PayU_Account_Model_CreateOrder constructor. | ||
* @param string $method | ||
*/ | ||
public function __construct($method) | ||
{ | ||
$this->payuConfig = Mage::getSingleton('payu/config', array('method' => $method)); | ||
} | ||
|
||
/** | ||
* @param array $orderData | ||
* @return object | ||
* @throws Mage_Core_Exception | ||
*/ | ||
public function execute($orderData) | ||
{ | ||
$this->payuConfig->initializeOpenPayUConfiguration(); | ||
|
||
$orderData['merchantPosId'] = $this->payuConfig->getMerchantPosId(); | ||
|
||
try { | ||
/** @var \OpenPayU_Result $result */ | ||
$result = \OpenPayU_Order::create($orderData); | ||
|
||
if ($result->getStatus() == \OpenPayU_Order::SUCCESS) { | ||
return $result->getResponse(); | ||
} else { | ||
Mage::log($result); | ||
|
||
Mage::throwException(Mage::helper('payu') | ||
->__('There was a problem with the payment initialization, please contact system administrator.')); | ||
} | ||
} catch (\OpenPayU_Exception $e) { | ||
Mage::log($e->getMessage()); | ||
|
||
Mage::throwException(Mage::helper('payu') | ||
->__('There was a problem with the payment initialization, please contact system administrator.')); | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.