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 |
|
|
|
|
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') { |
|
|
|
|
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') { |
|
|
|
|
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
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.