Completed
Push — master ( 39b1fc...a5c199 )
by Nikita
02:03
created

processOrder()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 26
Code Lines 21

Duplication

Lines 9
Ratio 34.62 %
Metric Value
dl 9
loc 26
rs 8.5806
cc 4
eloc 21
nc 3
nop 3
1
<?php
2
3
/**
4
 *
5
 *
6
 * @category Mygento
7
 * @package Mygento_Payture
8
 * @copyright Copyright © 2015 NKS LLC. (http://www.mygento.ru)
9
 */
10
class Mygento_Payture_Adminhtml_Payture_IndexController extends Mage_Adminhtml_Controller_Action
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
13
    public function indexAction()
14
    {
15
        echo 'Nope. Visit <a href="http://www.mygento.ru/">Magento development</a>';
16
    }
17
18
    public function completeAction()
19
    {
20
        $order_inc_id = $this->getRequest()->getParam('order');
21
        $order = Mage::getModel('sales/order')->load($order_inc_id);
22
        if ($order->getId()) {
23
            $req = array(
24
                'Key' => Mage::helper('payture')->getKey(),
25
                'OrderId' => $order->getId(),
26
                'Password' => Mage::helper('payture')->getPassword(),
27
            );
28
            $url = Mage::helper('payture')->getHost() . 'Charge?' . http_build_query($req);
29
            Mage::helper('payture')->addLog($url);
30
            $xml = simplexml_load_file($url);
31
            Mage::helper('payture')->addLog($xml);
32 View Code Duplication
            if ($xml["Success"] == 'True') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
                $collection = Mage::getModel('payture/keys')->getCollection();
34
                $collection->addFieldToFilter('orderid', $order->getId());
35
                $item = $collection->getFirstItem();
36
                $sess = Mage::getModel('payture/keys')->load($item->getId());
37
                $sess->setState('Complete');
38
                $sess->save();
39
                Mage::helper('payture')->addTransaction($order);
40
            }
41
        }
42
        $url = Mage::helper("adminhtml")->getUrl("adminhtml/sales_order/view", array('_secure' => true, 'order_id' => $order->getId()));
43
        Mage::app()->getResponse()->setRedirect($url);
44
    }
45
46
    public function unblockAction()
47
    {
48
        $order_inc_id = $this->getRequest()->getParam('order');
49
        $postData = Mage::app()->getRequest()->getPost();
50
        Mage::app()->getResponse()->setRedirect($this->processOrder('Unblock', $postData, $order_inc_id));
51
    }
52
53
    public function refundAction()
54
    {
55
        $order_inc_id = $this->getRequest()->getParam('order');
56
        $postData = Mage::app()->getRequest()->getPost();
57
        Mage::app()->getResponse()->setRedirect($this->processOrder('Refund', $postData, $order_inc_id));
58
    }
59
60
    private function processOrder($type, $postData, $order_inc_id)
61
    {
62
        $order = Mage::getModel('sales/order')->load($order_inc_id);
63
        if ($order->getId() && $postData['sum']) {
64
            $req = array(
65
                'Key' => Mage::helper('payture')->getKey(),
66
                'OrderId' => $order->getId(),
67
                'Password' => Mage::helper('payture')->getPassword(),
68
                'Amount' => round($postData['sum'] * 100, 0),
69
            );
70
            $url = Mage::helper('payture')->getHost() . $type . '?' . http_build_query($req);
71
            Mage::helper('payture')->addLog($url);
72
            $xml = simplexml_load_file($url);
73
            Mage::helper('payture')->addLog($xml);
74 View Code Duplication
            if ($xml["Success"] == 'True') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
                $collection = Mage::getModel('payture/keys')->getCollection();
76
                $collection->addFieldToFilter('orderid', $order->getId());
77
                $item = $collection->getFirstItem();
78
                $sess = Mage::getModel('payture/keys')->load($item->getId());
79
                $sess->setState($type . 'ed');
80
                $sess->save();
81
                Mage::helper('payture')->addTransaction($order);
82
            }
83
        }
84
        return Mage::helper("adminhtml")->getUrl("adminhtml/sales_order/view", array('_secure' => true, 'order_id' => $order->getId()));
85
    }
86
87
    protected function _isAllowed()
88
    {
89
        return true;
90
    }
91
}
92