PayU_Account - Version 0.1.6.1

Version Notes

Changed extension name: PayU_Account was PayU_PayU

Download this release

Release Info

Developer PayU
Extension PayU_Account
Version 0.1.6.1
Comparing to
See all releases


Version 0.1.6.1

Files changed (43) hide show
  1. app/code/local/PayU/Account/Block/Adminhtml/Sales/Order/View.php +53 -0
  2. app/code/local/PayU/Account/Block/Advertisement.php +42 -0
  3. app/code/local/PayU/Account/Block/BeforeSummary.php +53 -0
  4. app/code/local/PayU/Account/Block/Button.php +17 -0
  5. app/code/local/PayU/Account/Block/Form.php +45 -0
  6. app/code/local/PayU/Account/Block/Onestep/Checkout.php +53 -0
  7. app/code/local/PayU/Account/Block/Redirect.php +74 -0
  8. app/code/local/PayU/Account/Block/UpdateInfo.php +79 -0
  9. app/code/local/PayU/Account/Helper/Data.php +74 -0
  10. app/code/local/PayU/Account/Model/Adminhtml/Sales/Order.php +17 -0
  11. app/code/local/PayU/Account/Model/Advertisement.php +32 -0
  12. app/code/local/PayU/Account/Model/Button.php +33 -0
  13. app/code/local/PayU/Account/Model/Config.php +285 -0
  14. app/code/local/PayU/Account/Model/Environment.php +37 -0
  15. app/code/local/PayU/Account/Model/PayU.php +90 -0
  16. app/code/local/PayU/Account/Model/Payment.php +1132 -0
  17. app/code/local/PayU/Account/Model/Session.php +20 -0
  18. app/code/local/PayU/Account/Model/Thumbnail.php +31 -0
  19. app/code/local/PayU/Account/Model/ValidityTime.php +43 -0
  20. app/code/local/PayU/Account/controllers/Adminhtml/Sales/OrderController.php +77 -0
  21. app/code/local/PayU/Account/controllers/Checkout/CartController.php +23 -0
  22. app/code/local/PayU/Account/controllers/PaymentController.php +194 -0
  23. app/code/local/PayU/Account/etc/config.xml +124 -0
  24. app/code/local/PayU/Account/etc/system.xml +236 -0
  25. app/design/frontend/base/default/layout/payu_account.xml +106 -0
  26. app/design/frontend/base/default/template/payu_account/advertisement.phtml +4 -0
  27. app/design/frontend/base/default/template/payu_account/form.phtml +3 -0
  28. app/design/frontend/base/default/template/payu_account/info/payu_account.phtml +36 -0
  29. app/design/frontend/base/default/template/payu_account/onestep/checkout.phtml +5 -0
  30. app/etc/modules/PayU_Account.xml +12 -0
  31. app/locale/pl_PL/PayU_Account.csv +57 -0
  32. lib/payu/sdk/OpenPayU/Configuration.php +184 -0
  33. lib/payu/sdk/OpenPayU/OAuth.php +98 -0
  34. lib/payu/sdk/OpenPayU/OpenPayU.php +198 -0
  35. lib/payu/sdk/OpenPayU/OpenPayUBase.php +251 -0
  36. lib/payu/sdk/OpenPayU/OpenPayUNetwork.php +167 -0
  37. lib/payu/sdk/OpenPayU/OpenPayUOAuth.php +113 -0
  38. lib/payu/sdk/OpenPayU/Order.php +334 -0
  39. lib/payu/sdk/OpenPayU/Result.php +187 -0
  40. lib/payu/sdk/OpenPayU/ResultOAuth.php +187 -0
  41. lib/payu/sdk/openpayu.php +32 -0
  42. lib/payu/sdk/openpayu_domain.php +67 -0
  43. package.xml +18 -0
app/code/local/PayU/Account/Block/Adminhtml/Sales/Order/View.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Adminhtml Sales Order View
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+ class PayU_Account_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View {
15
+
16
+ // constructor
17
+ public function __construct() {
18
+
19
+ parent::__construct();
20
+
21
+ if($this->getOrder()->getPayment()->getMethod() == 'payu_account'){
22
+ $this->_addButton('payu-complete', array(
23
+ 'label' => Mage::helper('payu_account')->__('Accept PayU order'),
24
+ 'onclick' => 'setLocation(\'' . $this->getCompletePaymentUrl() . '\')',
25
+ 'class' => ''
26
+ ), 0, 100, 'header', 'header');
27
+
28
+ $this->_addButton('payu-reject', array(
29
+ 'label' => Mage::helper('payu_account')->__('Reject PayU order'),
30
+ 'onclick' => 'setLocation(\'' . $this->getRejectPaymentUrl() . '\')',
31
+ 'class' => ''
32
+ ), 0, 200, 'header', 'header');
33
+ }
34
+ }
35
+
36
+ // rejecting the PayU payment
37
+ public function getRejectPaymentUrl()
38
+ {
39
+ return $this->getUrl('*/sales_order/rejectPayUOrder');
40
+ }
41
+
42
+ // canceling the PayU payment
43
+ public function getCancelPaymentUrl()
44
+ {
45
+ return $this->getUrl('*/sales_order/cancelPayUOrder');
46
+ }
47
+
48
+ // completing the PayU payment
49
+ public function getCompletePaymentUrl()
50
+ {
51
+ return $this->getUrl('*/sales_order/completePayUOrder');
52
+ }
53
+ }
app/code/local/PayU/Account/Block/Advertisement.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Advertisement Block
6
+ * Payment
7
+ *
8
+ * @copyright Copyright (c) 2011-2012 PayU
9
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
10
+ * http://www.payu.com
11
+ * http://www.openpayu.com
12
+ * http://twitter.com/openpayu
13
+ */
14
+
15
+ class PayU_Account_Block_Advertisement extends Mage_Core_Block_Template
16
+ {
17
+ /**
18
+ * Redirection after clicking the advertisement
19
+ *
20
+ * @var string
21
+ */
22
+ protected $_redirectUrl = 'http://www.payu.pl';
23
+
24
+ /**
25
+ * (non-PHPdoc)
26
+ * @see magento/app/code/core/Mage/Core/Block/Mage_Core_Block_Template::_toHtml()
27
+ */
28
+ protected function _toHtml()
29
+ {
30
+ /**
31
+ * setting the advertisement source url
32
+ */
33
+ $this->setAdvertisementSrc(Mage::getModel('payu_account/config')->getAdvertisementSrc());
34
+
35
+ /**
36
+ * setting the redirect url
37
+ */
38
+ $this->setRedirectUrl($this->_redirectUrl);
39
+
40
+ return parent::_toHtml();
41
+ }
42
+ }
app/code/local/PayU/Account/Block/BeforeSummary.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU BeforeSummary Redirection Block
6
+ * Payment
7
+ *
8
+ * @copyright Copyright (c) 2011-2012 PayU
9
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
10
+ * http://www.payu.com
11
+ * http://www.openpayu.com
12
+ * http://twitter.com/openpayu
13
+ */
14
+
15
+ class PayU_Account_Block_BeforeSummary extends Mage_Core_Block_Abstract
16
+ {
17
+ protected $_order = null;
18
+
19
+ /**
20
+ * (non-PHPdoc)
21
+ * @see magento/app/code/core/Mage/Core/Block/Mage_Core_Block_Abstract::_toHtml()
22
+ */
23
+ protected function _toHtml()
24
+ {
25
+ $payment = Mage::getModel('payu_account/payment');
26
+
27
+ $form = new Varien_Data_Form();
28
+
29
+ $redirectData = $payment->beforeSummary();
30
+
31
+ $form->setAction($redirectData['url'])
32
+ ->setId('payu_checkout')
33
+ ->setName('payu_checkout')
34
+ ->setMethod('GET')
35
+ ->setUseContainer(true);
36
+
37
+ $form->addField('sessionId', 'hidden', array('name' => 'sessionId', 'value' => $redirectData['sessionId']));
38
+ $form->addField('oauth_token', 'hidden', array('name' => 'oauth_token', 'value' => $redirectData['oauth_token']));
39
+ $form->addField('client_id', 'hidden', array('name' => 'client_id', 'value' => $redirectData['client_id']));
40
+
41
+ $html = '<html><body>';
42
+ $html.= $form->toHtml();
43
+ $html.= '<script type="text/javascript">document.getElementById("payu_checkout").submit();</script>';
44
+ $html.= '</body></html>';
45
+
46
+ return $html;
47
+ }
48
+
49
+ public function setOrder($order) {
50
+ $this->_order = $order;
51
+ return $this;
52
+ }
53
+ }
app/code/local/PayU/Account/Block/Button.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Button Block
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+ class PayU_Account_Block_Button extends Mage_Core_Block_Template
15
+ {
16
+
17
+ }
app/code/local/PayU/Account/Block/Form.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Form Block
6
+ * Payment
7
+ *
8
+ * @copyright Copyright (c) 2011-2012 PayU
9
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
10
+ * http://www.payu.com
11
+ * http://www.openpayu.com
12
+ * http://twitter.com/openpayu
13
+ */
14
+
15
+
16
+ class PayU_Account_Block_Form extends Mage_Payment_Block_Form
17
+ {
18
+ /**
19
+ * Payment method code
20
+ * @var string
21
+ */
22
+ protected $_methodCode = 'payu_account';
23
+
24
+
25
+ /**
26
+ * Set template and redirect message
27
+ */
28
+ protected function _construct()
29
+ {
30
+ $this->setTemplate('payu_account/form.phtml');
31
+ $this->setMethodTitle('');
32
+ $this->setMethodLabelAfterHtml('<img src="'.Mage::getModel('payu_account/config')->getThumbnailSrc().'" height="20" alt="PayU"/> '.Mage::helper('payu_account')->__('Credit Card or E-transfer'));
33
+
34
+ return parent::_construct();
35
+ }
36
+
37
+ /**
38
+ * Payment method code getter
39
+ * @return string
40
+ */
41
+ public function getMethodCode()
42
+ {
43
+ return $this->_methodCode;
44
+ }
45
+ }
app/code/local/PayU/Account/Block/Onestep/Checkout.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU One Step Checkout Block
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+ class PayU_Account_Block_Onestep_Checkout extends Mage_Core_Block_Template
15
+ {
16
+
17
+ /** @var config variable */
18
+ protected $_config;
19
+
20
+ /** @var string Start One Step action */
21
+ protected $_startAction = 'newOneStep';
22
+
23
+ /** @var bool Whether the block should be eventually rendered */
24
+ protected $_shouldRender = true;
25
+
26
+ /** @var string Express checkout model factory name */
27
+ protected $_checkoutType = 'payu_account/express_checkout';
28
+
29
+ /**
30
+ * (non-PHPdoc)
31
+ * @see magento/app/code/core/Mage/Core/Block/Mage_Core_Block_Template::_toHtml()
32
+ */
33
+ protected function _toHtml()
34
+ {
35
+
36
+
37
+ if($this->getRequest()->getParam('submitCustomCheckout'))
38
+ {
39
+ $billingAddress = $this->getRequest()->getParam('billing');
40
+ $billingAddress['use_for_shipping'] = 0;
41
+ $shippingAddress = $this->getRequest()->getParam('shipping');
42
+ }
43
+
44
+
45
+ $this->_config = Mage::getModel('payu_account/config');
46
+ $this->setButtonSrc($this->_config->getButtonSrc());
47
+ $this->setIsOneStepCheckoutEnabled($this->_config->getIsOneStepCheckoutEnabled());
48
+ $this->setIsOneStepCheckoutAvailable($this->_config->getIsOneStepCheckoutAvailable());
49
+ $this->setCheckoutUrl($this->_config->getBaseUrl().$this->_startAction);
50
+
51
+ return parent::_toHtml();
52
+ }
53
+ }
app/code/local/PayU/Account/Block/Redirect.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Payment Redirect Block
6
+ * Payment
7
+ *
8
+ * @copyright Copyright (c) 2011-2012 PayU
9
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
10
+ * http://www.payu.com
11
+ * http://www.openpayu.com
12
+ * http://twitter.com/openpayu
13
+ */
14
+
15
+ class PayU_Account_Block_Redirect extends Mage_Core_Block_Abstract
16
+ {
17
+
18
+ protected $_order = null;
19
+
20
+ protected $_allShippingMethods = null;
21
+
22
+ /**
23
+ * (non-PHPdoc)
24
+ * @see magento1/app/code/core/Mage/Core/Block/Mage_Core_Block_Abstract::_toHtml()
25
+ */
26
+ protected function _toHtml()
27
+ {
28
+ /**
29
+ * Fetching current payment
30
+ *
31
+ * @var PayU_Account_Model_Payment
32
+ */
33
+ $payment = Mage::getModel('payu_account/payment');
34
+
35
+ /**
36
+ * Payment form
37
+ * @var Varien_Data_Form
38
+ */
39
+ $form = new Varien_Data_Form();
40
+
41
+ /**
42
+ * Setting the redirect info
43
+ * @var array
44
+ */
45
+ $redirectData = $payment->orderCreateRequest($this->_order,$this->_allShippingMethods);
46
+
47
+ $form->setAction($redirectData['url'])
48
+ ->setId('payu_checkout')
49
+ ->setName('payu_checkout')
50
+ ->setMethod('GET')
51
+ ->setUseContainer(true);
52
+
53
+ $form->addField('redirect_uri', 'hidden', array('name'=>'redirect_uri', 'value'=>$redirectData['redirect_uri']));
54
+ $form->addField('response_type', 'hidden', array('name'=>'response_type', 'value'=>$redirectData['response_type']));
55
+ $form->addField('client_id', 'hidden', array('name'=>'client_id', 'value'=>$redirectData['client_id']));
56
+
57
+ $html = '<html><body>';
58
+ $html.= $form->toHtml();
59
+ $html.= '<script type="text/javascript">document.getElementById("payu_checkout").submit();</script>';
60
+ $html.= '</body></html>';
61
+
62
+ return $html;
63
+ }
64
+
65
+ public function setAllShippingMethods($allShippingMethods){
66
+ $this->_allShippingMethods = $allShippingMethods;
67
+ return $this;
68
+ }
69
+
70
+ public function setOrder($order) {
71
+ $this->_order = $order;
72
+ return $this;
73
+ }
74
+ }
app/code/local/PayU/Account/Block/UpdateInfo.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Update Info Block
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+ class PayU_Account_Block_UpdateInfo extends Mage_Adminhtml_Block_System_Config_Form_Field
15
+ {
16
+
17
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
18
+ {
19
+
20
+ /** @var array Get latest version of the plugin */
21
+ $latestVersion = Mage::getModel('payu_account/config')->getLatestVersion();
22
+
23
+ /** @var array Get latest version info of the plugin */
24
+ $latestVersionInfo = Mage::getModel('payu_account/config')->getLatestVersionInfo();
25
+
26
+ if(!Mage::getModel('payu_account/config')->isLatestVersionInstalled()){
27
+
28
+ $html = "<div style='text-align:center;padding:5px;margin:5px 0px 5px 0px;border:1px #e58080 solid;background-color:#f6d3d3;box-shadow:2px 2px 6px #ccc;color:#ae1111;'>".Mage::helper('payu_account')->__('CAUTION: PayU plugin is not up to date.')."</div>";
29
+ $html .= Mage::helper('payu_account')->__('You are currently using version').":<br><b>";
30
+ $html .= Mage::getModel('payu_account/config')->getPluginVersion()." ".Mage::helper('payu_account')->__('for')." magento ".Mage::getModel('payu_account/config')->getMinimumMageVersion()."+</b><hr>";
31
+
32
+ $html .= Mage::helper('payu_account')->__('The latest version of PayU plugin is');
33
+ $html .= " <b>".$latestVersion['version']."</b>";
34
+
35
+ $html .= "<div style='text-align:center;padding:5px;margin:5px 0px 5px 0px;border:1px #c0dbea solid;background-color:#f4f9fb;box-shadow:2px 2px 6px #ccc;color:#1f516e;'><a href=\"http://".$latestVersionInfo['repository']."\" target=\"_blank\">".$latestVersionInfo['repository']."</a></div>";
36
+
37
+ }else{
38
+
39
+ $html = "<div style='text-align:center;padding:5px;margin:5px 0px 5px 0px;border:1px #97cf7b solid;background-color:#dbf2d0;box-shadow:2px 2px 6px #ccc;color:#3c8a15;'>".Mage::helper('payu_account')->__('OK: PayU plugin is up to date.')."</div>";
40
+ $html .= Mage::helper('payu_account')->__('You are currently using version').":<br><b>";
41
+ $html .= Mage::getModel('payu_account/config')->getPluginVersion()." ".Mage::helper('payu_account')->__('for')." magento ".Mage::getModel('payu_account/config')->getMinimumMageVersion()."+</b><hr>";
42
+
43
+ }
44
+ $html .= Mage::helper('payu_account')->__('Documents attached to this implementation').":<br>";
45
+
46
+ foreach($latestVersion['docs']['guides'] as $doc){
47
+
48
+ $html .= $this->getLayout()->createBlock('adminhtml/widget_button')
49
+ ->setType('button')
50
+ ->setClass('scalable')
51
+ ->setLabel($doc['name'])
52
+ ->setOnClick("window.open('".$doc['url']."')")
53
+ ->toHtml();
54
+ $html .= "<br>";
55
+
56
+ }
57
+
58
+ if(count($latestVersion['docs']['websites']) > 0){
59
+ $html .= Mage::helper('payu_account')->__('More info on').":<br>";
60
+ }
61
+
62
+ foreach($latestVersion['docs']['websites'] as $key => $website){
63
+
64
+
65
+ $html .= $this->getLayout()->createBlock('adminhtml/widget_button')
66
+ ->setType('button')
67
+ ->setClass('scalable')
68
+ ->setLabel($website['name'])
69
+ ->setOnClick("window.open('".$website['url']."')")
70
+ ->toHtml();
71
+ $html .= "<br>";
72
+
73
+ }
74
+
75
+ $html .= $latestVersion['description'];
76
+
77
+ return $html;
78
+ }
79
+ }
app/code/local/PayU/Account/Helper/Data.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Data Helper Model
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+ class PayU_Account_Helper_Data extends Mage_Core_Helper_Abstract
15
+ {
16
+ /**
17
+ * Converts the Magento float values (for instance 9.9900) to PayU accepted Currency format (999)
18
+ *
19
+ * @param string
20
+ * @return int
21
+ */
22
+ public function toAmount($val){
23
+ return (int)($val*100);
24
+ }
25
+
26
+ /**
27
+ * Change locale of given string and separator
28
+ * @param string $string
29
+ * @param string $s
30
+ */
31
+
32
+ public function localize($string, $s = "/"){
33
+
34
+ $lang = explode("_",Mage::app()->getLocale()->getLocaleCode());
35
+
36
+ if(!in_array($lang[0],array("pl","en")))
37
+ $lang[0] = "en";
38
+
39
+ $from = array("/pl/","/en/",$s."pl".$s,$s."en".$s,"_en.","_pl.");
40
+ $to = array("/".$lang[0]."/","/".$lang[0]."/",$s.$lang[0].$s,$s.$lang[0].$s,"_".$lang[0].".","_".$lang[0].".");
41
+
42
+ return str_replace($from, $to, $string);
43
+
44
+ }
45
+
46
+ public function isFirstVersionNewer($build1,$build2){
47
+ $arr1 = explode(".",$build1);
48
+ $arr2 = explode(".",$build2);
49
+
50
+ $b1 = "";
51
+ $b2 = "";
52
+
53
+ foreach($arr1 as $key => $b){
54
+ $b1 .= str_pad($arr1[$key], 4,"0",STR_PAD_LEFT);
55
+ $b2 .= str_pad($arr2[$key], 4,"0",STR_PAD_LEFT);
56
+ }
57
+
58
+ return ((int)$b1 > (int)$b2);
59
+ }
60
+
61
+ /*
62
+ public function localize($string, $s = "/"){
63
+ $lang = explode("_",Mage::app()->getLocale()->getLocaleCode());
64
+ if(!in_array($lang[0],array("pl","en")))
65
+ $lang[0] = "en";
66
+
67
+ _pl. _pl_ /pl/
68
+
69
+ $patt = array('[_./]pl[_./]','[_./]en[_./]');
70
+ $repl = array('[_./]'.$lang[0].'[_./]','[_./]'.$lang[0].'[_./]');
71
+ return preg_replace($patt,$repl,$string);
72
+ }*/
73
+
74
+ }
app/code/local/PayU/Account/Model/Adminhtml/Sales/Order.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class PayU_Account_Adminhtml_Model_Order extends Mage_Adminhtml_Sales_Model_Order{
4
+
5
+
6
+ public function newFunctions()
7
+ {
8
+ //new functions/methods content
9
+ }
10
+
11
+ public function existingFunctions()
12
+ {
13
+ //new functions/methods content with the extended functionalities
14
+ }
15
+
16
+
17
+ }
app/code/local/PayU/Account/Model/Advertisement.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Logo Model
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+ class PayU_Account_Model_Advertisement
15
+ {
16
+
17
+ public function toOptionArray()
18
+ {
19
+
20
+ $advertisements = Mage::getModel('payu_account/config')->getGoods('media_adverts_skyscraper');
21
+
22
+ $options = array();
23
+
24
+ foreach ($advertisements as $code => $label) {
25
+ $options[] = array(
26
+ 'value' => $label,
27
+ 'label' => $label
28
+ );
29
+ }
30
+ return $options;
31
+ }
32
+ }
app/code/local/PayU/Account/Model/Button.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Button Model
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+ class PayU_Account_Model_Button
15
+ {
16
+
17
+ public function toOptionArray()
18
+ {
19
+
20
+ /** @var array get list of available buttons */
21
+ $buttons = Mage::getModel('payu_account/config')->getGoods('media_buttons');
22
+
23
+ $options = array();
24
+
25
+ foreach ($buttons as $label) {
26
+ $options[] = array(
27
+ 'value' => $label,
28
+ 'label' => $label
29
+ );
30
+ }
31
+ return $options;
32
+ }
33
+ }
app/code/local/PayU/Account/Model/Config.php ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Config Model
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+ class PayU_Account_Model_Config
15
+ {
16
+ /** @var string self version */
17
+ protected $_pluginVersion = '0.1.6.1';
18
+
19
+ /** @var string minimum Magento e-commerce version */
20
+ protected $_minimumMageVersion = '1.6.0';
21
+
22
+ /** @var string stores information about current working environment */
23
+ protected $_env;
24
+
25
+ /** @var string prefix for configuration variables depending on environment */
26
+ protected $_prefix;
27
+
28
+ /** @var string represents the goods url */
29
+ protected $_goodsUrl = "http://openpayu.com/en/goods/json";
30
+
31
+ /** @var latest version path in goods array */
32
+ // @todo make it magento not osc, when magento is available
33
+ protected $_latestVersionPath = "plugins_magento_1.6.0";
34
+
35
+ /** @var string latest version url */
36
+ protected $_latestVersionUrl;
37
+
38
+ /** @var array latest plugin version info */
39
+ protected $_latestVersion;
40
+
41
+ /** @var array The goods resources are stored here */
42
+ protected $_goods;
43
+
44
+ protected $_storeId;
45
+
46
+ /**
47
+ * Constructor
48
+ *
49
+ * @param $params
50
+ */
51
+ public function __construct($params = array())
52
+ {
53
+
54
+ // assign current store id
55
+ $this->setStoreId();
56
+ // initialize the working environment
57
+ $this->setEnvironment();
58
+ // assign goods data
59
+ $this->setGoods();
60
+ // set latest version url
61
+ $this->setLatestVersionUrl();
62
+ // set latest version data
63
+ $this->setLatestVersion();
64
+ }
65
+
66
+
67
+
68
+ /** set current store Id */
69
+ protected function setStoreId(){
70
+ $this->_storeId = Mage::app()->getStore()->getId();
71
+ }
72
+
73
+ /**
74
+ * Set the environment
75
+ * @return string PayU environment variable
76
+ */
77
+ protected function setEnvironment(){
78
+
79
+ switch(Mage::getStoreConfig('payment/payu_account/environment')){
80
+
81
+ //check if we work in production mode
82
+ case PayU_Account_Model_Environment::PRODUCTION:
83
+ $this->_env = "secure";
84
+ $this->_prefix = "";
85
+ break;
86
+ // default sandbox mode
87
+ default:
88
+ $this->_env = "sandbox";
89
+ $this->_prefix = $this->_env."_";
90
+ break;
91
+
92
+ }
93
+
94
+ return $this->_env;
95
+
96
+ }
97
+
98
+ /** @return string get current environment */
99
+ public function getEnvironment(){
100
+ return $this->setEnvironment();
101
+ }
102
+
103
+ /** @return string get Merchant POS Id */
104
+ public function getMerchantPosId(){
105
+
106
+ // return Mage::getStoreConfig('payment/payu/'.$this->_prefix.'pos_id',Mage::app()->getStore()->getId());
107
+ // currently it is the same, so no need to separate parameter configuration
108
+ return $this->getClientId();
109
+
110
+ }
111
+
112
+ /** @return string get Pos Auth Key */
113
+ public function getPosAuthKey(){
114
+ return $this->getStoreConfig('payment/payu_account/'.$this->_prefix.'pos_auth_key');
115
+ }
116
+
117
+ /** @return string get (OAuth Client Name) */
118
+ public function getClientId(){
119
+ return $this->getStoreConfig('payment/payu_account/'.$this->_prefix.'oauth_client_name');
120
+ }
121
+
122
+ /** @return string get (OAuth Client Secret) */
123
+ public function getClientSecret(){
124
+ return $this->getStoreConfig('payment/payu_account/'.$this->_prefix.'oauth_client_secret');
125
+ }
126
+
127
+ /** @return string get signature key */
128
+ public function getSignatureKey(){
129
+ return $this->getStoreConfig('payment/payu_account/'.$this->_prefix.'signature_key');
130
+ }
131
+
132
+ /** @return int order validity time in minutes */
133
+ public function getOrderValidityTime(){
134
+
135
+ $validityTime = $this->getStoreConfig('payment/payu_account/validity_time');
136
+
137
+ if($validityTime)
138
+ $validityTime;
139
+ return "1440";
140
+ }
141
+
142
+ /** @return string small logo src */
143
+ public function getThumbnailSrc(){
144
+ return $this->getStoreConfig('payment/payu_account/payuthumbnail');
145
+ }
146
+
147
+ /** @return string advertisement banner url */
148
+ public function getAdvertisementSrc(){
149
+ return $this->getStoreConfig('payment/payu_account/payuadvertisement');
150
+ }
151
+
152
+ /** @return string one step checkout button url */
153
+ public function getButtonSrc(){
154
+ return $this->localize($this->getStoreConfig('payment/payu_account/payubutton'));
155
+ }
156
+
157
+ /** $return string base module url */
158
+ public function getBaseUrl(){
159
+ return Mage::getBaseUrl().'payu_account/payment/';
160
+ }
161
+
162
+ /** @return string check if is one step checkout method enabled */
163
+ public function getIsOneStepCheckoutEnabled(){
164
+ return $this->getStoreConfig('payment/payu_account/onestepcheckoutenabled');
165
+ }
166
+
167
+ /** @return string check if is one step checkout method available */
168
+ public function getIsOneStepCheckoutAvailable(){
169
+ return true;
170
+ }
171
+
172
+ /** @return int what is the default new order status */
173
+ public function getNewOrderStatus(){
174
+ return $this->getStoreConfig('payment/payu_account/order_status');
175
+ }
176
+
177
+ public function isLatestVersionInstalled(){
178
+ return !Mage::helper('payu_account')->isFirstVersionNewer($this->_latestVersion['version'],$this->_pluginVersion);
179
+ }
180
+
181
+ /** @return int what is the default new order status */
182
+ public function getIsSelfReturnEnabled(){
183
+ return $this->getStoreConfig('payment/payu_account/selfreturn');
184
+ }
185
+
186
+ /**
187
+ * Returns goods array (or string when leaf selected) depending on the needs
188
+ * @param string $name
189
+ * @return array|string $goods
190
+ */
191
+ public function getGoods($name = null){
192
+
193
+ $goodsItem = $this->_goods;
194
+
195
+ if($name !== null){
196
+
197
+ $name_arr = explode("_",$name);
198
+
199
+ foreach($name_arr as $col){
200
+ if(empty($goodsItem[$col]))
201
+ return array('error');
202
+ $goodsItem = $goodsItem[$col];
203
+ }
204
+
205
+ }
206
+
207
+ return $this->localize($goodsItem);
208
+
209
+ }
210
+
211
+ /** @return array get latest plugin version data */
212
+ public function getLatestVersion(){
213
+ return $this->_latestVersion;
214
+ }
215
+
216
+ /** @return array get main latest version of plugin info */
217
+ public function getLatestVersionInfo(){
218
+ return $this->getGoods($this->_latestVersionPath,"_");
219
+ }
220
+
221
+ /** @return get current plugin version */
222
+ public function getPluginVersion(){
223
+ return $this->_pluginVersion;
224
+ }
225
+
226
+ /** @return string get minimum mage version for the plugin to work on */
227
+ public function getMinimumMageVersion(){
228
+ return $this->_minimumMageVersion;
229
+ }
230
+
231
+ /** assign latest version */
232
+ protected function setLatestVersionUrl(){
233
+ $this->_latestVersionUrl = $this->getGoods($this->localize($this->_latestVersionPath."_info","_"));
234
+ }
235
+
236
+ /**
237
+ * Change locale of given string
238
+ *
239
+ * @param $string
240
+ * @param $s
241
+ * @return string
242
+ */
243
+ protected function localize($string, $s = "/"){
244
+ return Mage::helper('payu_account')->localize($string, $s);
245
+ }
246
+
247
+ /** assign latest version data */
248
+ protected function setLatestVersion(){
249
+ $this->_latestVersion = $this->getArrayFromJsonResponse($this->_latestVersionUrl);
250
+ }
251
+
252
+ /** assign goods resources array */
253
+ protected function setGoods(){
254
+ $this->_goods = $this->getArrayFromJsonResponse($this->_goodsUrl);
255
+ }
256
+
257
+ /**
258
+ * Converts json response to array
259
+ *
260
+ * @param $url string
261
+ * @return array
262
+ */
263
+ protected function getArrayFromJsonResponse($url){
264
+ $httpClient = new Varien_Http_Client($url);
265
+ $response = $httpClient->request(Varien_Http_Client::GET);
266
+ return json_decode($response->getBody(),true);
267
+ }
268
+
269
+ /**
270
+ * get Store Config variable
271
+ * @param $name
272
+ * @return string
273
+ */
274
+ protected function getStoreConfig($name){
275
+ return Mage::getStoreConfig($name,$this->_storeId);
276
+ }
277
+
278
+ public function getDomainName()
279
+ {
280
+ return $_SERVER['HTTP_HOST'];
281
+ }
282
+
283
+
284
+ }
285
+
app/code/local/PayU/Account/Model/Environment.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ /**
5
+ * ver. 0.1.6.1
6
+ * PayU Environment Model
7
+ *
8
+ * @copyright Copyright (c) 2011-2012 PayU
9
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
10
+ * http://www.payu.com
11
+ * http://www.openpayu.com
12
+ * http://twitter.com/openpayu
13
+ */
14
+
15
+
16
+ class PayU_Account_Model_Environment
17
+ {
18
+
19
+ /** @var string Production environment */
20
+ const PRODUCTION = 'secure';
21
+
22
+ /** @var string Testing environment */
23
+ const SANDBOX = 'sandbox';
24
+
25
+ public function toOptionArray() {
26
+ return array(
27
+ array(
28
+ 'value' => PayU_Account_Model_Environment::PRODUCTION,
29
+ 'label' => Mage::helper('payu_account')->__('Production')
30
+ ),
31
+ array(
32
+ 'value' => PayU_Account_Model_Environment::SANDBOX,
33
+ 'label' => 'Sandbox'
34
+ )
35
+ );
36
+ }
37
+ }
app/code/local/PayU/Account/Model/PayU.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Standard Payment Model
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+ class PayU_Account_Model_PaymentMethod extends Mage_Payment_Model_Method_Cc
15
+ {
16
+ /**
17
+ * unique internal payment method identifier
18
+ *
19
+ * @var string [a-z0-9_]
20
+ */
21
+ protected $_code = 'payu_account';
22
+
23
+ /**
24
+ * Here are examples of flags that will determine functionality availability
25
+ * of this module to be used by frontend and backend.
26
+ *
27
+ * @see all flags and their defaults in Mage_Payment_Model_Method_Abstract
28
+ *
29
+ * It is possible to have a custom dynamic logic by overloading
30
+ * public function can* for each flag respectively
31
+ */
32
+
33
+ /**
34
+ * Is this payment method a gateway (online auth/charge) ?
35
+ */
36
+ protected $_isGateway = true;
37
+
38
+ /**
39
+ * Can authorize online?
40
+ */
41
+ protected $_canAuthorize = true;
42
+
43
+ /**
44
+ * Can capture funds online?
45
+ */
46
+ protected $_canCapture = true;
47
+
48
+ /**
49
+ * Can capture partial amounts online?
50
+ */
51
+ protected $_canCapturePartial = false;
52
+
53
+ /**
54
+ * Can refund online?
55
+ */
56
+ protected $_canRefund = false;
57
+
58
+ /**
59
+ * Can void transactions online?
60
+ */
61
+ protected $_canVoid = true;
62
+
63
+ /**
64
+ * Can use this payment method in administration panel?
65
+ */
66
+ protected $_canUseInternal = true;
67
+
68
+ /**
69
+ * Can show this payment method as an option on checkout payment page?
70
+ */
71
+ protected $_canUseCheckout = true;
72
+
73
+ /**
74
+ * Is this payment method suitable for multi-shipping checkout?
75
+ */
76
+ protected $_canUseForMultishipping = true;
77
+
78
+ /**
79
+ * Can save credit card information for future processing?
80
+ */
81
+ protected $_canSaveCc = true;
82
+
83
+ /**
84
+ * Here you will need to implement authorize, capture and void public methods
85
+ *
86
+ * @see examples of transaction specific public methods such as
87
+ * authorize, capture and void in Mage_Paygate_Model_Authorizenet
88
+ */
89
+ }
90
+ ?>
app/code/local/PayU/Account/Model/Payment.php ADDED
@@ -0,0 +1,1132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU -Standard Payment Model
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+ require_once('lib/payu/sdk/openpayu.php');
15
+
16
+ class PayU_Account_Model_Payment extends Mage_Payment_Model_Method_Abstract
17
+
18
+ {
19
+ /**
20
+ *
21
+ * Configuration
22
+ * @var PayU_Account_Model_Config
23
+ */
24
+ protected $_config;
25
+
26
+ /**
27
+ *
28
+ * The base module url
29
+ * @var string
30
+ */
31
+ protected $_myUrl;
32
+
33
+ /**
34
+ *
35
+ * Payment method code
36
+ * @var string
37
+ */
38
+ protected $_code = 'payu_account';
39
+
40
+ /**
41
+ *
42
+ * Payment method title
43
+ * @var string
44
+ */
45
+ protected $_title = 'PayU account';
46
+
47
+ /**
48
+ *
49
+ * Block type
50
+ * @var string
51
+ */
52
+ protected $_formBlockType = 'payu_account/form';
53
+
54
+ /**
55
+ *
56
+ * Is initialization needed
57
+ * @var boolean
58
+ */
59
+ protected $_isInitializeNeeded = true;
60
+
61
+ /**
62
+ *
63
+ * Can use internal
64
+ * @var boolean
65
+ */
66
+ protected $_canUseInternal = false;
67
+
68
+ /**
69
+ *
70
+ * Enter description here ...
71
+ * @var unknown_type
72
+ */
73
+ protected $_canUseForMultishipping = false;
74
+
75
+ /**
76
+ * Transaction id
77
+ */
78
+ protected $_transactionId;
79
+
80
+ /**
81
+ * Currently processed order
82
+ *
83
+ * @var Mage_Sales_Model_Order
84
+ */
85
+ protected $_order;
86
+
87
+ protected $_tempInfo = "AWAITING_PayU";
88
+
89
+ /**
90
+ * PayU payment statuses
91
+ *
92
+ * @var string
93
+ */
94
+ const PAYMENT_STATUS_NEW = 'PAYMENT_STATUS_NEW';
95
+ const PAYMENT_STATUS_CANCEL = 'PAYMENT_STATUS_CANCEL';
96
+ const PAYMENT_STATUS_REJECT = 'PAYMENT_STATUS_REJECT';
97
+ const PAYMENT_STATUS_INIT = 'PAYMENT_STATUS_INIT';
98
+ const PAYMENT_STATUS_SENT = 'PAYMENT_STATUS_SENT';
99
+ const PAYMENT_STATUS_NOAUTH = 'PAYMENT_STATUS_NOAUTH';
100
+ const PAYMENT_STATUS_REJECT_DONE = 'PAYMENT_STATUS_REJECT_DONE';
101
+ const PAYMENT_STATUS_END = 'PAYMENT_STATUS_END';
102
+ const PAYMENT_STATUS_ERROR = 'PAYMENT_STATUS_ERROR';
103
+
104
+ const NEW_PAYMENT_URL = "payu_account/payment/new";
105
+
106
+ /**
107
+ * PayU order statuses
108
+ *
109
+ * @var string
110
+ */
111
+
112
+ const ORDER_STATUS_PENDING = 'ORDER_STATUS_PENDING';
113
+ const ORDER_STATUS_SENT = 'ORDER_STATUS_SENT';
114
+ const ORDER_STATUS_COMPLETE = 'ORDER_STATUS_COMPLETE';
115
+ const ORDER_STATUS_CANCEL = 'ORDER_STATUS_CANCEL';
116
+ const ORDER_STATUS_REJECT = 'ORDER_STATUS_REJECT';
117
+
118
+ /**
119
+ * Constructor
120
+ */
121
+ public function __construct()
122
+ {
123
+ parent::__construct();
124
+
125
+ // initialize the PayU config
126
+ $this->initializeOpenPayUConfiguration();
127
+ }
128
+
129
+ /**
130
+ * Initializes the payment ...
131
+ *
132
+ * @param Mage_Sales_Model_Order
133
+ * @param Mage_Shipping_Model_Shipping
134
+ * @return array
135
+ */
136
+ public function orderCreateRequest(Mage_Sales_Model_Order $order, $allShippingRates)
137
+ {
138
+
139
+ $this->_order = $order;
140
+
141
+ /**
142
+ * Setting session identifier
143
+ *
144
+ * @var string
145
+ */
146
+ $sessionid = md5(rand() . rand() . rand() . rand()) . "-" . $this->_order->getRealOrderId() . "-" . $this->_order->getId();
147
+
148
+
149
+ // store session identifier in session info
150
+ Mage::getSingleton('core/session')->setPayUSessionId($sessionid);
151
+
152
+ // assign current transaction id
153
+ $this->_transactionId = $sessionid;
154
+
155
+ /** @var string Order Currency Code */
156
+ $orderCurrencyCode = $this->_order->getOrderCurrencyCode();
157
+
158
+ /** @var string Country Code */
159
+ $orderCountryCode = $this->_order->getShippingAddress()->getCountry();
160
+
161
+ /** @var array assign the shipping info for created order */
162
+ $shippingCostList = array();
163
+
164
+ // assigning the shipping costs list
165
+ foreach ($allShippingRates as $rate) {
166
+
167
+ $shippingCostList[] = array(
168
+ 'ShippingCost' => array(
169
+ 'Type' => $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle(),
170
+ 'CountryCode' => $orderCountryCode,
171
+ 'Price' => array(
172
+ 'Gross' => $this->toAmount($rate->getPrice()),
173
+ 'Net' => $this->toAmount($rate->getPrice()),
174
+ 'Tax' => $this->toAmount($this->_order->getShippingTaxAmount()),
175
+ 'TaxRate' => $this->toAmount($this->calculateTaxRate()),
176
+ 'CurrencyCode' => $orderCurrencyCode
177
+ )
178
+ )
179
+ );
180
+
181
+ }
182
+
183
+ $shippingCost = array('CountryCode' => $orderCountryCode,
184
+ 'ShipToOtherCountry' => 'true',
185
+ 'ShippingCostList' => $shippingCostList
186
+ );
187
+
188
+ //print_r($shippingCost);
189
+
190
+ /** @var string All items included in the order */
191
+ $orderItems = $this->_order->getAllVisibleItems();
192
+
193
+ /** @var array Here is where order items will be processed for PayU purposes */
194
+ $items = array();
195
+
196
+ foreach ($orderItems as $key => $item) {
197
+
198
+ /** @var array Retrieving item info */
199
+ $itemInfo = $item->getData();
200
+
201
+ // Check if the item is countable one
202
+ if ($this->toAmount($itemInfo['price_incl_tax']) > 0) {
203
+
204
+ /** Pushing the current item to ShoppingCarItems list */
205
+ $items[]['ShoppingCartItem'] = array(
206
+ 'Quantity' => (int)$itemInfo['qty_ordered'],
207
+ 'Product' => array(
208
+ 'Name' => $itemInfo['name'],
209
+ 'UnitPrice' => array(
210
+ 'Gross' => $this->toAmount($itemInfo['price_incl_tax']),
211
+ 'Net' => $this->toAmount($itemInfo['price']),
212
+ 'Tax' => $this->toAmount($itemInfo['tax_amount']),
213
+ 'TaxRate' => $this->toAmount($itemInfo['tax_percent']),
214
+ 'CurrencyCode' => $orderCurrencyCode
215
+ )
216
+ )
217
+ );
218
+
219
+
220
+ }
221
+
222
+ }
223
+
224
+
225
+ // assigning the shopping cart
226
+ $shoppingCart = array('GrandTotal' => $this->toAmount($this->_order->getBaseSubtotal()),
227
+ 'CurrencyCode' => $orderCurrencyCode,
228
+ 'ShoppingCartItems' => $items
229
+ );
230
+
231
+ /** @var string Check wether the order is virtual or material */
232
+ $orderType = ($this->_order->getIsVirtual()) ? "VIRTUAL" : "MATERIAL";
233
+
234
+ // http://www.payu.com/pl/openpayu/OrderDomainRequest.html#Link18
235
+ $orderInfo = array('MerchantPosId' => OpenPayU_Configuration::getMerchantPosId(),
236
+ 'SessionId' => $sessionid,
237
+ 'OrderUrl' => $this->_myUrl . 'cancelPayment?order=' . $this->_order->getRealOrderId(), // is url where customer will see in myaccount, and will be able to use to back to shop.
238
+ 'OrderCreateDate' => date("c"),
239
+ 'OrderDescription' => 'Order no ' . $this->_order->getId(),
240
+ 'MerchantAuthorizationKey' => OpenPayU_Configuration::getPosAuthKey(),
241
+ 'OrderType' => $orderType,
242
+ 'ShoppingCart' => $shoppingCart,
243
+ 'ValidityTime' => $this->_config->getOrderValidityTime()
244
+ );
245
+
246
+ // http://www.payu.com/pl/openpayu/OrderDomainRequest.html#Link2
247
+ $OCReq = array('ReqId' => md5(rand()),
248
+ 'CustomerIp' => Mage::app()->getFrontController()->getRequest()->getClientIp(),
249
+ 'NotifyUrl' => $this->_myUrl . 'orderNotifyRequest', // url where PayU service will send notification with order processing status changes
250
+ 'OrderCancelUrl' => $this->_myUrl . 'cancelPayment',
251
+ 'OrderCompleteUrl' => $this->_myUrl . 'completePayment',
252
+ 'Order' => $orderInfo,
253
+ 'ShippingCost' => array(
254
+ 'AvailableShippingCost' => $shippingCost,
255
+ 'ShippingCostsUpdateUrl' => $this->_myUrl . 'shippingCostRetrieve' // this is url where PayU checkout service will send shipping costs retrieve request
256
+ )
257
+ );
258
+
259
+ //print_r($OCReq);
260
+
261
+ //return;
262
+
263
+ // send message OrderCreateRequest, $result->response = OrderCreateResponse message
264
+ $result = OpenPayU_Order::create($OCReq);
265
+
266
+ if ($result->getSuccess()) {
267
+
268
+ /** @var array Assigning the redirect form data */
269
+ $ret = array(
270
+ 'url' => OpenPayU_Configuration::getAuthUrl(),
271
+ 'redirect_uri' => $this->_myUrl . "beforeSummary",
272
+ 'response_type' => "code",
273
+ 'client_id' => OpenPayU_Configuration::getClientId()
274
+ );
275
+
276
+
277
+ } else {
278
+ /** Something has gone wrong with the $result succession */
279
+ Mage::throwException($this->__('There was a problem with initializing the payment, please contact the store administrator.' . $result->getError() . ' ' . $result->getMessage()));
280
+ }
281
+
282
+ return $ret;
283
+
284
+ }
285
+
286
+ /**
287
+ * One Step Checkout initialization
288
+ * @return Mage_Sales_Model_Order
289
+ */
290
+ public function newOneStep()
291
+ {
292
+
293
+
294
+ $checkout = Mage::getSingleton('checkout/type_onepage');
295
+
296
+ $customerSession = Mage::getSingleton('customer/session');
297
+
298
+ $checkout->initCheckout();
299
+
300
+ // if guest payment
301
+ if (!$customerSession->isLoggedIn()) {
302
+ ;
303
+
304
+ $billingAddress = array
305
+ (
306
+ 'address_id' => 5,
307
+ 'firstname' => $this->_tempInfo,
308
+ 'lastname' => $this->_tempInfo,
309
+ 'company' => "",
310
+ 'street' => array
311
+ (
312
+ 0 => $this->_tempInfo,
313
+ 1 => $this->_tempInfo
314
+ ),
315
+ 'city' => 'City',
316
+ 'postcode' => "00000",
317
+ 'country_id' => "PL",
318
+ 'telephone' => "000000000",
319
+ 'save_in_address_book' => 0
320
+ );
321
+
322
+ $checkout->saveBilling($billingAddress, false);
323
+ $checkout->saveShipping($billingAddress, false);
324
+ $checkout->saveCheckoutMethod('guest');
325
+ $checkout->getQuote()->setCustomerId(null)
326
+ ->setCustomerIsGuest(true)->setCustomerEmail(md5(rand() . rand()) . "_TEMP_PayU@" . Mage::getModel('payu_account/config')->getDomainName())
327
+ ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
328
+
329
+ } else {
330
+ $customer = $customerSession->getCustomer();
331
+ $checkout->saveBilling($customer->getDefaultBilling(), false);
332
+ $checkout->saveShipping($customer->getDefaultShipping(), false);
333
+ $checkout->saveCheckoutMethod('register');
334
+
335
+ $checkout->getQuote()->setCustomerId($customerSession->getCustomerId())
336
+ ->setCustomerIsGuest(false);
337
+ }
338
+
339
+ $checkout->getQuote()->getShippingAddress()->setShippingMethod('flatrate_flatrate')->setCollectShippingRates(true);
340
+
341
+ // presetting the default shipment method
342
+ $checkout->saveShippingMethod('flatrate_flatrate');
343
+ $checkout->getQuote()->collectTotals()->save();
344
+
345
+ // assigning the payment method type
346
+ $checkout->savePayment(array('method' => 'payu_account'));
347
+
348
+ $checkout->saveOrder();
349
+
350
+ $this->_order = Mage::getModel('sales/order')->load($checkout->getQuote()->getId(), 'quote_id');
351
+
352
+ $storeId = Mage::app()->getStore()->getId();
353
+ $paymentHelper = Mage::helper("payment");
354
+ $zeroSubTotalPaymentAction = $paymentHelper->getZeroSubTotalPaymentAutomaticInvoice($storeId);
355
+ if ($paymentHelper->isZeroSubTotal($storeId)
356
+ && $this->_order->getGrandTotal() == 0
357
+ && $zeroSubTotalPaymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE
358
+ && $paymentHelper->getZeroSubTotalOrderStatus($storeId) == 'pending'
359
+ ) {
360
+ $invoice = $this->_initInvoice();
361
+ $invoice->getOrder()->setIsInProcess(true);
362
+ $transactionSave = Mage::getModel('core/resource_transaction')
363
+ ->addObject($invoice)
364
+ ->addObject($invoice->getOrder());
365
+ $transactionSave->save();
366
+ }
367
+
368
+ return $this->_order;
369
+
370
+ }
371
+
372
+
373
+ /**
374
+ * Processing the BeforeSummary from PayU
375
+ *
376
+ * @return array
377
+ */
378
+ public function beforeSummary()
379
+ {
380
+
381
+ // After customer login PayU service redirect back user to merchant with ?code=... paramater.
382
+ // Parameter code is used to retrieve accessToken in OAuth autorization code mode from PayU service.
383
+
384
+ $code = Mage::app()->getRequest()->getParam('code');
385
+ $returnUri = $this->_myUrl . "beforeSummary";
386
+ /**
387
+ try {
388
+ $url = OpenPayU_Configuration::$serviceUrl . "user/oauth/authorize";
389
+ OpenPayU::setOpenPayuEndPoint($url);
390
+ $json = OpenPayuOAuth::getAccessTokenByCode($code, OpenPayU_Configuration::$clientId, OpenPayU_Configuration::$clientSecret,$returnUri);
391
+ echo $json->{"payu_user_email"};
392
+ } catch (Exception $ex) {
393
+ echo $ex;
394
+ }*/
395
+
396
+ $result = OpenPayU_OAuth::accessTokenByCode($code, $returnUri);
397
+
398
+ // checking if result is succeeded
399
+ if ($result->getSuccess()) {
400
+
401
+ $sessionId = Mage::getSingleton('core/session')->getPayUSessionId();
402
+ $this->setOrderBySessionId($sessionId);
403
+
404
+ $customer = Mage::getModel('customer/customer');
405
+
406
+ if ($this->_order->getCustomerIsGuest()) {
407
+ // check if we have the user in the database
408
+ $email = $result->getPayuUserEmail();
409
+ $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
410
+ $customer->loadByEmail($email);
411
+
412
+ } else {
413
+ $customer->load($this->_order->getCustomerId());
414
+ }
415
+
416
+ // if we are in guest mode
417
+ if (!$customer->getId()) {
418
+ $this->_order->setCustomerEmail($email);
419
+ } else {
420
+ $this->_order->sendNewOrderEmail();
421
+ //$this->_order->setCustomerId($customer->getId());
422
+ //$this->_order->setBillingAddress($customer->getDefaultBilling());
423
+ //$this->_order->setShippingAddress($customer->getDefaultShipping());
424
+ }
425
+
426
+ $this->_order->save();
427
+
428
+
429
+ /** @var array Data needed for redirection to PayU summary page */
430
+ $ret = array(
431
+ 'url' => OpenPayu_Configuration::getSummaryUrl(),
432
+ 'sessionId' => $sessionId,
433
+ 'oauth_token' => $result->getAccessToken(),
434
+ 'client_id' => OpenPayU_Configuration::getClientId()
435
+ );
436
+
437
+ } else {
438
+ Mage::throwException(Mage::helper('payu_account')->__('There was a problem with the payment initialization, please contact system administrator.') . $result->getError() .' '.$result->getMessage());
439
+ }
440
+
441
+ return $ret;
442
+ }
443
+
444
+ public function completeOrder($order)
445
+ {
446
+ $this->_order = $order;
447
+ $result = $this->orderStatusUpdateRequest(PayU_Account_Model_Payment::ORDER_STATUS_COMPLETE);
448
+ if ($result) {
449
+ $this->updateOrderStatus(PayU_Account_Model_Payment::ORDER_STATUS_COMPLETE);
450
+ return $result;
451
+ }
452
+ }
453
+
454
+ public function rejectOrder($order)
455
+ {
456
+ $this->_order = $order;
457
+ $result = $this->orderStatusUpdateRequest(PayU_Account_Model_Payment::ORDER_STATUS_REJECT);
458
+ if ($result) {
459
+ $this->updateOrderStatus(PayU_Account_Model_Payment::ORDER_STATUS_REJECT);
460
+ return $result;
461
+ }
462
+ }
463
+
464
+ public function cancelOrder($order)
465
+ {
466
+ $this->_order = $order;
467
+ $result = $this->orderStatusUpdateRequest(PayU_Account_Model_Payment::ORDER_STATUS_CANCEL);
468
+ if ($result) {
469
+ $this->updateOrderStatus(PayU_Account_Model_Payment::ORDER_STATUS_CANCEL);
470
+ return $result;
471
+ }
472
+ }
473
+
474
+
475
+ /** Complete payment */
476
+ public function completePayment()
477
+ {
478
+
479
+ // get some information about the order from PayU
480
+ $sessionId = Mage::getSingleton('core/session')->getPayUSessionId();
481
+ $this->retrieveAndUpdateBySessionId($sessionId);
482
+
483
+ }
484
+
485
+ /** Cancel payment */
486
+ public function cancelPayment()
487
+ {
488
+ $sessionId = Mage::app()->getRequest()->getParam('sessionId');
489
+
490
+ if (!empty($sessionId)) {
491
+ $result = OpenPayU_Order::cancel($sessionId, true);
492
+ }
493
+ }
494
+
495
+ /**
496
+ * Retrieve order info from PayU and update billing and shipping info
497
+ * @param string $sessionId
498
+ */
499
+ protected function retrieveAndUpdateBySessionId($sessionId)
500
+ {
501
+
502
+ $this->setOrderBySessionId($sessionId);
503
+
504
+ $result = OpenPayU_Order::retrieve($sessionId);
505
+
506
+ // parse the information
507
+ $response = $result->getResponse();
508
+
509
+ $orderRetrieveResponse = $response['OpenPayU']['OrderDomainResponse']['OrderRetrieveResponse'];
510
+
511
+ // get Payment status from response
512
+ $payUOrderStatus = $orderRetrieveResponse['OrderStatus'];
513
+
514
+ // get Payment status from response
515
+ $payUPaymentStatus = (isset($orderRetrieveResponse['PaymentStatus'])) ? $orderRetrieveResponse['PaymentStatus'] : false;
516
+
517
+ // update status of the payment
518
+ if (!empty($payUPaymentStatus))
519
+ $this->updatePaymentStatus($payUPaymentStatus, $payUOrderStatus);
520
+
521
+ // update order status if payment status not available
522
+ if (empty($payUPaymentStatus))
523
+ $this->updateOrderStatus($payUOrderStatus);
524
+
525
+ if (!empty($orderRetrieveResponse['CustomerRecord'])) {
526
+
527
+
528
+ // update shipping info of the order
529
+ $this->updateShippingInfo($orderRetrieveResponse);
530
+
531
+ // update customer data of the order
532
+ $this->updateCustomerData($orderRetrieveResponse);
533
+
534
+
535
+ }
536
+
537
+
538
+ }
539
+
540
+ protected function orderStatusUpdateRequest($status)
541
+ {
542
+ $sessionId = $this->_order->getPayment()->getLastTransId();
543
+ $result = OpenPayU_Order::updateStatus($sessionId, $status, true);
544
+ if ($result->getSuccess())
545
+ return $result;
546
+ else
547
+ Mage::log("PayU error while updating status: " . $result->getError());
548
+ return false;
549
+ }
550
+
551
+ protected function setOrderBySessionId($sess)
552
+ {
553
+
554
+ $orderId = $this->getOrderIdBySessionId($sess);
555
+ $this->_order = Mage::getModel('sales/order')->load($orderId);
556
+
557
+ }
558
+
559
+ /** @return xml Processing the OrderNotifyRequest from PayU */
560
+ public function orderNotifyRequest()
561
+ {
562
+
563
+ /** @var xml get posted document */
564
+ $document = Mage::app()->getRequest()->getPost('DOCUMENT');
565
+
566
+ /** if the document is empty return */
567
+ if (empty($document))
568
+ return "error";
569
+
570
+ try {
571
+ // Processing notification received from PayU service.
572
+ // Variable $notification contains array with OrderNotificationRequest message.
573
+ $result = OpenPayU_Order::consumeMessage($document);
574
+
575
+
576
+ if ($result->getMessage() == 'OrderNotifyRequest') {
577
+
578
+ /** @var string identify current session Id from document */
579
+ $sessionId = $result->getSessionId();
580
+
581
+ $this->_transactionId = $sessionId;
582
+
583
+ /** @var array get information about order */
584
+ $orderId = $this->getOrderIdBySessionId($sessionId);
585
+
586
+ if ($orderId > 0) {
587
+
588
+
589
+ $this->setOrderBySessionId($sessionId);
590
+
591
+ $this->retrieveAndUpdateBySessionId($sessionId);
592
+
593
+ }
594
+
595
+
596
+ } else {
597
+ Mage::log('PayU: There was a problem with PayU orderNotifyRequest, result data:' . serialize($result));
598
+ $ret = "error";
599
+ }
600
+
601
+ } catch (Exception $e) {
602
+ Mage::log('PayU: There was a problem with PayU orderNotifyRequest, errorMessage:' . $e->getMessage());
603
+ Mage::log('PayU: OpenPayU_Order::printOutputConsole:' . OpenPayU_Order::printOutputConsole());
604
+ $ret = "error";
605
+ }
606
+
607
+ }
608
+
609
+ /**
610
+ * Update order's customer information based on PayU information
611
+ * @var array result data from payu with billing and shipping info */
612
+ protected function updateCustomerData($data)
613
+ {
614
+
615
+ try {
616
+
617
+ $customerRecord = $data['CustomerRecord'];
618
+
619
+ //if($this->_order->getCustomerIsGuest()){
620
+
621
+ $this->_order->setCustomerFirstname($customerRecord['FirstName']);
622
+ $this->_order->setCustomerLastname($customerRecord['LastName']);
623
+
624
+ $billing = $this->_order->getBillingAddress();
625
+
626
+ $billing->setFirstname($customerRecord['FirstName']);
627
+ $billing->setLastname($customerRecord['LastName']);
628
+ $billing->setTelephone($customerRecord['Phone']);
629
+
630
+ $this->_order->setBillingAddress($billing);
631
+
632
+ //}
633
+
634
+
635
+ if (!empty($data['Shipping'])) {
636
+
637
+ $shippingAddress = $data['Shipping']['Address'];
638
+
639
+ /** check if we have guest customer */
640
+ //if($this->_order->getCustomerIsGuest()){
641
+
642
+ // assign billing additional info only to guests
643
+
644
+ $billing = $this->_order->getBillingAddress();
645
+
646
+ $billing->setCity($shippingAddress['City']);
647
+ $billing->setStreet($shippingAddress['Street'] . " " . $shippingAddress['HouseNumber'] . " / " . $shippingAddress['ApartmentNumber']);
648
+ $billing->setPostcode($shippingAddress['PostalCode']);
649
+ $billing->setCountryId($shippingAddress['CountryCode']);
650
+
651
+ $this->_order->setBillingAddress($billing);
652
+
653
+ //}
654
+
655
+
656
+ $recipient = explode(" ", $shippingAddress['RecipientName']);
657
+
658
+ $shipping = $this->_order->getShippingAddress();
659
+
660
+ $shipping->setFirstname($recipient[0]);
661
+ $shipping->setLastname($recipient[1]);
662
+ $shipping->setTelephone($customerRecord['Phone']);
663
+ $shipping->setCity($shippingAddress['City']);
664
+ $shipping->setStreet($shippingAddress['Street'] . " " . $shippingAddress['HouseNumber'] . " / " . $shippingAddress['ApartmentNumber']);
665
+ $shipping->setPostcode($shippingAddress['PostalCode']);
666
+ $shipping->setCountryId($shippingAddress['CountryCode']);
667
+
668
+ $this->_order->setShippingAddress($shipping)->save();
669
+
670
+ if (!$this->_order->getEmailSent()) {
671
+ $this->_order->sendNewOrderEmail();
672
+ $this->_order->setEmailSent(1);
673
+ }
674
+
675
+ }
676
+
677
+ $this->_order->save();
678
+
679
+ } catch (Error $e) {
680
+ }
681
+
682
+ }
683
+
684
+ /**
685
+ *
686
+ * Update shipping info after notifyRequest
687
+ * @param array $data
688
+ */
689
+ protected function updateShippingInfo($data)
690
+ {
691
+
692
+ try {
693
+
694
+ $typeChosen = $data['Shipping']['ShippingType'];
695
+ $cost = $data['Shipping']['ShippingCost']['Gross'];
696
+
697
+ if (!empty($typeChosen)) {
698
+
699
+ $quote = Mage::getModel('sales/quote')->load($this->_order->getQuoteId());
700
+ $address = $quote->getShippingAddress();
701
+
702
+ $shipping = Mage::getModel('shipping/shipping');
703
+ $shippingRates = $shipping->collectRatesByAddress($address)->getResult();
704
+
705
+ #file_put_contents("payu.log", "shipping: " . date("H:i:s") . " " . print_r($shippingRates, 1) . "\n", FILE_APPEND);
706
+
707
+ $shippingCostList = array();
708
+
709
+
710
+ foreach ($shippingRates->getAllRates() as $rate) {
711
+ $type = $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle();
712
+
713
+ if ($type == $typeChosen) {
714
+ $this->_order->setShippingDescription($typeChosen);
715
+ $this->_order->setShippingMethod($rate->getCarrier() . "_" . $rate->getMethod());
716
+ $current = $this->_order->getShippingAmount();
717
+ $this->_order->setShippingAmount($cost / 100);
718
+ $this->_order->setGrandTotal($this->_order->getGrandTotal() + $this->_order->getShippingAmount() - $current);
719
+ $this->_order->save();
720
+ }
721
+ }
722
+
723
+ }
724
+
725
+ } catch (Exception $e) {
726
+ Mage::logException("shipping info error: " . $e);
727
+ }
728
+
729
+ }
730
+
731
+ /** @return int return orderId by sessionId */
732
+ protected function getOrderIdBySessionId($sess)
733
+ {
734
+ $sessArr = explode("-", $sess);
735
+ if (count($sessArr) < 3)
736
+ return null;
737
+ return $sessArr[2];
738
+ }
739
+
740
+ /**
741
+ * Update order status
742
+ * @param string new order status
743
+ */
744
+ protected function updateOrderStatus($orderStatus)
745
+ {
746
+
747
+ $payment = $this->_order->getPayment();
748
+ $currentState = $payment->getAdditionalInformation('payu_order_status');
749
+
750
+ // change the order status if needed
751
+ if ($currentState != $orderStatus) {
752
+ try {
753
+ switch ($orderStatus) {
754
+
755
+ case PayU_Account_Model_Payment::ORDER_STATUS_CANCEL :
756
+ $this->updatePaymentStatusCancelled($payment);
757
+ break;
758
+
759
+ case PayU_Account_Model_Payment::ORDER_STATUS_REJECT :
760
+ $this->updatePaymentStatusDenied($payment);
761
+ break;
762
+
763
+ case PayU_Account_Model_Payment::ORDER_STATUS_SENT :
764
+ $this->updatePaymentStatusInProgress($payment);
765
+ break;
766
+
767
+ case PayU_Account_Model_Payment::ORDER_STATUS_PENDING :
768
+ $this->updatePaymentStatusPending($payment);
769
+ break;
770
+
771
+ default:
772
+ break;
773
+
774
+
775
+ }
776
+
777
+ $payment->setAdditionalInformation('payu_order_status', $orderStatus)->save();
778
+
779
+ } catch (Exception $e) {
780
+ Mage::logException($e);
781
+ }
782
+
783
+ }
784
+
785
+ }
786
+
787
+ /**
788
+ * Update payment status
789
+ * @param $paymentStatus
790
+ * @param $payUOrderStatus
791
+ */
792
+ protected function updatePaymentStatus($paymentStatus, $payUOrderStatus)
793
+ {
794
+
795
+ $payment = $this->_order->getPayment();
796
+ $currentState = $payment->getAdditionalInformation('payu_payment_status');
797
+
798
+ // change the payment status if needed
799
+ if ($currentState != $paymentStatus) {
800
+ try {
801
+ switch ($paymentStatus) {
802
+
803
+ case PayU_Account_Model_Payment::PAYMENT_STATUS_NEW :
804
+ $this->updatePaymentStatusNew($payment);
805
+ break;
806
+
807
+ case PayU_Account_Model_Payment::PAYMENT_STATUS_CANCEL :
808
+ $this->updatePaymentStatusCancelled($payment);
809
+ break;
810
+
811
+ case PayU_Account_Model_Payment::PAYMENT_STATUS_REJECT :
812
+ $this->updatePaymentStatusDenied($payment);
813
+ break;
814
+
815
+ case PayU_Account_Model_Payment::PAYMENT_STATUS_REJECT_DONE :
816
+ $this->updatePaymentStatusReturned($payment);
817
+ break;
818
+
819
+ case PayU_Account_Model_Payment::PAYMENT_STATUS_END :
820
+ $this->updatePaymentStatusCompleted($payment);
821
+ break;
822
+
823
+ case PayU_Account_Model_Payment::PAYMENT_STATUS_ERROR :
824
+ $this->updatePaymentStatusError($payment);
825
+ break;
826
+
827
+ default:
828
+ break;
829
+
830
+
831
+ }
832
+
833
+ // set current PayU status information and save
834
+ $payment->setAdditionalInformation('payu_payment_status', $paymentStatus)->save();
835
+
836
+ } catch (Exception $e) {
837
+ Mage::logException($e);
838
+ }
839
+ }
840
+
841
+ }
842
+
843
+
844
+ /**
845
+ * Get PayU session namespace
846
+ *
847
+ * @return PayU_Account_Model_Session
848
+ */
849
+ public function getSession()
850
+ {
851
+ return Mage::getSingleton('payu_account/session');
852
+ }
853
+
854
+ /**
855
+ * Get checkout session namespace
856
+ *
857
+ * @return Mage_Checkout_Model_Session
858
+ */
859
+ public function getCheckout()
860
+ {
861
+ return Mage::getSingleton('checkout/session');
862
+ }
863
+
864
+ /**
865
+ * Returns amount in PayU acceptable format
866
+ *
867
+ * @param $val
868
+ */
869
+ protected function toAmount($val)
870
+ {
871
+ return Mage::helper('payu_account')->toAmount($val);
872
+ }
873
+
874
+ /**
875
+ * Redirection url
876
+ *
877
+ * @return
878
+ */
879
+ public function getOrderPlaceRedirectUrl()
880
+ {
881
+ return Mage::getUrl('payu_account/payment/new', array('_secure' => true));
882
+ }
883
+
884
+ /**
885
+ * Get current quote
886
+ *
887
+ * @return Mage_Sales_Model_Quote
888
+ */
889
+ public function getQuote()
890
+ {
891
+ return $this->getCheckout()->getQuote();
892
+ }
893
+
894
+ /**
895
+ * Update payment status to new
896
+ * @param $payment
897
+ */
898
+ public function updatePaymentStatusNew($payment)
899
+ {
900
+ $transaction = $payment->setTransactionId($this->_transactionId);
901
+ $transaction->setPreparedMessage("PayU - " . Mage::helper('payu_account')->__('New transaction started.'));
902
+ $transaction->save();
903
+ }
904
+
905
+ /**
906
+ * Change the status to cancelled
907
+ * @param unknown_type $payment
908
+ */
909
+ public function updatePaymentStatusCancelled($payment)
910
+ {
911
+ $transaction = $payment->setTransactionId($this->_transactionId);
912
+
913
+ $payment->setPreparedMessage("PayU - " . Mage::helper('payu_account')->__('Transaction cancelled.'))
914
+ ->registerVoidNotification();
915
+
916
+ $comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true, "PayU - " . Mage::helper('payu_account')->__('The transaction has been cancelled.'), true)
917
+ ->sendOrderUpdateEmail()
918
+ ->save();
919
+
920
+ $transaction->setTxnType(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID);
921
+ $transaction->save();
922
+ }
923
+
924
+ /**
925
+ * Change the status to rejected
926
+ * @param $payment
927
+ */
928
+ public function updatePaymentStatusDenied($payment)
929
+ {
930
+ $transaction = $payment->setTransactionId($this->_transactionId);
931
+
932
+ $payment->setPreparedMessage("PayU - " . Mage::helper('payu_account')->__('Transaction rejected.'))
933
+ ->setParentTransactionId($this->_transactionId)
934
+ ->registerVoidNotification();
935
+
936
+ $comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true, "PayU - " . Mage::helper('payu_account')->__('The transaction has been rejected.'), true)
937
+ ->sendOrderUpdateEmail()
938
+ ->save();
939
+
940
+ $transaction->setTxnType(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID);
941
+ $transaction->save();
942
+ }
943
+
944
+ /**
945
+ * Change the status to in progress
946
+ * @param $payment
947
+ */
948
+ public function updatePaymentStatusInProgress($payment)
949
+ {
950
+ $transaction = $payment->setTransactionId($this->_transactionId);
951
+
952
+ $payment->setPreparedMessage("PayU - " . Mage::helper('payu_account')->__('The transaction is in progress.'))
953
+ ->setTransactionId($this->_transactionId) // this is the authorization transaction ID
954
+ ->registerVoidNotification();
955
+ }
956
+
957
+ /**
958
+ * Update payment status to pending
959
+ * @param $payment
960
+ */
961
+ public function updatePaymentStatusPending($payment)
962
+ {
963
+ $transaction = $payment->setTransactionId($this->_transactionId);
964
+
965
+
966
+ $payment->setPreparedMessage("PayU - " . Mage::helper('payu_account')->__('Transaction awaits approval.'))
967
+ ->setParentTransactionId($this->_transactionId) // this is the authorization transaction ID
968
+ ->registerVoidNotification();
969
+
970
+ $comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true, "PayU - " . Mage::helper('payu_account')->__('The transaction is pending.'), false)
971
+ ->save();
972
+
973
+ }
974
+
975
+
976
+ /**
977
+ * Update payment status to returned and holded
978
+ * @param $payment
979
+ */
980
+ public function updatePaymentStatusReturned($payment)
981
+ {
982
+ $transaction = $payment->setTransactionId($this->_transactionId);
983
+
984
+ $payment->setPreparedMessage("PayU - " . Mage::helper('payu_account')->__('Transaction returned.'))
985
+ ->registerVoidNotification();
986
+
987
+ $comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true, "PayU - " . Mage::helper('payu_account')->__('The transaction has been returned.'), true)
988
+ ->sendOrderUpdateEmail()
989
+ ->save();
990
+ }
991
+
992
+
993
+ /**
994
+ * Update payment status to complete
995
+ * @param $payment
996
+ */
997
+ public function updatePaymentStatusCompleted($payment)
998
+ {
999
+
1000
+ $transaction = $payment->setTransactionId($this->_transactionId);
1001
+ $transaction->setPreparedMessage("PayU - " . Mage::helper('payu_account')->__('The transaction completed successfully.'));
1002
+
1003
+ $payment->setIsTransactionApproved(true);
1004
+ $payment->setIsTransactionClosed(true);
1005
+
1006
+ $comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, "PayU - " . Mage::helper('payu_account')->__('The transaction completed successfully.'), true)
1007
+ ->sendOrderUpdateEmail(true, "PayU - " . Mage::helper('payu_account')->__('Thank you.') . " " . Mage::helper('payu_account')->__('The transaction completed successfully.'))
1008
+ ->save();
1009
+ $transaction->save();
1010
+ }
1011
+
1012
+ /**
1013
+ * Update payment status to error
1014
+ * @param $payment
1015
+ */
1016
+ public function updatePaymentStatusError($payment)
1017
+ {
1018
+ $transaction = $payment->setTransactionId($this->_transactionId);
1019
+
1020
+ $payment->setPreparedMessage('Transakcja błędna.')
1021
+ ->setParentTransactionId($this->_transactionId)
1022
+ ->registerVoidNotification();
1023
+ $comment = $this->_order->setState(Mage_Sales_Model_Order::STATE_HOLDED, true, "PayU - " . Mage::helper('payu_account')->__('The transaction is incorrect.'))
1024
+ ->sendOrderUpdateEmail(true, "PayU - " . Mage::helper('payu_account')->__('The transaction is incorrect.'))
1025
+ ->save();
1026
+ }
1027
+
1028
+ /** calculating the tax rate */
1029
+ protected function calculateTaxRate()
1030
+ {
1031
+ return ($this->_order->getShippingAmount() > 0) ? $this->_order->getShippingTaxAmount() / $this->_order->getShippingAmount() : 0.0;
1032
+ }
1033
+
1034
+ /** Recalculating the costs of shipping */
1035
+ public function shippingCostRetrieve()
1036
+ {
1037
+
1038
+ $document = Mage::app()->getRequest()->getPost('DOCUMENT');
1039
+
1040
+ $result = OpenPayU_Order::consumeMessage($document);
1041
+
1042
+ $cc = $result->getCountryCode();
1043
+ $rspId = $result->getReqId();
1044
+
1045
+ if ($result->getMessage() == 'ShippingCostRetrieveRequest') {
1046
+
1047
+ /** assigning the order */
1048
+ $this->setOrderBySessionId($result->getSessionId());
1049
+
1050
+ /** assigning a new country */
1051
+ $this->_order->getShippingAddress()->setCountryId($cc);
1052
+
1053
+
1054
+ $quote = Mage::getModel('sales/quote')->load($this->_order->getQuoteId());
1055
+ $address = $quote->getShippingAddress();
1056
+ $address->setCountryId($cc);
1057
+
1058
+ $shipping = Mage::getModel('shipping/shipping');
1059
+ $shippingRates = $shipping->collectRatesByAddress($address)->getResult();
1060
+
1061
+ $shippingCostList = array();
1062
+
1063
+
1064
+ //check if visible items equal allitems
1065
+ $factor = count($this->_order->getAllItems()) / count($this->_order->getAllVisibleItems());
1066
+
1067
+ foreach ($shippingRates->getAllRates() as $rate) {
1068
+
1069
+
1070
+ $shippingCostList[] = array(
1071
+ 'ShippingCost' => array(
1072
+ 'Type' => $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle(),
1073
+ 'CountryCode' => $this->_order->getShippingAddress()->getCountry(),
1074
+ 'Price' => array(
1075
+ 'Gross' => $this->toAmount($rate->getPrice() / $factor),
1076
+ 'Net' => $this->toAmount($rate->getPrice() / $factor),
1077
+ 'Tax' => $this->toAmount($this->_order->getShippingTaxAmount()),
1078
+ 'TaxRate' => $this->toAmount($this->calculateTaxRate()),
1079
+ 'CurrencyCode' => $this->_order->getOrderCurrencyCode()
1080
+ )
1081
+ )
1082
+ );
1083
+
1084
+ }
1085
+
1086
+ $arr = array(
1087
+ 'CountryCode' => $cc,
1088
+ 'ShipToOtherCountry' => 'true',
1089
+ 'ShippingCostList' => $shippingCostList
1090
+ );
1091
+
1092
+ $this->_order->save();
1093
+
1094
+ $xml = OpenPayU::buildShippingCostRetrieveResponse($arr, $rspId, $cc);
1095
+
1096
+ header("Content-type: text/xml");
1097
+ echo $xml;
1098
+ }
1099
+
1100
+ }
1101
+
1102
+
1103
+ /**
1104
+ * Get PayU -configuration
1105
+ *
1106
+ * @return PayU_Account_Model_Config
1107
+ */
1108
+ protected function getConfig()
1109
+ {
1110
+ return Mage::getModel('payu_account/config');
1111
+ }
1112
+
1113
+
1114
+ /** Initialize PayU configuration */
1115
+ protected function initializeOpenPayUConfiguration()
1116
+ {
1117
+
1118
+ $this->_config = $this->getConfig();
1119
+
1120
+ $this->_myUrl = $this->_config->getBaseUrl();
1121
+
1122
+ OpenPayU_Configuration::setEnvironment($this->_config->getEnvironment());
1123
+ OpenPayU_Configuration::setMerchantPosId($this->_config->getMerchantPosId());
1124
+ OpenPayU_Configuration::setPosAuthKey($this->_config->getPosAuthKey());
1125
+ OpenPayU_Configuration::setClientId($this->_config->getClientId());
1126
+ OpenPayU_Configuration::setClientSecret($this->_config->getClientSecret());
1127
+ OpenPayU_Configuration::setSignatureKey($this->_config->getSignatureKey());
1128
+
1129
+
1130
+ }
1131
+
1132
+ }
app/code/local/PayU/Account/Model/Session.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Session Model
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+ class PayU_Account_Model_Session extends Mage_Core_Model_Session_Abstract
15
+ {
16
+ public function __construct()
17
+ {
18
+ $this->init('payu_account');
19
+ }
20
+ }
app/code/local/PayU/Account/Model/Thumbnail.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Thumbnail Model
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+ class PayU_Account_Model_Thumbnail
15
+ {
16
+ public function toOptionArray()
17
+ {
18
+
19
+ $thumbnails = Mage::getModel('payu_account/config')->getGoods('media_logos');
20
+
21
+ $options = array();
22
+
23
+ foreach ($thumbnails as $label) {
24
+ $options[] = array(
25
+ 'value' => $label,
26
+ 'label' => $label
27
+ );
28
+ }
29
+ return $options;
30
+ }
31
+ }
app/code/local/PayU/Account/Model/ValidityTime.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ /**
5
+ * ver. 0.1.6.1
6
+ * PayU Validity Time Model
7
+ *
8
+ * @copyright Copyright (c) 2011-2012 PayU
9
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
10
+ * http://www.payu.com
11
+ * http://www.openpayu.com
12
+ * http://twitter.com/openpayu
13
+ */
14
+
15
+
16
+ class PayU_Account_Model_ValidityTime
17
+ {
18
+
19
+ public function toOptionArray() {
20
+
21
+ $minutes = array(
22
+
23
+ '1440' => '1440 min (24h)',
24
+ '720' => '720 min (12h)',
25
+ '360' => '360 min (6h)',
26
+ '60' => '60 min (1h)',
27
+ '30' => '30 min',
28
+
29
+ );
30
+
31
+ $options = array();
32
+
33
+ foreach ($minutes as $code => $label) {
34
+ $options[] = array(
35
+ 'value' => $code,
36
+ 'label' => $label
37
+ );
38
+ }
39
+
40
+ return $options;
41
+
42
+ }
43
+ }
app/code/local/PayU/Account/controllers/Adminhtml/Sales/OrderController.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Adminhtml Sales Order Controller
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+ include_once("Mage/Adminhtml/controllers/Sales/OrderController.php");
15
+
16
+ class PayU_Account_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController{
17
+
18
+
19
+ /**
20
+ * Cancel
21
+ */
22
+ public function cancelPayUOrderAction(){
23
+
24
+ $order = Mage::getModel('sales/order')->load(Mage::app()->getRequest()->getParam('order_id'));
25
+
26
+ $payu = Mage::getModel('payu_account/payment');
27
+
28
+ $session = Mage::getSingleton('adminhtml/session');
29
+
30
+ if($payu->cancelOrder($order)->getSuccess()){
31
+ $session->addSuccess( Mage::helper('payu_account')->__('The order has been cancelled in PayU.') );
32
+ }else{
33
+ $session->addError( Mage::helper('payu_account')->__('There was a problem while cancelling the order in PayU.') );
34
+ }
35
+ $this->_redirect('*/sales_order/view', array('order_id' => $order->getId()));
36
+
37
+ }
38
+
39
+ /**
40
+ * Reject
41
+ */
42
+ public function rejectPayUOrderAction(){
43
+
44
+ $order = Mage::getModel('sales/order')->load(Mage::app()->getRequest()->getParam('order_id'));
45
+
46
+ $payu = Mage::getModel('payu_account/payment');
47
+
48
+ $session = Mage::getSingleton('adminhtml/session');
49
+
50
+ if($payu->rejectOrder($order)->getSuccess()){
51
+ $session->addSuccess( Mage::helper('payu_account')->__('The order has been rejected in PayU.') );
52
+ }else{
53
+ $session->addError( Mage::helper('payu_account')->__('There was a problem while rejecting the order in PayU.') );
54
+ }
55
+ $this->_redirect('*/sales_order/view', array('order_id' => $order->getId()));
56
+
57
+ }
58
+
59
+ /**
60
+ *
61
+ */
62
+ public function completePayUOrderAction(){
63
+ $order = Mage::getModel('sales/order')->load(Mage::app()->getRequest()->getParam('order_id'));
64
+
65
+ $payu = Mage::getModel('payu_account/payment');
66
+ $session = Mage::getSingleton('adminhtml/session');
67
+
68
+ if($payu->completeOrder($order)->getSuccess()){
69
+ $session->addSuccess(Mage::helper('payu_account')->__('The order is completing in PayU, please wait while status changes.'));
70
+ }else{
71
+ $session->addError(Mage::helper('payu_account')->__('There was a problem while completing the order in PayU.'));
72
+ }
73
+ $this->_redirect('*/sales_order/view', array('order_id' => $order->getId()));
74
+
75
+ }
76
+
77
+ }
app/code/local/PayU/Account/controllers/Checkout/CartController.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Cart Controller
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+ require_once 'Mage/Checkout/controllers/CartController.php';
15
+
16
+ class PayU_Account_Checkout_CartController extends Mage_Checkout_CartController
17
+ {
18
+
19
+ public function indexAction() {
20
+ $this->loadLayout();
21
+ $this->renderLayout();
22
+ }
23
+ }
app/code/local/PayU/Account/controllers/PaymentController.php ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ver. 0.1.6.1
5
+ * PayU Standard Payment Controller
6
+ *
7
+ * @copyright Copyright (c) 2011-2012 PayU
8
+ * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ * http://www.payu.com
10
+ * http://www.openpayu.com
11
+ * http://twitter.com/openpayu
12
+ */
13
+
14
+
15
+ class PayU_Account_PaymentController extends Mage_Core_Controller_Front_Action {
16
+
17
+ protected $_session = null;
18
+ protected $_order = null;
19
+ protected $_payment = null;
20
+
21
+ protected $_allShippingRates = null;
22
+
23
+ /**
24
+ * Initializes new One Step Checkout
25
+ */
26
+ public function newOneStepAction() {
27
+
28
+ $this->setSession();
29
+ $this->_order = Mage::getModel('payu_account/payment')->newOneStep();
30
+ $this->_redirect('payu_account/payment/new');
31
+
32
+ }
33
+
34
+ /**
35
+ * Create invoice
36
+ *
37
+ * @return Mage_Sales_Model_Order_Invoice
38
+ */
39
+ protected function _initInvoice()
40
+ {
41
+ $items = array();
42
+ foreach ($this->_order->getAllItems() as $item) {
43
+ $items[$item->getId()] = $item->getQtyOrdered();
44
+ }
45
+ /* @var $invoice Mage_Sales_Model_Service_Order */
46
+ $invoice = Mage::getModel('sales/service_order', $this->_order)->prepareInvoice($items);
47
+ $invoice->setEmailSent(true)->register();
48
+
49
+ Mage::register('current_invoice', $invoice);
50
+ return $invoice;
51
+ }
52
+
53
+ /**
54
+ * Initializes new One Page payment
55
+ */
56
+ public function newAction() {
57
+ $this->setSession();
58
+ $this->setOrder();
59
+ $this->forceNewOrderStatus();
60
+ $this->setPayment(true);
61
+ $this->_allShippingRates = Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->getAllShippingRates();
62
+ $this->getResponse()->setBody($this->getLayout()->createBlock('payu_account/redirect')->setAllShippingMethods($this->_allShippingRates)->setOrder($this->_order)->toHtml());
63
+ }
64
+
65
+ /**
66
+ * Before PayU summary action
67
+ */
68
+ public function beforeSummaryAction(){
69
+ $this->setSession();
70
+ $this->setOrder();
71
+ $this->setPayment(true);
72
+ $this->getResponse()->setBody($this->getLayout()->createBlock('payu_account/beforeSummary')->setOrder($this->_order)->toHtml());
73
+ }
74
+
75
+ /**
76
+ * Processes PayU OrderNotifyRequest
77
+ */
78
+ public function orderNotifyRequestAction(){
79
+
80
+ try {
81
+ Mage::getModel('payu_account/payment')->orderNotifyRequest();
82
+ } catch (Exception $e) {
83
+ Mage::logException($e);
84
+ }
85
+
86
+
87
+ }
88
+
89
+ /**
90
+ * Shipping cost retrieve
91
+ *
92
+ * @todo not functioning yet
93
+ */
94
+ public function shippingCostRetrieveAction(){
95
+ $this->setSession();
96
+ $this->setOrder();
97
+ try {
98
+ Mage::getModel('payu_account/payment')->shippingCostRetrieve();
99
+ } catch (Exception $e) {
100
+ Mage::logException($e);
101
+ }
102
+
103
+ }
104
+
105
+ /**
106
+ * Complete payment action
107
+ */
108
+ public function completePaymentAction(){
109
+
110
+ $this->setSession();
111
+ $this->setOrder();
112
+ $this->setPayment();
113
+ //if(!Mage::getModel('payu/config')->getIsSelfReturnEnabled())
114
+ // Mage::getModel('payu/payment')->completePayment();
115
+ if (defined('Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW')) {
116
+ $this->_order->setState(Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW, true)->save();
117
+ } else {
118
+ $this->_order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
119
+ }
120
+ Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
121
+ Mage::getSingleton('checkout/session')->setSuccess( Mage::helper('payu_account')->__('Thank you.') );
122
+ $this->_redirect('checkout/onepage/success',array('_secure' => true));
123
+
124
+ }
125
+
126
+ /**
127
+ * Cancel payment action
128
+ *
129
+ * @todo not yet implemented
130
+ */
131
+ public function cancelPaymentAction(){
132
+ Mage::getSingleton('checkout/session')->setMessage( Mage::helper('payu_account')->__('The payment has been cancelled.') );
133
+ $this->_redirect('checkout/cart', array('_secure'=>true));
134
+ }
135
+
136
+
137
+
138
+ /**
139
+ * Error payment action
140
+ *
141
+ * @todo not yet implemented
142
+ */
143
+ public function errorAction() {
144
+ $this->_redirect('checkout/onepage/failure', array('_secure'=>true));
145
+ }
146
+
147
+ /** Setting checkout session */
148
+ private function setSession() {
149
+ $this->_session = Mage::getSingleton('checkout/session');
150
+ }
151
+
152
+ /** Setting the order */
153
+ private function setOrder() {
154
+ $id = $this->_session->getLastRealOrderId();
155
+ $this->_order = Mage::getModel('sales/order')->loadByIncrementId($id);
156
+ }
157
+
158
+ /** Setting the new order */
159
+ private function setNewOrder() {
160
+ $this->_order = Mage::getModel('payu_account/payment')->prepareNewOrderByCart();
161
+ }
162
+
163
+ /**
164
+ * Setting the payment
165
+ *
166
+ * @param boolean
167
+ */
168
+ private function setPayment($is_order_new = false) {
169
+ $this->_payment = $this->_order->getPayment();
170
+ }
171
+
172
+ /**
173
+ * Check if the order is new
174
+ *
175
+ * @return boolean
176
+ */
177
+ private function isNewOrder() {
178
+ return (Mage::getSingleton('checkout/session')->getLastRealOrderId() == $this->_order->getRealOrderId());
179
+ }
180
+
181
+
182
+ /** Forcing the order to be new */
183
+ private function forceNewOrderStatus() {
184
+ if ($this->isNewOrder()) {
185
+ $status = $this->_order->getStatus();
186
+ $state = $this->_order->getState();
187
+ if ($state == Mage_Sales_Model_Order::STATE_NEW && $status != Mage::getStoreConfig("payment/payu_account/order_status")) {
188
+ $this->_order->setState(Mage::getStoreConfig("payment/payu_account/order_status"), true)
189
+ ->save();
190
+ }
191
+ }
192
+ }
193
+
194
+ }
app/code/local/PayU/Account/etc/config.xml ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+
4
+ <modules>
5
+ <PayU_Account>
6
+ <version>0.1.6.1</version>
7
+ </PayU_Account>
8
+ </modules>
9
+
10
+ <adminhtml>
11
+ <translate>
12
+ <modules>
13
+ <PayU_Account>
14
+ <files>
15
+ <default>PayU_Account.csv</default>
16
+ </files>
17
+ </PayU_Account>
18
+ </modules>
19
+ </translate>
20
+ </adminhtml>
21
+
22
+ <admin>
23
+ <routers>
24
+ <adminhtml>
25
+ <args>
26
+ <modules>
27
+ <PayU_Account before="Mage_Adminhtml">PayU_Account_Adminhtml</PayU_Account>
28
+ </modules>
29
+ </args>
30
+ </adminhtml>
31
+ </routers>
32
+ </admin>
33
+
34
+ <frontend>
35
+ <routers>
36
+ <checkout>
37
+ <args>
38
+ <modules>
39
+ <PayU_Account before="Mage_Checkout">PayU_Account_Checkout</PayU_Account>
40
+ </modules>
41
+ </args>
42
+ </checkout>
43
+ <PayU>
44
+ <use>standard</use>
45
+ <args>
46
+ <module>PayU_Account</module>
47
+ <frontName>payu_account</frontName>
48
+ </args>
49
+ </PayU>
50
+ </routers>
51
+ <layout>
52
+ <updates>
53
+ <payu_account module="PayU_Account">
54
+ <file>payu_account.xml</file>
55
+ </payu_account>
56
+ </updates>
57
+ </layout>
58
+ <translate>
59
+ <modules>
60
+ <PayU_Account>
61
+ <files>
62
+ <default>PayU_Account.csv</default>
63
+ </files>
64
+ </PayU_Account>
65
+ </modules>
66
+ </translate>
67
+ </frontend>
68
+
69
+ <global>
70
+ <blocks>
71
+ <payu_account>
72
+ <class>PayU_Account_Block</class>
73
+ </payu_account>
74
+ <adminhtml>
75
+ <rewrite>
76
+ <sales_order_view>PayU_Account_Block_Adminhtml_Sales_Order_View</sales_order_view>
77
+ </rewrite>
78
+ </adminhtml>
79
+ </blocks>
80
+ <models>
81
+ <payu_account>
82
+ <class>PayU_Account_Model</class>
83
+ </payu_account>
84
+ </models>
85
+ <helpers>
86
+ <payu_account>
87
+ <class>PayU_Account_Helper</class>
88
+ </payu_account>
89
+ </helpers>
90
+ <resources>
91
+
92
+ <payu_account_setup>
93
+ <setup>
94
+ <module>PayU_Account</module>
95
+ </setup>
96
+ <connection>
97
+ <use>core_setup</use>
98
+ </connection>
99
+ </payu_account_setup>
100
+ <payu_account_write>
101
+ <connection>
102
+ <use>core_write</use>
103
+ </connection>
104
+ </payu_account_write>
105
+ <payu_account_read>
106
+ <connection>
107
+ <use>core_read</use>
108
+ </connection>
109
+ </payu_account_read>
110
+ </resources>
111
+ </global>
112
+
113
+ <default>
114
+ <payment>
115
+ <payu_account>
116
+ <active>1</active>
117
+ <model>payu_account/payment</model>
118
+ <order_status>pending</order_status>
119
+ <payment_action>authorize</payment_action>
120
+ <allowspecific>0</allowspecific>
121
+ </payu_account>
122
+ </payment>
123
+ </default>
124
+ </config>
app/code/local/PayU/Account/etc/system.xml ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <payu_account translate="label" module="paygate">
7
+ <label>PayU account</label>
8
+ <sort_order>670</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <fields>
13
+
14
+ <header1 translate="label">
15
+ <label>Main parameters</label>
16
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
17
+ <sort_order>0</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>1</show_in_store>
21
+ </header1>
22
+
23
+ <active translate="label">
24
+ <label>Enabled</label>
25
+ <frontend_type>select</frontend_type>
26
+ <source_model>adminhtml/system_config_source_yesno</source_model>
27
+ <sort_order>1</sort_order>
28
+ <show_in_default>1</show_in_default>
29
+ <show_in_website>1</show_in_website>
30
+ <show_in_store>1</show_in_store>
31
+ </active>
32
+
33
+ <onestepcheckoutenabled translate="label">
34
+ <label>Is One Step Checkout Enabled</label>
35
+ <frontend_type>select</frontend_type>
36
+ <source_model>adminhtml/system_config_source_yesno</source_model>
37
+ <sort_order>2</sort_order>
38
+ <show_in_default>1</show_in_default>
39
+ <show_in_website>1</show_in_website>
40
+ <show_in_store>1</show_in_store>
41
+ </onestepcheckoutenabled>
42
+
43
+ <selfreturn translate="label">
44
+ <label>Is self-return enabled</label>
45
+ <frontend_type>select</frontend_type>
46
+ <source_model>adminhtml/system_config_source_yesno</source_model>
47
+ <sort_order>3</sort_order>
48
+ <show_in_default>1</show_in_default>
49
+ <show_in_website>1</show_in_website>
50
+ <show_in_store>1</show_in_store>
51
+ </selfreturn>
52
+
53
+ <order_status translate="label">
54
+ <label>New order status</label>
55
+ <frontend_type>select</frontend_type>
56
+ <source_model>adminhtml/system_config_source_order_status_processing</source_model>
57
+ <sort_order>4</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>1</show_in_website>
60
+ <show_in_store>1</show_in_store>
61
+ </order_status>
62
+
63
+ <validity_time translate="label comment">
64
+ <label>Order validity time in PayU</label>
65
+ <frontend_type>select</frontend_type>
66
+ <source_model>payu_account/validityTime</source_model>
67
+ <sort_order>5</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>1</show_in_website>
70
+ <show_in_store>1</show_in_store>
71
+ </validity_time>
72
+
73
+ <environment translate="label">
74
+ <label>Active environment</label>
75
+ <frontend_type>select</frontend_type>
76
+ <source_model>payu_account/environment</source_model>
77
+ <sort_order>6</sort_order>
78
+ <show_in_default>1</show_in_default>
79
+ <show_in_website>1</show_in_website>
80
+ <show_in_store>1</show_in_store>
81
+ </environment>
82
+
83
+ <header2 translate="label">
84
+ <label>Parameters of production environment</label>
85
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
86
+ <sort_order>7</sort_order>
87
+ <show_in_default>1</show_in_default>
88
+ <show_in_website>1</show_in_website>
89
+ <show_in_store>1</show_in_store>
90
+ </header2>
91
+
92
+ <oauth_client_name translate="label">
93
+ <label>OAuth Protocol - client_id (POS ID)</label>
94
+ <frontend_type>text</frontend_type>
95
+ <sort_order>8</sort_order>
96
+ <show_in_default>1</show_in_default>
97
+ <show_in_website>1</show_in_website>
98
+ <show_in_store>1</show_in_store>
99
+ </oauth_client_name>
100
+
101
+ <oauth_client_secret translate="label">
102
+ <label>OAuth Protocol - client_secret</label>
103
+ <frontend_type>text</frontend_type>
104
+ <sort_order>9</sort_order>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>1</show_in_website>
107
+ <show_in_store>1</show_in_store>
108
+ </oauth_client_secret>
109
+
110
+ <signature_key translate="label">
111
+ <label>Symmetrical key for encrypting communication</label>
112
+ <frontend_type>text</frontend_type>
113
+ <sort_order>11</sort_order>
114
+ <show_in_default>1</show_in_default>
115
+ <show_in_website>1</show_in_website>
116
+ <show_in_store>1</show_in_store>
117
+ </signature_key>
118
+
119
+ <pos_auth_key translate="label">
120
+ <label>Pos Auth Key</label>
121
+ <frontend_type>text</frontend_type>
122
+ <sort_order>10</sort_order>
123
+ <show_in_default>1</show_in_default>
124
+ <show_in_website>1</show_in_website>
125
+ <show_in_store>1</show_in_store>
126
+ </pos_auth_key>
127
+
128
+ <header3 translate="label">
129
+ <label>Parameters of test environment (Sandbox)</label>
130
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
131
+ <sort_order>12</sort_order>
132
+ <show_in_default>1</show_in_default>
133
+ <show_in_website>1</show_in_website>
134
+ <show_in_store>1</show_in_store>
135
+ </header3>
136
+
137
+ <sandbox_oauth_client_name translate="label">
138
+ <label>OAuth Protocol - client_id (POS ID)</label>
139
+ <frontend_type>text</frontend_type>
140
+ <sort_order>14</sort_order>
141
+ <show_in_default>1</show_in_default>
142
+ <show_in_website>1</show_in_website>
143
+ <show_in_store>1</show_in_store>
144
+ </sandbox_oauth_client_name>
145
+
146
+ <sandbox_oauth_client_secret translate="label">
147
+ <label>OAuth Protocol - client_secret</label>
148
+ <frontend_type>text</frontend_type>
149
+ <sort_order>15</sort_order>
150
+ <show_in_default>1</show_in_default>
151
+ <show_in_website>1</show_in_website>
152
+ <show_in_store>1</show_in_store>
153
+ </sandbox_oauth_client_secret>
154
+
155
+ <sandbox_signature_key translate="label">
156
+ <label>Symmetrical key for encrypting communication</label>
157
+ <frontend_type>text</frontend_type>
158
+ <sort_order>17</sort_order>
159
+ <show_in_default>1</show_in_default>
160
+ <show_in_website>1</show_in_website>
161
+ <show_in_store>1</show_in_store>
162
+ </sandbox_signature_key>
163
+
164
+ <sandbox_pos_auth_key translate="label">
165
+ <label>Pos Auth Key</label>
166
+ <frontend_type>text</frontend_type>
167
+ <sort_order>16</sort_order>
168
+ <show_in_default>1</show_in_default>
169
+ <show_in_website>1</show_in_website>
170
+ <show_in_store>1</show_in_store>
171
+ </sandbox_pos_auth_key>
172
+
173
+ <header4 translate="label">
174
+ <label>Settings of external resources</label>
175
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
176
+ <sort_order>18</sort_order>
177
+ <show_in_default>1</show_in_default>
178
+ <show_in_website>1</show_in_website>
179
+ <show_in_store>1</show_in_store>
180
+ </header4>
181
+
182
+ <payubutton translate="label">
183
+ <label>One Step Checkout button</label>
184
+ <frontend_type>select</frontend_type>
185
+ <source_model>payu_account/button</source_model>
186
+ <sort_order>19</sort_order>
187
+ <show_in_default>1</show_in_default>
188
+ <show_in_website>1</show_in_website>
189
+ <show_in_store>1</show_in_store>
190
+ </payubutton>
191
+
192
+ <payuthumbnail translate="label">
193
+ <label>Small logo (visible when choosing the payment method)</label>
194
+ <frontend_type>select</frontend_type>
195
+ <source_model>payu_account/thumbnail</source_model>
196
+ <sort_order>20</sort_order>
197
+ <show_in_default>1</show_in_default>
198
+ <show_in_website>1</show_in_website>
199
+ <show_in_store>1</show_in_store>
200
+ </payuthumbnail>
201
+
202
+ <payuadvertisement translate="label">
203
+ <label>PayU Advertisement</label>
204
+ <source_model>payu_account/advertisement</source_model>
205
+ <frontend_type>select</frontend_type>
206
+ <sort_order>21</sort_order>
207
+ <show_in_default>1</show_in_default>
208
+ <show_in_website>1</show_in_website>
209
+ <show_in_store>1</show_in_store>
210
+ </payuadvertisement>
211
+
212
+ <header5 translate="label">
213
+ <label>The PayU plugin latest version information</label>
214
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
215
+ <sort_order>22</sort_order>
216
+ <show_in_default>1</show_in_default>
217
+ <show_in_website>0</show_in_website>
218
+ <show_in_store>0</show_in_store>
219
+ </header5>
220
+
221
+ <payuupdate translate="label">
222
+ <label></label>
223
+ <frontend_type>multiline</frontend_type>
224
+ <frontend_model>payu_account/updateInfo</frontend_model>
225
+ <sort_order>23</sort_order>
226
+ <show_in_default>1</show_in_default>
227
+ <show_in_website>0</show_in_website>
228
+ <show_in_store>0</show_in_store>
229
+ </payuupdate>
230
+
231
+ </fields>
232
+ </payu_account>
233
+ </groups>
234
+ </payment>
235
+ </sections>
236
+ </config>
app/design/frontend/base/default/layout/payu_account.xml ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+
4
+ <catalog_product_view>
5
+ <!--<reference name="product.info.addtocart">
6
+ <block type="payu_account/onestep_checkout" name="payu_account.button" template="payu_account/onestep/checkout.phtml">
7
+ <action method="setIsInCatalogProduct"><value>1</value></action>
8
+ </block>
9
+ </reference>-->
10
+ <reference name="right">
11
+ <block type="payu_account/advertisement" name="payu_account.advertisement" template="payu_account/advertisement.phtml">
12
+ </block>
13
+ </reference>
14
+ </catalog_product_view>
15
+
16
+ <checkout_cart_index>
17
+ <reference name="checkout.cart.top_methods">
18
+ <block type="payu_account/onestep_checkout" name="checkout.cart.methods.payu_express.top" before="-" template="payu_account/onestep/checkout.phtml">
19
+ <action method="setIsQuoteAllowed"><value>1</value></action>
20
+ </block>
21
+ </reference>
22
+
23
+ <reference name="checkout.cart.methods">
24
+ <block type="payu_account/onestep_checkout" name="checkout.cart.methods.payu_express.bottom" before="-" template="payu_account/onestep/checkout.phtml">
25
+ <action method="setIsQuoteAllowed"><value>1</value></action>
26
+ </block>
27
+ </reference>
28
+
29
+ <update handle="SHORTCUT_popup" />
30
+ </checkout_cart_index>
31
+
32
+ <catalog_category_default>
33
+ <update handle="SHORTCUT_popup" />
34
+ <reference name="right">
35
+ <block type="payu_account/advertisement" name="payu_account.partner.right.advertisement" template="payu_account/advertisement.phtml"/>
36
+ </reference>
37
+ </catalog_category_default>
38
+
39
+ <catalog_category_layered>
40
+ <update handle="SHORTCUT_popup" />
41
+ <reference name="right">
42
+ <block type="payu_account/advertisement" name="payu_account.partner.right.advertisement" template="payu_account/advertisement.phtml"/>
43
+ </reference>
44
+ </catalog_category_layered>
45
+
46
+ <catalog_product_compare_index>
47
+ <update handle="SHORTCUT_popup" />
48
+ </catalog_product_compare_index>
49
+
50
+ <catalogsearch_result_index>
51
+ <update handle="SHORTCUT_popup" />
52
+ </catalogsearch_result_index>
53
+
54
+ <catalogsearch_advanced_result>
55
+ <update handle="SHORTCUT_popup" />
56
+ </catalogsearch_advanced_result>
57
+
58
+ <tag_product_list>
59
+ <update handle="SHORTCUT_popup" />
60
+ </tag_product_list>
61
+ <tag_customer_view>
62
+ <update handle="SHORTCUT_popup" />
63
+ </tag_customer_view>
64
+
65
+ <wishlist_index_index>
66
+ <update handle="SHORTCUT_popup" />
67
+ </wishlist_index_index>
68
+ <review_product_list>
69
+ <update handle="SHORTCUT_popup" />
70
+ </review_product_list>
71
+
72
+ <checkout_onepage_success>
73
+ <update handle="SHORTCUT_popup" />
74
+ </checkout_onepage_success>
75
+ <checkout_onepage_failure>
76
+ <update handle="SHORTCUT_popup" />
77
+ </checkout_onepage_failure>
78
+
79
+ <cms_index_index>
80
+ <reference name="right">
81
+ <block type="payu_account/advertisement" name="payu_account.partner.right.advertisement" template="payu_account/advertisement.phtml"/>
82
+ </reference>
83
+ </cms_index_index>
84
+
85
+ <default>
86
+ <reference name="topCart.extra_actions">
87
+ <block type="payu_account/onestep_checkout" name="payu_account.partner.top_cart.shortcut" template="payu_account/onestep/checkout.phtml"/>
88
+ </reference>
89
+ <reference name="cart_sidebar.extra_actions">
90
+ <block type="payu_account/onestep_checkout" name="payu_account.partner.cart_sidebar.shortcut" template="payu_account/onestep/checkout.phtml"/>
91
+ </reference>
92
+ </default>
93
+
94
+ <SHORTCUT_popup>
95
+ <reference name="product.tooltip">
96
+ <block type="page/html_wrapper" name="product.info.addtocart.payu_account.wrapper" translate="label">
97
+ <block type="payu_account/onestep_checkout" name="product.info.addtocart.payu" template="payu_account/onestep/checkout.phtml">
98
+ <action method="setIsInCatalogProduct"><value>1</value></action>
99
+ <action method="setShowOrPosition"><value>after</value></action>
100
+ </block>
101
+ </block>
102
+ </reference>
103
+ </SHORTCUT_popup>
104
+
105
+
106
+ </layout>
app/design/frontend/base/default/template/payu_account/advertisement.phtml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <div class="payu-advertisement" style="text-align:center;">
2
+ <a href="<?php echo $this->getRedirectUrl();?>" target="_blank">
3
+ <img src="<?php echo $this->getAdvertisementSrc();?>" alt="PayU We Accept" /></a>
4
+ </div>
app/design/frontend/base/default/template/payu_account/form.phtml ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <ul class="form-list" id="payment_form_<?php echo $this->getMethodCode() ?>" style="display:none;">
2
+ <li class="form-alt"><?php echo Mage::helper('payu_account')->__('You will be redirected to PayU after submitting the order.'); ?></li>
3
+ </ul>
app/design/frontend/base/default/template/payu_account/info/payu_account.phtml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php echo $this->getMethod()->getTitle() ?>
28
+ <?php if($this->getInfo()->getAdditionalData()): ?>
29
+ <?php if($this->getPayableTo()): ?><br /><?php echo Mage::helper('payment')->__('Make Check payable to: %s', $this->htmlEscape($this->getPayableTo())) ?><?php endif; ?>
30
+ <?php if($this->getMailingAddress()): ?>
31
+ <label><?php echo Mage::helper('payment')->__('Send Check to:') ?></label>
32
+ <div class="checkmo-mailing-address">
33
+ <?php echo nl2br($this->htmlEscape($this->getMailingAddress())) ?>
34
+ </div>
35
+ <?php endif; ?>
36
+ <?php endif; ?>
app/design/frontend/base/default/template/payu_account/onestep/checkout.phtml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php if($this->getIsOneStepCheckoutEnabled()): ?>
2
+ <p class="payu-button" style="margin:5px 0 5px 0;">
3
+ <a onclick="<?php if(!$this->getIsOneStepCheckoutAvailable()): ?>alert('<?php echo $this->__('This feature is currently not available.'); ?>');return false;<?php endif; ?>" href="<?php echo $this->getCheckoutUrl();?>"><img src="<?php echo $this->getButtonSrc(); ?>" alt="PayU One Step Checkout" /></a>
4
+ </p>
5
+ <?php endif; ?>
app/etc/modules/PayU_Account.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <PayU_Account>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <depends>
8
+ <Mage_Payment />
9
+ </depends>
10
+ </PayU_Account>
11
+ </modules>
12
+ </config>
app/locale/pl_PL/PayU_Account.csv ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "PayU account","Konto PayU"
2
+ "Main parameters","Główne parametry"
3
+ "Is One-Click Checkout Enabled","Czy One-Click Checkout włączony"
4
+ "Is self-return enabled","Czy autoodbiór włączony"
5
+ "New order status","Status nowego zamówienia"
6
+ "Active environment","Aktywne środowisko"
7
+ "Parameters of production environment","Parametry środowiska produkcyjnego"
8
+ "POS ID","ID POS (Id punktu płatności)"
9
+ "Client ID (POS ID)","Nazwa klienta (ID POS)"
10
+ "Key MD5 (OAuth protocol - client_secret )","Klucz MD5"
11
+ "Pos Auth Key (Payment authorisation key)","Klucz autoryzacji płatności"
12
+ "Second key MD5 (Symmetrical key)","Drugi klucz MD5 (Symetryczny klucz)"
13
+ "Parameters of test environment (Sandbox)","Parametry środowiska testowego (Sandbox)"
14
+ "POS ID","ID POS (Id punktu płatności)"
15
+ "Client ID (POS ID)","Nazwa klienta (ID POS)"
16
+ "Key MD5 (OAuth protocol - client_secret )","Klucz MD5"
17
+ "Pos Auth Key (Payment authorisation key)","Klucz autoryzacji płatności"
18
+ "Second key MD5 (Symmetrical key)","Drugi klucz MD5 (Symetryczny klucz)"
19
+ "Settings of external resources","Ustawienia zewnętrznych zasobów"
20
+ "One-Click Checkout button","Przycisk One-Click Checkout"
21
+ "Small logo (visible when choosing the payment method)","Małe logo (widoczne przy wyborze standardowej metody płatności)"
22
+ "PayU Advertisement","PayU Reklama"
23
+ "The PayU account module latest version information","Informacje o najnowszej wersji modułu konto PayU"
24
+ "Credit Card or E-transfer","Karta kredytowa lub e-przelew"
25
+ "You are currently using version","Aktualnie zainstalowana wersja"
26
+ "for","dla"
27
+ "The latest version of PayU account plugin is","Najnowszą wersją pluginu konto PayU jest"
28
+ "Get the latest version - ","Pobierz najnowszą wersję - "
29
+ "Documents attached to this implementation","Dokumenty dołączone do tej implementacji"
30
+ "Thank you.","Dziękujemy."
31
+ "Production","Produkcja"
32
+ "There was a problem with the payment initialization, please contact system administrator.","Wystąpił problem podczas inicjalizacji płatności, prosimy o kontakt z obsługą sklepu."
33
+ "Transaction cancelled.","Transakcja anulowana."
34
+ "The transaction has been cancelled.","Transakcja została anulowana."
35
+ "Transaction rejected.","Transakcja odrzucona."
36
+ "The transaction has been rejected.","Transakcja została odrzucona."
37
+ "The transaction is in progress.","Transakcja w trakcie realizacji."
38
+ "Transaction awaits approval.","Transakcja oczekuje na akceptację."
39
+ "The transaction is pending.","Transakcja w toku."
40
+ "Transaction returned.","Transakcja zwrócona."
41
+ "The transaction has been returned.","Transakcja została zwrócona."
42
+ "The transaction completed successfully.","Transakcja zakończona pomyślnie"
43
+ "The transaction is incorrect.","Transakcja nieprawidłowa."
44
+ "You will be redirected to PayU after submitting the order.","Po złożeniu zamówienia nastąpi przekierowanie do PayU."
45
+ "Accept PayU order","Akceptuj zamówienie PayU"
46
+ "Cancel PayU order","Anuluj zamówienie PayU"
47
+ "Order validity time in PayU","Czas ważności zamówienia w PayU"
48
+ "More info on","Więcej informacji na"
49
+ "The order has been cancelled in PayU.","Zamówienie zostało anulowane w PayU."
50
+ "There was a problem while cancelling the order in PayU.","Wystąpił błąd podczas próby anulowania zamówienia w PayU."
51
+ "There was a problem while rejecting the order in PayU.","Wystąpił błąd podczas próby anulowania zamówienia w PayU."
52
+ "The order is completing in PayU, please wait while status changes.","Zamówienie jest w trakcie zmiany na zakończone w PayU, proszę czekać na zmianę statusu w sklepie."
53
+ "There was a problem while completing the order in PayU.","Wystąpił błąd podczas próby zakończenia zamówienia w PayU."
54
+ "CAUTION: PayU plugin is not up to date.","UWAGA: Plugin PayU nie jest aktualny."
55
+ "OK: PayU account plugin is up to date.","OK: Plugin konto PayU jest aktualny."
56
+ "The latest version of PayU plugin is","Najnowszą wersją pluginu PayU jest"
57
+ "The PayU plugin latest version information","Informacje o najnowszej wersji pluginu PayU"
lib/payu/sdk/OpenPayU/Configuration.php ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ OpenPayU Standard Library
5
+
6
+ @copyright Copyright (c) 2011-2012 PayU
7
+ @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
8
+ http://www.payu.com
9
+ http://openpayu.com
10
+ http://twitter.com/openpayu
11
+ */
12
+
13
+ class OpenPayU_Configuration
14
+ {
15
+ public static $env = 'sandbox';
16
+ public static $merchantPosId = '';
17
+ public static $posAuthKey = '';
18
+ public static $clientId = '';
19
+ public static $clientSecret = '';
20
+ public static $signatureKey = '';
21
+
22
+ public static $serviceUrl = '';
23
+ public static $summaryUrl = '';
24
+ public static $authUrl = '';
25
+ public static $serviceDomain = '';
26
+
27
+ /**
28
+ * @access public
29
+ * @param string $value
30
+ * @param string $domain
31
+ * @param string $country
32
+ * @throws Exception
33
+ */
34
+ public static function setEnvironment($value = 'sandbox', $domain = 'payu.pl', $country = 'pl')
35
+ {
36
+ $value = strtolower($value);
37
+ $domain = strtolower($domain);
38
+ $country = strtolower($country);
39
+
40
+ if ($value == 'sandbox' || $value == 'secure') {
41
+ self::$env = $value;
42
+ self::$serviceDomain = $domain;
43
+
44
+ self::$serviceUrl = 'https://' . $value . '.' . $domain . '/' . $country . '/standard/';
45
+ self::$summaryUrl = self::$serviceUrl . 'co/summary';
46
+ self::$authUrl = self::$serviceUrl . 'oauth/user/authorize';
47
+ } else if ($value == 'custom') {
48
+ self::$env = $value;
49
+
50
+ self::$serviceUrl = $domain . '/' . $country . '/standard/';
51
+ self::$summaryUrl = self::$serviceUrl . 'co/summary';
52
+ self::$authUrl = self::$serviceUrl . 'oauth/user/authorize';
53
+ } else {
54
+ throw new Exception('Invalid value:' . $value . ' for environment. Proper values are: "sandbox" or "secure".');
55
+ }
56
+ }
57
+
58
+ /**
59
+ * @access public
60
+ * @return string
61
+ */
62
+ public static function getServiceUrl()
63
+ {
64
+ return self::$serviceUrl;
65
+ }
66
+
67
+ /**
68
+ * @access public
69
+ * @return string
70
+ */
71
+ public static function getSummaryUrl()
72
+ {
73
+ return self::$summaryUrl;
74
+ }
75
+
76
+ /**
77
+ * @access public
78
+ * @return string
79
+ */
80
+ public static function getAuthUrl()
81
+ {
82
+ return self::$authUrl;
83
+ }
84
+
85
+ /**
86
+ * @access public
87
+ * @return string
88
+ */
89
+ public static function getEnvironment()
90
+ {
91
+ return self::$env;
92
+ }
93
+
94
+ /**
95
+ * @access public
96
+ * @param string
97
+ */
98
+ public static function setMerchantPosId($value)
99
+ {
100
+ self::$merchantPosId = trim($value);
101
+ }
102
+
103
+ /**
104
+ * @access public
105
+ * @return string
106
+ */
107
+ public static function getMerchantPosId()
108
+ {
109
+ return self::$merchantPosId;
110
+ }
111
+
112
+ /**
113
+ * @access public
114
+ * @param string
115
+ */
116
+ public static function setPosAuthKey($value)
117
+ {
118
+ self::$posAuthKey = trim($value);
119
+ }
120
+
121
+ /**
122
+ * @access public
123
+ * @return string
124
+ */
125
+ public static function getPosAuthKey()
126
+ {
127
+ return self::$posAuthKey;
128
+ }
129
+
130
+ /**
131
+ * @access public
132
+ * @param string
133
+ */
134
+ public static function setClientId($value)
135
+ {
136
+ self::$clientId = trim($value);
137
+ }
138
+
139
+ /**
140
+ * @access public
141
+ * @return string
142
+ */
143
+ public static function getClientId()
144
+ {
145
+ return self::$clientId;
146
+ }
147
+
148
+ /**
149
+ * @access public
150
+ * @param string
151
+ */
152
+ public static function setClientSecret($value)
153
+ {
154
+ self::$clientSecret = trim($value);
155
+ }
156
+
157
+ /**
158
+ * @access public
159
+ * @return string
160
+ */
161
+ public static function getClientSecret()
162
+ {
163
+ return self::$clientSecret;
164
+ }
165
+
166
+ /**
167
+ * @access public
168
+ * @param string
169
+ */
170
+ public static function setSignatureKey($value)
171
+ {
172
+ self::$signatureKey = trim($value);
173
+ }
174
+
175
+ /**
176
+ * @access public
177
+ * @return string
178
+ */
179
+ public static function getSignatureKey()
180
+ {
181
+ return self::$signatureKey;
182
+ }
183
+
184
+ }
lib/payu/sdk/OpenPayU/OAuth.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ OpenPayU Standard Library
5
+
6
+ @copyright Copyright (c) 2011-2012 PayU
7
+ @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
8
+ http://www.payu.com
9
+ http://openpayu.com
10
+ http://twitter.com/openpayu
11
+ */
12
+
13
+ class OpenPayU_OAuth extends OpenPayUOAuth
14
+ {
15
+ /**
16
+ * Function returns authorize by code response
17
+ * @access public
18
+ * @param string $code
19
+ * @param string $returnUri
20
+ * @param bool $debug
21
+ * @return OpenPayU_ResultOAuth $result
22
+ */
23
+ public static function accessTokenByCode($code, $returnUri, $debug = TRUE)
24
+ {
25
+
26
+ $url = OpenPayU_Configuration::getServiceUrl() . 'user/oauth/authorize';
27
+
28
+ $result = new OpenPayU_ResultOAuth();
29
+ $result->setUrl($url);
30
+ $result->setCode($code);
31
+
32
+ if ($debug) {
33
+ OpenPayU::addOutputConsole('retrieve accessToken, authorization code mode, url', $url);
34
+ OpenPayU::addOutputConsole('return_uri', $returnUri);
35
+ }
36
+
37
+ try {
38
+ OpenPayU::setOpenPayuEndPoint($url);
39
+ $json = OpenPayuOAuth::getAccessTokenByCode($code, OpenPayU_Configuration::getClientId(), OpenPayU_Configuration::getClientSecret(), $returnUri);
40
+
41
+ $result->setAccessToken($json->{'access_token'});
42
+ if (isSet($json->{'payu_user_email'})) {
43
+ $result->setPayuUserEmail($json->{'payu_user_email'});
44
+ }
45
+ if (isSet($json->{'payu_user_id'})) {
46
+ $result->setPayuUserId($json->{'payu_user_id'});
47
+ }
48
+ $result->setExpiresIn($json->{'expires_in'});
49
+ $result->setRefreshToken($json->{'refresh_token'});
50
+ $result->setSuccess(1);
51
+ } catch (Exception $ex) {
52
+ $result->setSuccess(0);
53
+ $result->setError($ex->getMessage());
54
+ }
55
+
56
+ return $result;
57
+ }
58
+
59
+ /**
60
+ * Function returns authorize by client credentials response
61
+ * @access public
62
+ * @param bool $debug
63
+ * @return OpenPayU_ResultOAuth $result
64
+ */
65
+ public static function accessTokenByClientCredentials($debug = TRUE)
66
+ {
67
+ $url = OpenPayU_Configuration::getServiceUrl() . 'oauth/authorize';
68
+
69
+ $result = new OpenPayU_ResultOAuth();
70
+ $result->setUrl($url);
71
+
72
+ OpenPayU::setOpenPayuEndPoint($url);
73
+
74
+ if ($debug)
75
+ OpenPayU::addOutputConsole('retrieve accessToken', 'retrieve accessToken, client credentials mode, url: ' . $url);
76
+
77
+ try {
78
+ OpenPayU::setOpenPayuEndPoint($url);
79
+ $json = OpenPayUOAuth::getAccessTokenByClientCredentials(OpenPayU_Configuration::getClientId(), OpenPayU_Configuration::getClientSecret());
80
+
81
+ $result->setAccessToken($json->{'access_token'});
82
+ if (isSet($json->{'payu_user_email'})) {
83
+ $result->setPayuUserEmail($json->{'payu_user_email'});
84
+ }
85
+ if (isSet($json->{'payu_user_id'})) {
86
+ $result->setPayuUserId($json->{'payu_user_id'});
87
+ }
88
+ $result->setExpiresIn($json->{'expires_in'});
89
+ $result->setRefreshToken($json->{'refresh_token'});
90
+ $result->setSuccess(1);
91
+ } catch (Exception $ex) {
92
+ $result->setSuccess(0);
93
+ $result->setError($ex->getMessage());
94
+ }
95
+
96
+ return $result;
97
+ }
98
+ }
lib/payu/sdk/OpenPayU/OpenPayU.php ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ OpenPayU Standard Library
5
+
6
+ @copyright Copyright (c) 2011-2012 PayU
7
+ @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
8
+ http://www.payu.com
9
+ http://openpayu.com
10
+ http://twitter.com/openpayu
11
+ */
12
+
13
+ class OpenPayU extends OpenPayUBase
14
+ {
15
+
16
+ /**
17
+ * Function builds OrderCreateRequest Document
18
+ * @access public
19
+ * @param string $data
20
+ * @return string
21
+ */
22
+ public static function buildOrderCreateRequest($data)
23
+ {
24
+ $xml = OpenPayU::buildOpenPayURequestDocument($data, 'OrderCreateRequest');
25
+ return $xml;
26
+ }
27
+
28
+ /**
29
+ * Function builds OrderRetrieveRequest Document
30
+ * @access public
31
+ * @param array $data
32
+ * @return string $xml
33
+ */
34
+ public static function buildOrderRetrieveRequest($data)
35
+ {
36
+ $xml = OpenPayU::buildOpenPayURequestDocument($data, 'OrderRetrieveRequest');
37
+ return $xml;
38
+ }
39
+
40
+ /**
41
+ * Function builds ShippingCostRetrieveResponse Document
42
+ * @access public
43
+ * @param array $data
44
+ * @param string $reqId
45
+ * @return string $xml
46
+ */
47
+ public static function buildShippingCostRetrieveResponse($data, $reqId)
48
+ {
49
+
50
+ $cost = array(
51
+ 'ResId' => $reqId,
52
+ 'Status' => array('StatusCode' => 'OPENPAYU_SUCCESS'),
53
+ 'AvailableShippingCost' => $data
54
+ );
55
+
56
+ $xml = OpenPayU::buildOpenPayUResponseDocument($cost, 'ShippingCostRetrieveResponse');
57
+ return $xml;
58
+ }
59
+
60
+ /**
61
+ * Function builds buildOrderNotifyResponse Document
62
+ * @access public
63
+ * @param string $reqId
64
+ * @return string $xml
65
+ */
66
+ public static function buildOrderNotifyResponse($reqId)
67
+ {
68
+
69
+ $cost = array(
70
+ 'ResId' => $reqId,
71
+ 'Status' => array('StatusCode' => 'OPENPAYU_SUCCESS')
72
+ );
73
+
74
+ $xml = OpenPayU::buildOpenPayUResponseDocument($cost, 'OrderNotifyResponse');
75
+ return $xml;
76
+ }
77
+
78
+ /**
79
+ * Function builds verifyResponse Status
80
+ * @access public
81
+ * @param string $data
82
+ * @param string $message
83
+ * @return string $xml
84
+ */
85
+ public static function verifyResponse($data, $message)
86
+ {
87
+
88
+ $arr = OpenPayU::parseOpenPayUDocument(stripslashes($data));
89
+
90
+ if (isset($arr['OpenPayU']['OrderDomainResponse'][$message]['Status']))
91
+ $status_code = $arr['OpenPayU']['OrderDomainResponse'][$message]['Status'];
92
+
93
+ if ($status_code == null)
94
+ $status_code = $arr['OpenPayU']['HeaderResponse']['Status'];
95
+
96
+ return $status_code;
97
+ }
98
+
99
+ /**
100
+ * Function returns OrderCancelResponse Status Document
101
+ * @access public
102
+ * @param string $data
103
+ * @return string $xml
104
+ */
105
+ public static function verifyOrderCancelResponseStatus($data)
106
+ {
107
+ return OpenPayU::verifyResponse($data, 'OrderCancelResponse');
108
+ }
109
+
110
+ /**
111
+ * Function returns OrderStatusUpdateResponse Status Document
112
+ * @access public
113
+ * @param string $data
114
+ * @return string $xml
115
+ */
116
+ public static function verifyOrderStatusUpdateResponseStatus($data)
117
+ {
118
+ return OpenPayU::verifyResponse($data, 'OrderStatusUpdateResponse');
119
+ }
120
+
121
+ /**
122
+ * Function returns OrderCreateResponse Status
123
+ * @access public
124
+ * @param string $data
125
+ * @return string $status_code
126
+ */
127
+ public static function verifyOrderCreateResponse($data)
128
+ {
129
+ $arr = OpenPayU::parseOpenPayUDocument(stripslashes($data));
130
+
131
+ if (isset($arr['OpenPayU']['OrderDomainResponse']['OrderCreateResponse']['Status']))
132
+ $status_code = $arr['OpenPayU']['OrderDomainResponse']['OrderCreateResponse']['Status'];
133
+
134
+ if ($status_code == null)
135
+ $status_code = $arr['OpenPayU']['HeaderResponse']['Status'];
136
+
137
+ return $status_code;
138
+ }
139
+
140
+ /**
141
+ * Function returns OrderRetrieveResponse Status
142
+ * @access public
143
+ * @param string $data
144
+ * @return string $status_code
145
+ */
146
+ public static function verifyOrderRetrieveResponseStatus($data)
147
+ {
148
+ $arr = OpenPayU::parseOpenPayUDocument(stripslashes($data));
149
+
150
+ if (isset($arr['OpenPayU']['OrderDomainResponse']['OrderRetrieveResponse']['Status']))
151
+ $status_code = $arr['OpenPayU']['OrderDomainResponse']['OrderRetrieveResponse']['Status'];
152
+
153
+ if ($status_code == null)
154
+ $status_code = $arr['OpenPayU']['HeaderResponse']['Status'];
155
+
156
+ return $status_code;
157
+ }
158
+
159
+ /**
160
+ * Function returns OrderRetrieveResponse Data
161
+ * @access public
162
+ * @param string $data
163
+ * @return array $order_retrieve
164
+ */
165
+ public static function getOrderRetrieveResponse($data)
166
+ {
167
+ $arr = OpenPayU::parseOpenPayUDocument(stripslashes($data));
168
+ $order_retrieve = $arr['OpenPayU']['OrderDomainResponse']['OrderRetrieveResponse'];
169
+
170
+ return $order_retrieve;
171
+ }
172
+
173
+ /**
174
+ * Function builds OrderCancelRequest Document
175
+ * @access public
176
+ * @param string $data
177
+ * @return string $xml
178
+ */
179
+ public static function buildOrderCancelRequest($data)
180
+ {
181
+ $xml = OpenPayU::buildOpenPayURequestDocument($data, 'OrderCancelRequest');
182
+
183
+ return $xml;
184
+ }
185
+
186
+ /**
187
+ * Function builds OrderStatusUpdateRequest Document
188
+ * @access public
189
+ * @param string $data
190
+ * @return string $xml
191
+ */
192
+ public static function buildOrderStatusUpdateRequest($data)
193
+ {
194
+ $xml = OpenPayU::buildOpenPayURequestDocument($data, 'OrderStatusUpdateRequest');
195
+
196
+ return $xml;
197
+ }
198
+ }
lib/payu/sdk/OpenPayU/OpenPayUBase.php ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ OpenPayU Standard Library
5
+
6
+ @copyright Copyright (c) 2011-2012 PayU
7
+ @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
8
+ http://www.payu.com
9
+ http://openpayu.com
10
+ http://twitter.com/openpayu
11
+ */
12
+
13
+ class OpenPayUBase extends OpenPayUNetwork
14
+ {
15
+
16
+ /** @var string outputConsole message */
17
+ protected static $outputConsole = '';
18
+
19
+ /**
20
+ * Show outputConsole message
21
+ * @access public
22
+ */
23
+ public static function printOutputConsole()
24
+ {
25
+ echo OpenPayU::$outputConsole;
26
+ }
27
+
28
+ /**
29
+ * Add $outputConsole message
30
+ * @access public
31
+ * @param string $header
32
+ * @param string $text
33
+ */
34
+ public static function addOutputConsole($header, $text = '')
35
+ {
36
+ OpenPayU::$outputConsole .= '<br/><strong>' . $header . ':</strong><br />' . $text . '<br/>';
37
+ }
38
+
39
+ /**
40
+ * Function builds OpenPayU Request Document
41
+ * @access public
42
+ * @param string $data
43
+ * @param string $startElement Name of Document Element
44
+ * @param string $version Xml Version
45
+ * @param string $xml_encoding Xml Encoding
46
+ * @return string
47
+ */
48
+ public static function buildOpenPayURequestDocument($data, $startElement, $version = '1.0', $xml_encoding = 'UTF-8')
49
+ {
50
+ return OpenPayUBase::buildOpenPayUDocument($data, $startElement, 1, $version, $xml_encoding);
51
+ }
52
+
53
+ /**
54
+ * Function builds OpenPayU Response Document
55
+ * @access public
56
+ * @param string $data
57
+ * @param string $startElement Name of Document Element
58
+ * @param string $version Xml Version
59
+ * @param string $xml_encoding Xml Encoding
60
+ * @return string
61
+ */
62
+ public static function buildOpenPayUResponseDocument($data, $startElement, $version = '1.0', $xml_encoding = 'UTF-8')
63
+ {
64
+ return OpenPayUBase::buildOpenPayUDocument($data, $startElement, 0, $version, $xml_encoding);
65
+ }
66
+
67
+ /**
68
+ * Function converts array to XML document
69
+ * @access public
70
+ * @param XMLWriter $xml
71
+ * @param array $data
72
+ */
73
+ public static function arr2xml(XMLWriter $xml, $data)
74
+ {
75
+ if (!empty($data) && is_array($data)) {
76
+ foreach ($data as $key => $value) {
77
+ if (is_array($value)) {
78
+ if (is_numeric($key)) {
79
+ self::arr2xml($xml, $value);
80
+ } else {
81
+ $xml->startElement($key);
82
+ self::arr2xml($xml, $value);
83
+ $xml->endElement();
84
+ }
85
+ continue;
86
+ }
87
+ $xml->writeElement($key, $value);
88
+ }
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Function converts array to Form
94
+ * @access public
95
+ * @param array $data
96
+ * @param string $parent
97
+ * @param integer $index
98
+ * @return string $fragment
99
+ */
100
+ public static function arr2form($data, $parent, $index)
101
+ {
102
+ $fragment = '';
103
+
104
+ if (!empty($data) && is_array($data)) {
105
+ foreach ($data as $key => $value) {
106
+ if (is_array($value)) {
107
+ if (is_numeric($key)) {
108
+ $fragment .= OpenPayUBase::arr2form($value, $parent, $key);
109
+ } else {
110
+ $p = $parent != '' ? $parent . '.' . $key : $key;
111
+ if (is_numeric($index)) {
112
+ $p .= '[' . $index . ']';
113
+ }
114
+ $fragment .= OpenPayUBase::arr2form($value, $p, $key);
115
+ }
116
+ continue;
117
+ }
118
+
119
+ $path = $parent != '' ? $parent . '.' . $key : $key;
120
+ $fragment .= OpenPayUBase::buildFormFragmentInput($path, $value);
121
+ }
122
+ }
123
+
124
+ return $fragment;
125
+ }
126
+
127
+ /**
128
+ * Function converts xml to array
129
+ * @access public
130
+ * @param XMLReader $xml
131
+ * @return array $tree
132
+ */
133
+ public static function read($xml)
134
+ {
135
+ $tree = null;
136
+ while ($xml->read()) {
137
+ if ($xml->nodeType == XMLReader::END_ELEMENT) {
138
+ return $tree;
139
+ } else if ($xml->nodeType == XMLReader::ELEMENT) {
140
+ if (!$xml->isEmptyElement) {
141
+ $tree[$xml->name] = OpenPayUBase::read($xml);
142
+ }
143
+ } else if ($xml->nodeType == XMLReader::TEXT) {
144
+ $tree = $xml->value;
145
+ }
146
+ }
147
+ return $tree;
148
+ }
149
+
150
+ /**
151
+ * Function builds OpenPayU Xml Document
152
+ * @access public
153
+ * @param string $data
154
+ * @param string $startElement
155
+ * @param integer $request
156
+ * @param string $xml_version
157
+ * @param string $xml_encoding
158
+ * @return string $xml
159
+ */
160
+ public static function buildOpenPayUDocument($data, $startElement, $request = 1, $xml_version = '1.0', $xml_encoding = 'UTF-8')
161
+ {
162
+ if (!is_array($data))
163
+ return false;
164
+
165
+ $xml = new XmlWriter();
166
+ $xml->openMemory();
167
+ $xml->startDocument($xml_version, $xml_encoding);
168
+ $xml->startElementNS(null, 'OpenPayU', 'http://www.openpayu.com/openpayu.xsd');
169
+
170
+ $header = $request == 1 ? 'HeaderRequest' : 'HeaderResponse';
171
+
172
+ $xml->startElement($header);
173
+
174
+ $xml->writeElement('Algorithm', 'MD5');
175
+
176
+ $xml->writeElement('SenderName', 'exampleSenderName');
177
+ $xml->writeElement('Version', $xml_version);
178
+
179
+ $xml->endElement();
180
+
181
+ // domain level - open
182
+ $xml->startElement(OpenPayUDomain::getDomain4Message($startElement));
183
+
184
+ // message level - open
185
+ $xml->startElement($startElement);
186
+
187
+ self::arr2xml($xml, $data);
188
+
189
+ // message level - close
190
+ $xml->endElement();
191
+ // domain level - close
192
+ $xml->endElement();
193
+ // document level - close
194
+ $xml->endElement();
195
+
196
+ return $xml->outputMemory(true);
197
+ }
198
+
199
+ /**
200
+ * Function builds form input element
201
+ * @access public
202
+ * @param string $name
203
+ * @param string $value
204
+ * @param string $type
205
+ * @return string
206
+ */
207
+ public static function buildFormFragmentInput($name, $value, $type = 'hidden')
208
+ {
209
+ return "<input type='" . $type . "' name='" . $name . "' value='" . $value . "'>\n";
210
+ }
211
+
212
+ /**
213
+ * Function builds OpenPayU Form
214
+ * @access public
215
+ * @param string $data
216
+ * @param string $msgName
217
+ * @param string $version
218
+ * @return string
219
+ */
220
+ public static function buildOpenPayuForm($data, $msgName, $version = '1.0')
221
+ {
222
+ if (!is_array($data))
223
+ return false;
224
+
225
+ $url = OpenPayUNetwork::getOpenPayuEndPoint();
226
+
227
+ $form = "<form method='post' action='" . $url . "'>\n";
228
+ $form .= OpenPayUBase::buildFormFragmentInput('HeaderRequest.Version', $version);
229
+ $form .= OpenPayUBase::buildFormFragmentInput('HeaderRequest.Name', $msgName);
230
+ $form .= OpenPayUBase::arr2form($data, '', '');
231
+ $form .= "</form>";
232
+
233
+ return $form;
234
+ }
235
+
236
+ /**
237
+ * Function converts Xml string to array
238
+ * @access public
239
+ * @param string $xmldata
240
+ * @return array $assoc
241
+ */
242
+ public static function parseOpenPayUDocument($xmldata)
243
+ {
244
+ $xml = new XMLReader();
245
+ $xml->XML($xmldata);
246
+
247
+ $assoc = self::read($xml);
248
+
249
+ return $assoc;
250
+ }
251
+ }
lib/payu/sdk/OpenPayU/OpenPayUNetwork.php ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ OpenPayU Standard Library
5
+
6
+ @copyright Copyright (c) 2011-2012 PayU
7
+ @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
8
+ http://www.payu.com
9
+ http://openpayu.com
10
+ http://twitter.com/openpayu
11
+ */
12
+
13
+ class OpenPayUNetwork
14
+ {
15
+ /** @var string OpenPayU EndPoint Url */
16
+ protected static $openPayuEndPointUrl = '';
17
+
18
+ /**
19
+ * The function sets EndPointUrl param of OpenPayU
20
+ * @access public
21
+ * @param string $ep
22
+ */
23
+ public static function setOpenPayuEndPoint($ep)
24
+ {
25
+ self::$openPayuEndPointUrl = $ep;
26
+ }
27
+
28
+ /**
29
+ * This function checks the availability of cURL
30
+ * @access private
31
+ * @return bool
32
+ */
33
+ private static function isCurlInstalled()
34
+ {
35
+ if (in_array('curl', get_loaded_extensions()))
36
+ return true;
37
+
38
+ return false;
39
+ }
40
+
41
+ /**
42
+ * The function returns the parameter EndPointUrl OpenPayU
43
+ * @access public
44
+ * @return string
45
+ * @throws Exception
46
+ */
47
+ public static function getOpenPayuEndPoint()
48
+ {
49
+ if (empty(self::$openPayuEndPointUrl))
50
+ throw new Exception('OpenPayUNetwork::$openPayuEndPointUrl is empty');
51
+
52
+ return self::$openPayuEndPointUrl;
53
+ }
54
+
55
+ /**
56
+ * This function sends data to the EndPointUrl OpenPayU
57
+ * @access public
58
+ * @param string $doc
59
+ * @return string
60
+ * @throws Exception
61
+ */
62
+ public static function sendOpenPayuDocument($doc)
63
+ {
64
+
65
+ if (empty(self::$openPayuEndPointUrl))
66
+ throw new Exception('OpenPayUNetwork::$openPayuEndPointUrl is empty');
67
+
68
+ if (!self::isCurlInstalled())
69
+ throw new Exception('cURL is not available');
70
+
71
+ $xml = urlencode($doc);
72
+ return OpenPayU::sendData(self::$openPayuEndPointUrl, 'DOCUMENT=' . $xml);
73
+ }
74
+
75
+ /**
76
+ * This function sends auth data to the EndPointUrl OpenPayU
77
+ * @access public
78
+ * @param string $doc
79
+ * @param integer $merchantPosId
80
+ * @param string $signatureKey
81
+ * @param string $algorithm
82
+ * @return string
83
+ * @throws Exception
84
+ */
85
+ public static function sendOpenPayuDocumentAuth($doc, $merchantPosId, $signatureKey, $algorithm = 'MD5')
86
+ {
87
+ if (empty(self::$openPayuEndPointUrl))
88
+ throw new Exception('OpenPayUNetwork::$openPayuEndPointUrl is empty');
89
+
90
+ if (empty($signatureKey))
91
+ throw new Exception('Merchant Signature Key should not be null or empty.');
92
+
93
+ if (empty($merchantPosId))
94
+ throw new Exception('MerchantPosId should not be null or empty.');
95
+
96
+ $tosigndata = $doc . $signatureKey;
97
+ $xml = urlencode($doc);
98
+ $signature = '';
99
+ if ($algorithm == 'MD5') {
100
+ $signature = md5($tosigndata);
101
+ } else if ($algorithm == 'SHA') {
102
+ $signature = sha1($tosigndata);
103
+ } else if ($algorithm == 'SHA-256' || $algorithm == 'SHA256' || $algorithm == 'SHA_256') {
104
+ $signature = hash('sha256', $tosigndata);
105
+ }
106
+ $authData = 'sender=' . $merchantPosId .
107
+ ';signature=' . $signature .
108
+ ';algorithm=' . $algorithm .
109
+ ';content=DOCUMENT';
110
+
111
+ if (!self::isCurlInstalled())
112
+ throw new Exception('curl is not available');
113
+
114
+ return OpenPayU::sendDataAuth(self::$openPayuEndPointUrl, 'DOCUMENT=' . $xml, $authData);
115
+ }
116
+
117
+ /**
118
+ * This function sends auth data to the EndPointUrl OpenPayU
119
+ * @access public
120
+ * @param string $url
121
+ * @param string $doc
122
+ * @param string $authData
123
+ * @return string $response
124
+ */
125
+ public static function sendDataAuth($url, $doc, $authData)
126
+ {
127
+ $ch = curl_init($url);
128
+ curl_setopt($ch, CURLOPT_POST, 1);
129
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $doc);
130
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
131
+ curl_setopt($ch, CURLOPT_SSLVERSION, 3);
132
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
133
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
134
+ curl_setopt($ch, CURLOPT_HEADER, false);
135
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
136
+
137
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('OpenPayu-Signature:' . $authData));
138
+
139
+ $response = curl_exec($ch);
140
+
141
+ return $response;
142
+ }
143
+
144
+ /**
145
+ * This function sends data to the EndPointUrl OpenPayU
146
+ * @access public
147
+ * @param string $url
148
+ * @param string $doc
149
+ * @return string $response
150
+ */
151
+ public static function sendData($url, $doc)
152
+ {
153
+ $ch = curl_init($url);
154
+ curl_setopt($ch, CURLOPT_POST, 1);
155
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $doc);
156
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
157
+ curl_setopt($ch, CURLOPT_SSLVERSION, 3);
158
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
159
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
160
+ curl_setopt($ch, CURLOPT_HEADER, false);
161
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
162
+
163
+ $response = curl_exec($ch);
164
+
165
+ return $response;
166
+ }
167
+ }
lib/payu/sdk/OpenPayU/OpenPayUOAuth.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ OpenPayU Standard Library
5
+
6
+ @copyright Copyright (c) 2011-2012 PayU
7
+ @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
8
+ http://www.payu.com
9
+ http://openpayu.com
10
+ http://twitter.com/openpayu
11
+ */
12
+
13
+ class OpenPayuOAuth extends OpenPayUBase
14
+ {
15
+
16
+ /**
17
+ * @access public
18
+ * @param string $code
19
+ * @param string $oauth_client_name
20
+ * @param string $oauth_client_secret
21
+ * @param string $page_redirect
22
+ * @return mixed
23
+ * @throws Exception
24
+ */
25
+ public static function getAccessTokenByCode($code, $oauth_client_name, $oauth_client_secret, $page_redirect)
26
+ {
27
+ $params = 'code=' . $code . '&client_id=' . $oauth_client_name . '&client_secret=' . $oauth_client_secret . '&grant_type=authorization_code&redirect_uri=' . $page_redirect;
28
+
29
+ $response = OpenPayU::sendData(OpenPayUNetwork::getOpenPayuEndPoint(), $params);
30
+
31
+ $resp_json = json_decode($response);
32
+ OpenPayU::addOutputConsole('oauth response', $response);
33
+ $access_token = $resp_json->{"access_token"};
34
+
35
+ if (empty($access_token))
36
+ throw new Exception('access_token is empty, error: ' . $response);
37
+
38
+ return $resp_json;
39
+ }
40
+
41
+ /**
42
+ * @access public
43
+ * @param string $code
44
+ * @param string $oauth_client_name
45
+ * @param string $oauth_client_secret
46
+ * @param string $page_redirect
47
+ * @return mixed
48
+ * @throws Exception
49
+ */
50
+ public static function getAccessToken($code, $oauth_client_name, $oauth_client_secret, $page_redirect)
51
+ {
52
+ $params = 'code=' . $code . '&client_id=' . $oauth_client_name . '&client_secret=' . $oauth_client_secret . '&grant_type=authorization_code&redirect_uri=' . $page_redirect;
53
+
54
+ $response = OpenPayU::sendData(OpenPayUNetwork::getOpenPayuEndPoint(), $params);
55
+
56
+ $resp_json = json_decode($response);
57
+ OpenPayU::addOutputConsole('oauth response', $response);
58
+ $access_token = $resp_json->{"access_token"};
59
+
60
+ if (empty($access_token))
61
+ throw new Exception('access_token is empty, error: ' . $response);
62
+
63
+ return $access_token;
64
+ }
65
+
66
+ /**
67
+ * @access public
68
+ * @param string $oauth_client_name
69
+ * @param string $oauth_client_secret
70
+ * @return mixed
71
+ * @throws Exception
72
+ */
73
+ public static function getAccessTokenByClientCredentials($oauth_client_name, $oauth_client_secret)
74
+ {
75
+ $params = 'client_id=' . $oauth_client_name . '&client_secret=' . $oauth_client_secret . '&grant_type=client_credentials';
76
+
77
+ $response = OpenPayU::sendData(OpenPayUNetwork::getOpenPayuEndPoint(), $params);
78
+
79
+ $resp_json = json_decode($response);
80
+ OpenPayU::addOutputConsole('oauth response', $response);
81
+
82
+ $access_token = $resp_json->{'access_token'};
83
+
84
+ if (empty($access_token))
85
+ throw new Exception('access_token is empty, error: ' . $response);
86
+
87
+ return $resp_json;
88
+ }
89
+
90
+ /**
91
+ * @access public
92
+ * @param string $oauth_client_name
93
+ * @param string $oauth_client_secret
94
+ * @return mixed
95
+ * @throws Exception
96
+ */
97
+ public static function getAccessTokenOnly($oauth_client_name, $oauth_client_secret)
98
+ {
99
+ $params = 'client_id=' . $oauth_client_name . '&client_secret=' . $oauth_client_secret . '&grant_type=client_credentials';
100
+
101
+ $response = OpenPayU::sendData(OpenPayUNetwork::getOpenPayuEndPoint(), $params);
102
+
103
+ $resp_json = json_decode($response);
104
+ OpenPayU::addOutputConsole('oauth response', $response);
105
+
106
+ $access_token = $resp_json->{'access_token'};
107
+
108
+ if (empty($access_token))
109
+ throw new Exception('access_token is empty, error: ' . $response);
110
+
111
+ return $access_token;
112
+ }
113
+ }
lib/payu/sdk/OpenPayU/Order.php ADDED
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ OpenPayU Standard Library
5
+
6
+ @copyright Copyright (c) 2011-2012 PayU
7
+ @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
8
+ http://www.payu.com
9
+ http://openpayu.com
10
+ http://twitter.com/openpayu
11
+ */
12
+
13
+ class OpenPayU_Order extends OpenPayU
14
+ {
15
+
16
+ /**
17
+ * Function sending Order to PayU Service
18
+ * @access public
19
+ * @param array $order
20
+ * @param bool $debug
21
+ * @return object $result
22
+ */
23
+ public static function create($order, $debug = TRUE)
24
+ {
25
+
26
+ // preparing payu service for order initialization
27
+ $OrderCreateRequestUrl = OpenPayU_Configuration::getServiceUrl() . 'co/openpayu/OrderCreateRequest';
28
+
29
+ if ($debug)
30
+ OpenPayU::addOutputConsole('OpenPayU endpoint for OrderCreateRequest message', $OrderCreateRequestUrl);
31
+
32
+ OpenPayU::setOpenPayuEndPoint($OrderCreateRequestUrl);
33
+
34
+ // convert array to openpayu document
35
+ $xml = OpenPayU::buildOrderCreateRequest($order);
36
+
37
+ if ($debug)
38
+ OpenPayU::addOutputConsole('OrderCreateRequest message', htmlentities($xml));
39
+
40
+ $merchantPosId = OpenPayU_Configuration::getMerchantPosId();
41
+ $signatureKey = OpenPayU_Configuration::getSignatureKey();
42
+
43
+ // send openpayu document with order initialization structure to PayU service
44
+ $response = OpenPayU::sendOpenPayuDocumentAuth($xml, $merchantPosId, $signatureKey);
45
+
46
+ if ($debug)
47
+ OpenPayU::addOutputConsole('OrderCreateRequest message', htmlentities($response));
48
+
49
+ // verify response from PayU service
50
+ $status = OpenPayU::verifyOrderCreateResponse($response);
51
+
52
+ if ($debug)
53
+ OpenPayU::addOutputConsole('OrderCreateResponse status', serialize($status));
54
+
55
+ $result = new OpenPayU_Result();
56
+ $result->setStatus($status);
57
+ $result->setError($status['StatusCode']);
58
+ $result->setMessage($status['StatusDesc']);
59
+ $result->setSuccess($status['StatusCode'] == 'OPENPAYU_SUCCESS' ? TRUE : FALSE);
60
+ $result->setRequest($order);
61
+ $result->setResponse(OpenPayU::parseOpenPayUDocument($response));
62
+
63
+ return $result;
64
+ }
65
+
66
+ /**
67
+ * Function retrieving Order data from PayU Service
68
+ * @access public
69
+ * @param string $sessionId
70
+ * @param bool $debug
71
+ * @return OpenPayU_Result $result
72
+ */
73
+ public static function retrieve($sessionId, $debug = TRUE)
74
+ {
75
+ $req = array(
76
+ 'ReqId' => md5(rand()),
77
+ 'MerchantPosId' => OpenPayU_Configuration::getMerchantPosId(),
78
+ 'SessionId' => $sessionId
79
+ );
80
+
81
+ $OrderRetrieveRequestUrl = OpenPayU_Configuration::getServiceUrl() . 'co/openpayu/OrderRetrieveRequest';
82
+
83
+ if ($debug)
84
+ OpenPayU::addOutputConsole('OpenPayU endpoint for OrderRetrieveRequest message', $OrderRetrieveRequestUrl);
85
+
86
+ $oauthResult = OpenPayu_OAuth::accessTokenByClientCredentials();
87
+
88
+ OpenPayU::setOpenPayuEndPoint($OrderRetrieveRequestUrl . '?oauth_token=' . $oauthResult->getAccessToken());
89
+ $xml = OpenPayU::buildOrderRetrieveRequest($req);
90
+
91
+ if ($debug)
92
+ OpenPayU::addOutputConsole('OrderRetrieveRequest message', htmlentities($xml));
93
+
94
+ $merchantPosId = OpenPayU_Configuration::getMerchantPosId();
95
+ $signatureKey = OpenPayU_Configuration::getSignatureKey();
96
+ $response = OpenPayU::sendOpenPayuDocumentAuth($xml, $merchantPosId, $signatureKey);
97
+
98
+ if ($debug)
99
+ OpenPayU::addOutputConsole('OrderRetrieveResponse message', htmlentities($response));
100
+
101
+ $status = OpenPayU::verifyOrderRetrieveResponseStatus($response);
102
+
103
+ if ($debug)
104
+ OpenPayU::addOutputConsole('OrderRetrieveResponse status', serialize($status));
105
+
106
+ $result = new OpenPayU_Result();
107
+ $result->setStatus($status);
108
+ $result->setError($status['StatusCode']);
109
+ $result->setMessage($status['StatusDesc']);
110
+ $result->setSuccess($status['StatusCode'] == 'OPENPAYU_SUCCESS' ? TRUE : FALSE);
111
+ $result->setRequest($req);
112
+ $result->setResponse($response);
113
+
114
+ try {
115
+ $assoc = OpenPayU::parseOpenPayUDocument($response);
116
+ $result->setResponse($assoc);
117
+ } catch (Exception $ex) {
118
+ if ($debug)
119
+ OpenPayU::addOutputConsole('OrderRetrieveResponse parse result exception', $ex->getMessage());
120
+ }
121
+
122
+ return $result;
123
+ }
124
+
125
+ /**
126
+ * Function consume message
127
+ * @access public
128
+ * @param string $xml
129
+ * @param boolean $response Show Response Xml
130
+ * @param bool $debug
131
+ * @return object $result
132
+ */
133
+ public static function consumeMessage($xml, $response = TRUE, $debug = TRUE)
134
+ {
135
+ $xml = stripslashes(urldecode($xml));
136
+ $rq = OpenPayU::parseOpenPayUDocument($xml);
137
+
138
+ $msg = $rq['OpenPayU']['OrderDomainRequest'];
139
+
140
+ switch (key($msg)) {
141
+ case 'OrderNotifyRequest':
142
+ return self::consumeNotification($xml, $response, $debug);
143
+ break;
144
+ case 'ShippingCostRetrieveRequest':
145
+ return self::consumeShippingCostRetrieveRequest($xml, $debug);
146
+ break;
147
+ default:
148
+ return key($msg);
149
+ break;
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Function consume notification message
155
+ * @access private
156
+ * @param string $xml
157
+ * @param boolean $response Show Response Xml
158
+ * @param bool $debug
159
+ * @return OpenPayU_Result $result
160
+ */
161
+ private static function consumeNotification($xml, $response = TRUE, $debug = TRUE)
162
+ {
163
+ if ($debug)
164
+ OpenPayU::addOutputConsole('OrderNotifyRequest message', $xml);
165
+
166
+ $xml = stripslashes(urldecode($xml));
167
+ $rq = OpenPayU::parseOpenPayUDocument($xml);
168
+ $reqId = $rq['OpenPayU']['OrderDomainRequest']['OrderNotifyRequest']['ReqId'];
169
+ $sessionId = $rq['OpenPayU']['OrderDomainRequest']['OrderNotifyRequest']['SessionId'];
170
+
171
+ if ($debug)
172
+ OpenPayU::addOutputConsole('OrderNotifyRequest data, reqId', $reqId . ', sessionId: ' . $sessionId);
173
+
174
+
175
+ // response to payu service
176
+ $rsp = OpenPayU::buildOrderNotifyResponse($reqId);
177
+ if ($debug)
178
+ OpenPayU::addOutputConsole('OrderNotifyResponse message', $rsp);
179
+
180
+ // show response
181
+ if ($response == TRUE) {
182
+ header("Content-Type:text/xml");
183
+ echo $rsp;
184
+ }
185
+
186
+ // create OpenPayU Result object
187
+ $result = new OpenPayU_Result();
188
+ $result->setSessionId($sessionId);
189
+ $result->setSuccess(TRUE);
190
+ $result->setRequest($rq);
191
+ $result->setResponse($rsp);
192
+ $result->setMessage('OrderNotifyRequest');
193
+
194
+ // if everything is alright return full data sent from payu service to client
195
+ return $result;
196
+ }
197
+
198
+ /**
199
+ * Function consume shipping cost calculation request message
200
+ * @access private
201
+ * @param string $xml
202
+ * @param bool $debug
203
+ * @return OpenPayU_Result $result
204
+ */
205
+ private static function consumeShippingCostRetrieveRequest($xml, $debug = TRUE)
206
+ {
207
+ if ($debug)
208
+ OpenPayU::addOutputConsole('consumeShippingCostRetrieveRequest message', $xml);
209
+
210
+ $rq = OpenPayU::parseOpenPayUDocument($xml);
211
+
212
+ $result = new OpenPayU_Result();
213
+ $result->setCountryCode($rq['OpenPayU']['OrderDomainRequest']['ShippingCostRetrieveRequest']['CountryCode']);
214
+ $result->setSessionId($rq['OpenPayU']['OrderDomainRequest']['ShippingCostRetrieveRequest']['SessionId']);
215
+ $result->setReqId($rq['OpenPayU']['OrderDomainRequest']['ShippingCostRetrieveRequest']['ReqId']);
216
+ $result->setMessage('ShippingCostRetrieveRequest');
217
+
218
+ if ($debug)
219
+ OpenPayU::addOutputConsole('consumeShippingCostRetrieveRequest reqId', $result->getReqId() . ', countryCode: ' . $result->getCountryCode());
220
+
221
+ return $result;
222
+ }
223
+
224
+ /**
225
+ * Function use to cancel
226
+ * @access public
227
+ * @param string $sessionId
228
+ * @param bool $debug
229
+ * @return OpenPayU_Result $result
230
+ */
231
+ public static function cancel($sessionId, $debug = TRUE)
232
+ {
233
+
234
+ $rq = array(
235
+ 'ReqId' => md5(rand()),
236
+ 'MerchantPosId' => OpenPayU_Configuration::getMerchantPosId(),
237
+ 'SessionId' => $sessionId
238
+ );
239
+
240
+ $result = new OpenPayU_Result();
241
+ $result->setRequest($rq);
242
+
243
+ $url = OpenPayU_Configuration::getServiceUrl() . 'co/openpayu/OrderCancelRequest';
244
+
245
+ if ($debug)
246
+ OpenPayU::addOutputConsole('OpenPayU endpoint for OrderCancelRequest message', $url);
247
+
248
+ $oauthResult = OpenPayu_OAuth::accessTokenByClientCredentials();
249
+ OpenPayU::setOpenPayuEndPoint($url . '?oauth_token=' . $oauthResult->getAccessToken());
250
+
251
+ $xml = OpenPayU::buildOrderCancelRequest($rq);
252
+
253
+ if ($debug)
254
+ OpenPayU::addOutputConsole('OrderCancelRequest message', htmlentities($xml));
255
+
256
+ $merchantPosId = OpenPayU_Configuration::getMerchantPosId();
257
+ $signatureKey = OpenPayU_Configuration::getSignatureKey();
258
+ $response = OpenPayU::sendOpenPayuDocumentAuth($xml, $merchantPosId, $signatureKey);
259
+
260
+ if ($debug)
261
+ OpenPayU::addOutputConsole('OrderCancelResponse message', htmlentities($response));
262
+
263
+ // verify response from PayU service
264
+ $status = OpenPayU::verifyOrderCancelResponseStatus($response);
265
+
266
+ if ($debug)
267
+ OpenPayU::addOutputConsole('OrderCancelResponse status', serialize($status));
268
+
269
+ $result->setStatus($status);
270
+ $result->setError($status['StatusCode']);
271
+ $result->setMessage($status['StatusDesc']);
272
+ $result->setSuccess($status['StatusCode'] == 'OPENPAYU_SUCCESS' ? TRUE : FALSE);
273
+ $result->setResponse(OpenPayU::parseOpenPayUDocument($response));
274
+
275
+ return $result;
276
+ }
277
+
278
+ /**
279
+ * Function use to update status
280
+ * @access public
281
+ * @param string $sessionId
282
+ * @param string $status
283
+ * @param bool $debug
284
+ * @return OpenPayU_Result $result
285
+ */
286
+ public static function updateStatus($sessionId, $status, $debug = TRUE)
287
+ {
288
+
289
+ $rq = array(
290
+ 'ReqId' => md5(rand()),
291
+ 'MerchantPosId' => OpenPayU_Configuration::getMerchantPosId(),
292
+ 'SessionId' => $sessionId,
293
+ 'OrderStatus' => $status,
294
+ 'Timestamp' => date('c')
295
+ );
296
+
297
+ $result = new OpenPayU_Result();
298
+ $result->setRequest($rq);
299
+
300
+ $url = OpenPayU_Configuration::getServiceUrl() . 'co/openpayu/OrderStatusUpdateRequest';
301
+
302
+ if ($debug)
303
+ OpenPayU::addOutputConsole('OpenPayU endpoint for OrderStatusUpdateRequest message', $url);
304
+
305
+ $oauthResult = OpenPayu_OAuth::accessTokenByClientCredentials();
306
+ OpenPayU::setOpenPayuEndPoint($url . '?oauth_token=' . $oauthResult->getAccessToken());
307
+
308
+ $xml = OpenPayU::buildOrderStatusUpdateRequest($rq);
309
+
310
+ if ($debug)
311
+ OpenPayU::addOutputConsole('OrderStatusUpdateRequest message', htmlentities($xml));
312
+
313
+ $merchantPosId = OpenPayU_Configuration::getMerchantPosId();
314
+ $signatureKey = OpenPayU_Configuration::getSignatureKey();
315
+ $response = OpenPayU::sendOpenPayuDocumentAuth($xml, $merchantPosId, $signatureKey);
316
+
317
+ if ($debug)
318
+ OpenPayU::addOutputConsole('OrderStatusUpdateResponse message', htmlentities($response));
319
+
320
+ // verify response from PayU service
321
+ $status = OpenPayU::verifyOrderStatusUpdateResponseStatus($response);
322
+
323
+ if ($debug)
324
+ OpenPayU::addOutputConsole('OrderStatusUpdateResponse status', serialize($status));
325
+
326
+ $result->setStatus($status);
327
+ $result->setError($status['StatusCode']);
328
+ $result->setMessage($status['StatusDesc']);
329
+ $result->setSuccess($status['StatusCode'] == 'OPENPAYU_SUCCESS' ? TRUE : FALSE);
330
+ $result->setResponse(OpenPayU::parseOpenPayUDocument($response));
331
+
332
+ return $result;
333
+ }
334
+ }
lib/payu/sdk/OpenPayU/Result.php ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ OpenPayU Standard Library
5
+
6
+ @copyright Copyright (c) 2011-2012 PayU
7
+ @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
8
+ http://www.payu.com
9
+ http://openpayu.com
10
+ http://twitter.com/openpayu
11
+ */
12
+
13
+ class OpenPayU_Result
14
+ {
15
+ private $status = '';
16
+ private $error = '';
17
+ private $success = 0;
18
+ private $request = '';
19
+ private $response = '';
20
+ private $sessionId = '';
21
+ private $message = '';
22
+ private $countryCode = '';
23
+ private $reqId = '';
24
+
25
+ /**
26
+ * @access public
27
+ * @return string
28
+ */
29
+ public function getStatus()
30
+ {
31
+ return $this->status;
32
+ }
33
+
34
+ /**
35
+ * @access public
36
+ * @param $value
37
+ */
38
+ public function setStatus($value)
39
+ {
40
+ $this->status = $value;
41
+ }
42
+
43
+ /**
44
+ * @access public
45
+ * @return string
46
+ */
47
+ public function getError()
48
+ {
49
+ return $this->error;
50
+ }
51
+
52
+ /**
53
+ * @access public
54
+ * @param $value
55
+ */
56
+ public function setError($value)
57
+ {
58
+ $this->error = $value;
59
+ }
60
+
61
+ /**
62
+ * @access public
63
+ * @return int
64
+ */
65
+ public function getSuccess()
66
+ {
67
+ return $this->success;
68
+ }
69
+
70
+ /**
71
+ * @access public
72
+ * @param $value
73
+ */
74
+ public function setSuccess($value)
75
+ {
76
+ $this->success = $value;
77
+ }
78
+
79
+ /**
80
+ * @access public
81
+ * @return string
82
+ */
83
+ public function getRequest()
84
+ {
85
+ return $this->request;
86
+ }
87
+
88
+ /**
89
+ * @access public
90
+ * @param $value
91
+ */
92
+ public function setRequest($value)
93
+ {
94
+ $this->request = $value;
95
+ }
96
+
97
+ /**
98
+ * @access public
99
+ * @return string
100
+ */
101
+ public function getResponse()
102
+ {
103
+ return $this->response;
104
+ }
105
+
106
+ /**
107
+ * @access public
108
+ * @param $value
109
+ */
110
+ public function setResponse($value)
111
+ {
112
+ $this->response = $value;
113
+ }
114
+
115
+ /**
116
+ * @access public
117
+ * @return string
118
+ */
119
+ public function getSessionId()
120
+ {
121
+ return $this->sessionId;
122
+ }
123
+
124
+ /**
125
+ * @access public
126
+ * @param $value
127
+ */
128
+ public function setSessionId($value)
129
+ {
130
+ $this->sessionId = $value;
131
+ }
132
+
133
+ /**
134
+ * @access public
135
+ * @return string
136
+ */
137
+ public function getMessage()
138
+ {
139
+ return $this->message;
140
+ }
141
+
142
+ /**
143
+ * @access public
144
+ * @param $value
145
+ */
146
+ public function setMessage($value)
147
+ {
148
+ $this->message = $value;
149
+ }
150
+
151
+ /**
152
+ * @access public
153
+ * @return string
154
+ */
155
+ public function getCountryCode()
156
+ {
157
+ return $this->countryCode;
158
+ }
159
+
160
+ /**
161
+ * @access public
162
+ * @param $value
163
+ */
164
+ public function setCountryCode($value)
165
+ {
166
+ $this->countryCode = $value;
167
+ }
168
+
169
+ /**
170
+ * @access public
171
+ * @return string
172
+ */
173
+ public function getReqId()
174
+ {
175
+ return $this->reqId;
176
+ }
177
+
178
+ /**
179
+ * @access public
180
+ * @param $value
181
+ */
182
+ public function setReqId($value)
183
+ {
184
+ $this->reqId = $value;
185
+ }
186
+
187
+ }
lib/payu/sdk/OpenPayU/ResultOAuth.php ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ OpenPayU Standard Library
5
+
6
+ @copyright Copyright (c) 2011-2012 PayU
7
+ @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
8
+ http://www.payu.com
9
+ http://openpayu.com
10
+ http://twitter.com/openpayu
11
+ */
12
+
13
+ class OpenPayU_ResultOAuth
14
+ {
15
+ private $url = '';
16
+ private $code = '';
17
+ private $accessToken = '';
18
+ private $payuUserEmail = '';
19
+ private $payuUserId = '';
20
+ private $expiresIn = '';
21
+ private $refreshToken = '';
22
+ private $success = '';
23
+ private $error = '';
24
+
25
+ /**
26
+ * @access public
27
+ * @return string
28
+ */
29
+ public function getUrl()
30
+ {
31
+ return $this->url;
32
+ }
33
+
34
+ /**
35
+ * @access public
36
+ * @param $value
37
+ */
38
+ public function setUrl($value)
39
+ {
40
+ $this->url = $value;
41
+ }
42
+
43
+ /**
44
+ * @access public
45
+ * @return string
46
+ */
47
+ public function getCode()
48
+ {
49
+ return $this->code;
50
+ }
51
+
52
+ /**
53
+ * @access public
54
+ * @param $value
55
+ */
56
+ public function setCode($value)
57
+ {
58
+ $this->code = $value;
59
+ }
60
+
61
+ /**
62
+ * @access public
63
+ * @return string
64
+ */
65
+ public function getAccessToken()
66
+ {
67
+ return $this->accessToken;
68
+ }
69
+
70
+ /**
71
+ * @access public
72
+ * @param $value
73
+ */
74
+ public function setAccessToken($value)
75
+ {
76
+ $this->accessToken = $value;
77
+ }
78
+
79
+ /**
80
+ * @access public
81
+ * @return string
82
+ */
83
+ public function getPayuUserEmail()
84
+ {
85
+ return $this->payuUserEmail;
86
+ }
87
+
88
+ /**
89
+ * @access public
90
+ * @param $value
91
+ */
92
+ public function setPayuUserEmail($value)
93
+ {
94
+ $this->payuUserEmail = $value;
95
+ }
96
+
97
+ /**
98
+ * @access public
99
+ * @return string
100
+ */
101
+ public function getPayuUserId()
102
+ {
103
+ return $this->payuUserId;
104
+ }
105
+
106
+ /**
107
+ * @access public
108
+ * @param $value
109
+ */
110
+ public function setPayuUserId($value)
111
+ {
112
+ $this->payuUserId = $value;
113
+ }
114
+
115
+ /**
116
+ * @access public
117
+ * @return string
118
+ */
119
+ public function getExpiresIn()
120
+ {
121
+ return $this->expiresIn;
122
+ }
123
+
124
+ /**
125
+ * @access public
126
+ * @param $value
127
+ */
128
+ public function setExpiresIn($value)
129
+ {
130
+ $this->expiresIn = $value;
131
+ }
132
+
133
+ /**
134
+ * @access public
135
+ * @return string
136
+ */
137
+ public function getRefreshToken()
138
+ {
139
+ return $this->refreshToken;
140
+ }
141
+
142
+ /**
143
+ * @access public
144
+ * @param $value
145
+ */
146
+ public function setRefreshToken($value)
147
+ {
148
+ $this->refreshToken = $value;
149
+ }
150
+
151
+ /**
152
+ * @access public
153
+ * @return string
154
+ */
155
+ public function getSuccess()
156
+ {
157
+ return $this->success;
158
+ }
159
+
160
+ /**
161
+ * @access public
162
+ * @param $value
163
+ */
164
+ public function setSuccess($value)
165
+ {
166
+ $this->success = $value;
167
+ }
168
+
169
+ /**
170
+ * @access public
171
+ * @return string
172
+ */
173
+ public function getError()
174
+ {
175
+ return $this->error;
176
+ }
177
+
178
+ /**
179
+ * @access public
180
+ * @param $value
181
+ */
182
+ public function setError($value)
183
+ {
184
+ $this->error = $value;
185
+ }
186
+
187
+ }
lib/payu/sdk/openpayu.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ ver. 0.1.9
5
+ OpenPayU Standard Library
6
+
7
+ @copyright Copyright (c) 2011-2012 PayU
8
+ @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
9
+ http://www.payu.com
10
+ http://openpayu.com
11
+ http://twitter.com/openpayu
12
+ */
13
+
14
+ include_once('openpayu_domain.php');
15
+
16
+ /*
17
+ these files are obsolete and will be removed in future.
18
+ valid only for SDK 0.0.x
19
+ */
20
+ include_once('OpenPayU/OpenPayUNetwork.php');
21
+ include_once('OpenPayU/OpenPayUBase.php');
22
+ include_once('OpenPayU/OpenPayU.php');
23
+ include_once('OpenPayU/OpenPayUOAuth.php');
24
+
25
+ /*
26
+ these files are 0.1.x compatible
27
+ */
28
+ include_once('OpenPayU/Result.php');
29
+ include_once('OpenPayU/ResultOAuth.php');
30
+ include_once('OpenPayU/Configuration.php');
31
+ include_once('OpenPayU/Order.php');
32
+ include_once('OpenPayU/OAuth.php');
lib/payu/sdk/openpayu_domain.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ OpenPayU Standard Library
5
+
6
+ @copyright Copyright (c) 2011-2012 PayU
7
+ @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
8
+ http://www.payu.com
9
+ http://openpayu.com
10
+ http://twitter.com/openpayu
11
+
12
+ */
13
+
14
+ class OpenPayUDomain
15
+ {
16
+
17
+ private static $msg2domain = null;
18
+
19
+ /**
20
+ * @deprecated
21
+ */
22
+ private static function builder()
23
+ {
24
+ OpenPayUDomain::$msg2domain = array
25
+ (
26
+ 'OrderCreateRequest' => 'OrderDomainRequest',
27
+ 'OrderCreateResponse' => 'OrderDomainResponse',
28
+ 'OrderStatusUpdateRequest' => 'OrderDomainRequest',
29
+ 'OrderStatusUpdateResponse' => 'OrderDomainResponse',
30
+ 'OrderCancelRequest' => 'OrderDomainRequest',
31
+ 'OrderCancelResponse' => 'OrderDomainResponse',
32
+ 'OrderNotifyRequest' => 'OrderDomainRequest',
33
+ 'OrderNotifyResponse' => 'OrderDomainResponse',
34
+ 'OrderRetrieveRequest' => 'OrderDomainRequest',
35
+ 'OrderRetrieveResponse' => 'OrderDomainResponse',
36
+ 'ShippingCostRetrieveRequest' => 'OrderDomainRequest',
37
+ 'ShippingCostRetrieveResponse' => 'OrderDomainResponse'
38
+ );
39
+ }
40
+
41
+ /**
42
+ * Function returns Message domain
43
+ * @param string $msg
44
+ * @access public
45
+ * @return array
46
+ */
47
+ public static function getDomain4Message($msg)
48
+ {
49
+ self::$msg2domain = array
50
+ (
51
+ 'OrderCreateRequest' => 'OrderDomainRequest',
52
+ 'OrderCreateResponse' => 'OrderDomainResponse',
53
+ 'OrderStatusUpdateRequest' => 'OrderDomainRequest',
54
+ 'OrderStatusUpdateResponse' => 'OrderDomainResponse',
55
+ 'OrderCancelRequest' => 'OrderDomainRequest',
56
+ 'OrderCancelResponse' => 'OrderDomainResponse',
57
+ 'OrderNotifyRequest' => 'OrderDomainRequest',
58
+ 'OrderNotifyResponse' => 'OrderDomainResponse',
59
+ 'OrderRetrieveRequest' => 'OrderDomainRequest',
60
+ 'OrderRetrieveResponse' => 'OrderDomainResponse',
61
+ 'ShippingCostRetrieveRequest' => 'OrderDomainRequest',
62
+ 'ShippingCostRetrieveResponse' => 'OrderDomainResponse'
63
+ );
64
+
65
+ return self::$msg2domain[$msg];
66
+ }
67
+ }
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>PayU_Account</name>
4
+ <version>0.1.6.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/LGPL-3.0">LGPL 3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Official PayU payment gateway module.</summary>
10
+ <description>PayU account is a new tool for making payments for items bought in several places on the Internet. By choosing it, you will increase transaction security and speed up the shopping process, as the time of waiting for funds from buyers is reduced to the minimum. The PayU account allows a buyer to define his favourite payment channels as well as save in one place personal and contact details needed to make payment for shopping. If a buyer uses a payment card, he may also save its details on the PayU account and afterwards, pay with one click, while data for delivery will be completed automatically. As a result, a payment is made within not more than a few seconds. An additional functionality for registered users of the PayU account is access to the whole transaction history in shops which have made this payment method available. Moreover, a special searcher allows you to sort items bought by such criteria as: date, transaction status, amount.</description>
11
+ <notes>Changed extension name: PayU_Account was PayU_PayU</notes>
12
+ <authors><author><name>PayU</name><user>PayU</user><email>openpayu@payu.pl</email></author></authors>
13
+ <date>2012-10-10</date>
14
+ <time>13:05:29</time>
15
+ <contents><target name="magelocal"><dir name="PayU"><dir name="Account"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="View.php" hash="d4f667130318272c1b820c7e764d6527"/></dir></dir></dir><file name="Advertisement.php" hash="d059fb8c367c89c6ef79ccabccbfb40c"/><file name="BeforeSummary.php" hash="b0a6dbb2465e4f4f61c8c165534b9368"/><file name="Button.php" hash="3909b68250a1ca92d7377ff634e29871"/><file name="Form.php" hash="f7e93d2deac7c696178030bc039ac02c"/><dir name="Onestep"><file name="Checkout.php" hash="fb82c1a9fa774e19cbe3b8cb6871b84a"/></dir><file name="Redirect.php" hash="e38a6de3a4d30af93cbbe6ec43ed7169"/><file name="UpdateInfo.php" hash="06d659fe8fc89db69d5a3922b35e3c62"/></dir><dir name="Helper"><file name="Data.php" hash="2bfc2993c494eee282a29a7c81b4e137"/></dir><dir name="Model"><dir name="Adminhtml"><dir name="Sales"><file name="Order.php" hash="faf6a7c3551674bbc4050d82b6900ae7"/></dir></dir><file name="Advertisement.php" hash="63d1fcc29921758dff18c26fb25f9cba"/><file name="Button.php" hash="644b1dbf9bb2a341e465667ff61e2dc5"/><file name="Config.php" hash="9dcc3dcf003fa1abf44630d634ec8431"/><file name="Environment.php" hash="3cb491832d6f52db191fc6ee0bdd3299"/><file name="PayU.php" hash="15d9c535370ab799cc0eafe908a24813"/><file name="Payment.php" hash="ec9538ec1c605b16d3d938188f6c2a5d"/><file name="Session.php" hash="a34bd5903030c9cb8b68230dbaab76b7"/><file name="Thumbnail.php" hash="8445d33f12fea85717309b84fdf31798"/><file name="ValidityTime.php" hash="65890cfce821cebb242484c1891b24b0"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Sales"><file name="OrderController.php" hash="9be477892260fd555612558b10de3ae2"/></dir></dir><dir name="Checkout"><file name="CartController.php" hash="c3a77f1fd667b1a21ca9c523964fa140"/></dir><file name="PaymentController.php" hash="4545378300278a0cf4c09fda65568477"/></dir><dir name="etc"><file name="config.xml" hash="e7060eb8584f989183db1ae699758e0e"/><file name="system.xml" hash="8ffc666f06d061ba72a632e65406b5c8"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="payu_account.xml" hash="433c0d85f093a87658cca04fa2dcddd4"/></dir><dir name="template"><dir name="payu_account"><file name="advertisement.phtml" hash="2fc6547dc439c7a5c65b190b0b3bbd26"/><file name="form.phtml" hash="9dd9fd37672b2f249cd5b8701b8ce511"/><dir name="info"><file name="payu_account.phtml" hash="89ff5f164123bad98d94beafd8138532"/></dir><dir name="onestep"><file name="checkout.phtml" hash="e4149c323496f479233b48442ef99212"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="PayU_Account.xml" hash="aa06ac3ab552c6069423bcafd5c0140d"/></dir></target><target name="magelocale"><dir name="pl_PL"><file name="PayU_Account.csv" hash="34fc527b4638b12062a17e8fa35a9565"/></dir></target><target name="magelib"><dir name="payu"><dir name="sdk"><dir name="OpenPayU"><file name="Configuration.php" hash="247d5b8eee40df9f2328e44a513b302d"/><file name="OAuth.php" hash="22a906bd9ffd37a7f9720ac12efd3117"/><file name="OpenPayU.php" hash="4013d4d8aaa4b985a2a26e01ee97312d"/><file name="OpenPayUBase.php" hash="8ff7b263a1463d749fc14c5b5f02659c"/><file name="OpenPayUNetwork.php" hash="a6090839643a7279459f358ae2a0e410"/><file name="OpenPayUOAuth.php" hash="701a2c75af0b9f0df8471e7f108e389a"/><file name="Order.php" hash="20f94d108ab5d27c3ec3fbef3d647729"/><file name="Result.php" hash="6ad2be85b87dfc7410c11ed3a507079e"/><file name="ResultOAuth.php" hash="b7ac42eb16a0be6bd38f3b3310025a5b"/></dir><file name="openpayu.php" hash="04068271490f87c9bdd7f280c5da34d6"/><file name="openpayu_domain.php" hash="b38e5963a8ad5e515bca8864851722d6"/></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>5.4.7</max></php></required></dependencies>
18
+ </package>