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_Adminhtml_Payture_IndexController extends Mage_Adminhtml_Controller_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 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 = Mage::helper('payture')->getData($url); |
31
|
|
|
Mage::helper('payture')->addLog($xml); |
32
|
|
|
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
|
|
|
//Check the ticket |
42
|
|
|
Mage::helper('payture')->checkTicket($item); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
$url = Mage::helper("adminhtml")->getUrl("adminhtml/sales_order/view", array('_secure' => true, 'order_id' => $order->getId())); |
46
|
|
|
Mage::app()->getResponse()->setRedirect($url); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function unblockAction() |
50
|
|
|
{ |
51
|
|
|
$order_inc_id = $this->getRequest()->getParam('order'); |
52
|
|
|
$postData = Mage::app()->getRequest()->getPost(); |
53
|
|
|
|
54
|
|
|
$redirectLink = $this->processOrder('Unblock', $postData, $order_inc_id); |
55
|
|
|
|
56
|
|
|
//Check the ticket |
57
|
|
|
$collection = Mage::getModel('payture/keys')->getCollection(); |
58
|
|
|
$collection->addFieldToFilter('orderid', $order_inc_id); |
59
|
|
|
$ticket = $collection->getFirstItem(); |
60
|
|
|
|
61
|
|
|
if ($ticket && $ticket->getId()) { |
62
|
|
|
Mage::helper('payture')->checkTicket($ticket); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
Mage::app()->getResponse()->setRedirect($redirectLink); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function refundAction() |
69
|
|
|
{ |
70
|
|
|
$order_inc_id = $this->getRequest()->getParam('order'); |
71
|
|
|
$postData = Mage::app()->getRequest()->getPost(); |
72
|
|
|
Mage::app()->getResponse()->setRedirect($this->processOrder('Refund', $postData, $order_inc_id)); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function processOrder($type, $postData, $order_inc_id) |
76
|
|
|
{ |
77
|
|
|
$order = Mage::getModel('sales/order')->load($order_inc_id); |
78
|
|
|
if ($order->getId() && $postData['sum']) { |
79
|
|
|
$req = array( |
80
|
|
|
'Key' => Mage::helper('payture')->getKey(), |
81
|
|
|
'OrderId' => $order->getId(), |
82
|
|
|
'Password' => Mage::helper('payture')->getPassword(), |
83
|
|
|
'Amount' => round($postData['sum'] * 100, 0), |
84
|
|
|
// @codingStandardsIgnoreStart |
85
|
|
|
'Cheque' => base64_encode(Mage::helper('payture')->getOrderItemsJson($order)) |
86
|
|
|
// @codingStandardsIgnoreEnd |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
Mage::helper('payture')->processTransaction($type, $req, $order); |
90
|
|
|
} |
91
|
|
|
return Mage::helper("adminhtml")->getUrl("adminhtml/sales_order/view", array('_secure' => true, 'order_id' => $order->getId())); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
protected function _isAllowed() |
95
|
|
|
{ |
96
|
|
|
return Mage::getSingleton('admin/session')->isAllowed('mygento/payture'); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|