Completed
Branch master (741ff8)
by Nikita
02:08
created

Mygento_Payture_ApiController::frameAction()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 29
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 29
rs 6.7272
cc 7
eloc 22
nc 6
nop 0
1
<?php
2
3
/**
4
 *
5
 *
6
 * @category Mygento
7
 * @package Mygento_Payture
8
 * @copyright Copyright © 2016 NKS LLC. (http://www.mygento.ru)
9
 */
10
class Mygento_Payture_ApiController extends Mage_Core_Controller_Front_Action
11
{
12
13
    public function indexAction()
14
    {
15
        $this->getResponse()->setBody('Nope. Visit <a href="http://www.mygento.ru/">Magento development</a>');
16
    }
17
18
    public function frameAction()
19
    {
20
        if ($this->getRequest()->isPost()) {
21
            $postData = Mage::app()->getRequest()->getPost();
22
            if (!Mage::getModel('payture/payture')->checkSign($postData['orderid'], $postData['hash'])) {
23
                $this->response->statusCode(401);
24
                return $this->response;
25
            }
26
            $order_id = $postData['orderid'];
27
            $order = Mage::getModel('sales/order')->load($order_id);
28
            if (!$order || !$order->getId()) {
29
                return false;
30
            }
31
            if (!$order->canInvoice()) {
32
                return false;
33
            }
34
            $code = $order->getPayment()->getMethodInstance()->getCode();
35
            if (!$code == 'payture') {
36
                return false;
37
            }
38
            $url2go = Mage::helper('payture')->getLink($order->getId());
39
            Mage::register('payture_frame_link', $url2go);
40
            $this->loadLayout();
41
            $this->renderLayout();
42
        } else {
43
            $this->response->statusCode(500);
44
            return $this->response;
45
        }
46
    }
47
}
48