Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #68 from PayU/retrieve
Browse files Browse the repository at this point in the history
Retrieve paymethods
  • Loading branch information
regdos authored May 7, 2018
2 parents 3ef9819 + 11ec891 commit 91eb062
Show file tree
Hide file tree
Showing 27 changed files with 752 additions and 185 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
1. [Instalacja](#instalacja)
1. [Konfiguracja](#konfiguracja)
* [Parametry](#parametry)
1. [Informacje o cechach](#informacje-o-cechach)
* [Kolejność metod płatności](#kolejność-metod-płatności)

## Cechy
Moduł płatności PayU dodaje do Magento opcję płatności PayU.
Expand All @@ -26,7 +28,7 @@ Możliwe są następujące operacje:
Moduł dodaje dwie metody płatności:

![methods][img0]
* **Zapłać przez PayU** - przekierowanie na stronę wyboru metod płatności w PayU
* **Zapłać przez PayU** - wybór metody płatności i przekierowanie do banku / formatkę kartową lub przekierowanie na stronę wyboru metod płatności w PayU
* **Zapłać kartą** - bezpośrednie przekierowanie na formularz płatności kartą

## Wymagania
Expand Down Expand Up @@ -84,6 +86,13 @@ Dodatkowo jeżeli aktualizujesz moduł ze starszej wersji należy z katalogu `in
| Czy włączyć wtyczkę? | Określa czy metoda płatności będzie dostępna w sklepie na liście płatności. |
| Tryb testowy (Sandbox) | Określa czy płatności będą realizowane na środowisku testowym (sandbox) PayU. |

#### Parametry dla metody `Zapłać przez PayU`

| Parameter | Opis |
|---------|-----------|
| Wyświetlaj metody płatności | Określa czy ma być wyświetlana lista bramek płatności podczas procesu zamówienia w Magento |
| Kolejność metod płatności | Określa kolejnośc wyświetlanych metod płatności [więcej informacji](#kolejność-metod-płatności). |

#### Parametry punktu płatności (POS)

| Parameter | Opis |
Expand All @@ -103,6 +112,10 @@ Dostępne gdy parametr `Tryb testowy (Sandbox)` jest ustawiony na `Tak`.
| OAuth - client_id | client_id dla protokołu OAuth z systemu PayU |
| OAuth - client_secret | client_secret for OAuth z systemu PayU |

## Informacje o cechach

### Kolejność metod płatności
W celu ustalenia kolejności wyświetlanych ikon matod płatności należy podać symbole metod płatności oddzielając je przecinkiem. [Lista metod płatności][ext7].

<!--LINKS-->

Expand All @@ -113,9 +126,10 @@ Dostępne gdy parametr `Tryb testowy (Sandbox)` jest ustawiony na `Tak`.
[ext1]: http://php.net/manual/en/book.curl.php
[ext2]: http://php.net/manual/en/book.hash.php
[ext3]: https://github.com/PayU/plugin_magento_160
[ext4]: https://secure.payu.com/boarding/#/form&pk_campaign=Plugin-Github&pk_kwd=Magento
[ext5]: https://secure.snd.payu.com/boarding/#/form&pk_campaign=Plugin-Github&pk_kwd=Magento
[ext4]: https://secure.payu.com/boarding/?pk_campaign=Plugin-Github&pk_kwd=Magento#/form
[ext5]: https://secure.snd.payu.com/boarding/?pk_campaign=Plugin-Github&pk_kwd=Magento#/form
[ext6]: https://github.com/PayU/plugin_magento_2
[ext7]: http://developers.payu.com/pl/overview.html#paymethods

<!--images:-->
[img0]: readme_images/methods.png
5 changes: 3 additions & 2 deletions app/code/community/PayU/Account/Block/Form/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

abstract class PayU_Account_Block_Form_Abstract extends Mage_Payment_Block_Form {


protected function _construct()
{
parent::_construct();
Expand All @@ -17,7 +16,9 @@ protected function _construct()
protected function _prepareLayout()
{
if ($head = $this->getLayout()->getBlock('head')) {
$head->addCss('css/payu/payu.css');
$head
->addCss('css/payu/payu.css')
->addItem('skin_js', 'js/payu/payu.js');
}
return parent::_prepareLayout();
}
Expand Down
30 changes: 29 additions & 1 deletion app/code/community/PayU/Account/Block/Form/PayuAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,38 @@ class PayU_Account_Block_Form_PayuAccount extends PayU_Account_Block_Form_Abstra

protected function _construct()
{
parent::_construct();

$this->setMethodTitle($this->__('Pay with PayU'));
$this->setMethodLabelAfterHtml('<img src="' . $this->getPayuLogo() . '" alt="PayU" class="formPayuLogo" />');
$this->setTemplate('payu_account/form.phtml');
return parent::_construct();

}

/**
* @return array|null
*/
public function getPayMethods()
{
/** @var PayU_Account_Model_Config $payuConfig */
$payuConfig = Mage::getSingleton('payu/config', array('method' => PayU_Account_Model_Method_PayuAccount::CODE));

if (!$payuConfig->isShowPaytypes()) {
return null;
}

/** @var PayU_Account_Model_GetPayMethods $getPayMetods */
$getPayMetods = Mage::getModel('payu/getPayMethods', array('method' => PayU_Account_Model_Method_PayuCard::CODE));

return $getPayMetods->execute();
}

/**
* @return bool
*/
public function isShowPayuConditions()
{
return substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2) === 'pl';
}

}
5 changes: 3 additions & 2 deletions app/code/community/PayU/Account/Block/Form/PayuCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ class PayU_Account_Block_Form_PayuCard extends PayU_Account_Block_Form_Abstract

protected function _construct()
{
parent::_construct();

$this->setMethodTitle($this->__('Pay by card'));
$this->setMethodLabelAfterHtml('<img src="' . $this->getCardLogos() . '" alt="PayU" class="formPayuLogo" />');

return parent::_construct();
$this->setTemplate('payu_account/card_form.phtml');
}

}
2 changes: 1 addition & 1 deletion app/code/community/PayU/Account/Block/UpdateInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PayU_Account_Block_UpdateInfo extends Mage_Adminhtml_Block_System_Config_F
*/
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
$html = '<b>' . Mage::getModel('payu/config')->getPluginVersion() . ' ' . Mage::helper('payu')->__('for') . ' magento ' . Mage::getModel('payu/config')->getMinimumMageVersion() . '+</b>';
$html = '<b>' . Mage::getModel('payu/config')->getPluginVersion() . '</b>';

return $html;
}
Expand Down
130 changes: 73 additions & 57 deletions app/code/community/PayU/Account/Model/Config.php
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);
}

}
48 changes: 48 additions & 0 deletions app/code/community/PayU/Account/Model/CreateOrder.php
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.'));

}
}
}
Loading

0 comments on commit 91eb062

Please sign in to comment.