1
|
|
|
<?php |
2
|
|
|
namespace Pagantis\Pagantis\Controller\Payment; |
3
|
|
|
|
4
|
|
|
use Magento\Framework\App\Action\Action; |
5
|
|
|
use Magento\Framework\View\Element\BlockInterface; |
6
|
|
|
use Magento\Framework\App\ResourceConnection; |
7
|
|
|
use Magento\Framework\DB\Ddl\Table; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Iframe |
11
|
|
|
* @package Pagantis\Pagantis\Controller\Payment |
12
|
|
|
*/ |
13
|
|
|
class Iframe extends Action |
14
|
|
|
{ |
15
|
|
|
/** Concurrency tablename */ |
16
|
|
|
const LOGS_TABLE = 'Pagantis_logs'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \Magento\Framework\View\Result\PageFactory |
20
|
|
|
*/ |
21
|
|
|
protected $_pageFactory; |
22
|
|
|
|
23
|
|
|
/** @var ResourceConnection $dbObject */ |
24
|
|
|
protected $dbObject; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Iframe constructor. |
28
|
|
|
* |
29
|
|
|
* @param \Magento\Framework\App\Action\Context $context |
30
|
|
|
* @param \Magento\Framework\View\Result\PageFactory $pageFactory |
31
|
|
|
* @param ResourceConnection $dbObject |
32
|
|
|
* @param \Pagantis\Pagantis\Helper\Config $pagantisConfig |
33
|
|
|
*/ |
34
|
|
|
public function __construct( |
35
|
|
|
\Magento\Framework\App\Action\Context $context, |
36
|
|
|
\Magento\Framework\View\Result\PageFactory $pageFactory, |
37
|
|
|
ResourceConnection $dbObject, |
38
|
|
|
\Pagantis\Pagantis\Helper\Config $pagantisConfig |
39
|
|
|
) { |
40
|
|
|
$this->_pageFactory = $pageFactory; |
41
|
|
|
$this->dbObject = $dbObject; |
42
|
|
|
$this->config = $pagantisConfig->getConfig(); |
|
|
|
|
43
|
|
|
return parent::__construct($context); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|\Magento\Framework\View\Result\Page |
48
|
|
|
* @throws \Zend_Db_Exception |
49
|
|
|
*/ |
50
|
|
|
public function execute() |
51
|
|
|
{ |
52
|
|
|
try { |
53
|
|
|
$resultPage = $this->_pageFactory->create(); |
54
|
|
|
$orderId = $this->getRequest()->getParam('orderId'); |
55
|
|
|
if ($orderId == '') { |
56
|
|
|
throw new \Exception('Empty orderId'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if ($this->config['pagantis_public_key'] == '' || $this->config['pagantis_private_key'] == '') { |
60
|
|
|
throw new \Exception('Public and Secret Key not found'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$orderClient = new \Pagantis\OrdersApiClient\Client( |
64
|
|
|
$this->config['pagantis_public_key'], |
65
|
|
|
$this->config['pagantis_private_key'] |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$order = $orderClient->getOrder($orderId); |
69
|
|
|
|
70
|
|
|
/** @var \Pagantis\Pagantis\Block\Payment\Iframe $block */ |
71
|
|
|
$block = $resultPage->getLayout()->getBlock('pagantis_payment_iframe'); |
72
|
|
|
$block |
73
|
|
|
->setEmail($order->getUser()->getEmail()) |
74
|
|
|
->setOrderUrl($order->getActionUrls()->getForm()) |
75
|
|
|
->setCheckoutUrl($order->getConfiguration()->getUrls()->getCancel()) |
76
|
|
|
; |
77
|
|
|
|
78
|
|
|
return $resultPage; |
79
|
|
|
} catch (\Exception $exception) { |
80
|
|
|
$this->insertLog($exception); |
81
|
|
|
die($exception->getMessage()); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return void|\Zend_Db_Statement_Interface |
87
|
|
|
* @throws \Zend_Db_Exception |
88
|
|
|
*/ |
89
|
|
|
private function checkDbLogTable() |
90
|
|
|
{ |
91
|
|
|
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ |
92
|
|
|
$dbConnection = $this->dbObject->getConnection(); |
93
|
|
|
$tableName = $this->dbObject->getTableName(self::LOGS_TABLE); |
94
|
|
|
if (!$dbConnection->isTableExists($tableName)) { |
95
|
|
|
$table = $dbConnection |
96
|
|
|
->newTable($tableName) |
97
|
|
|
->addColumn('id', Table::TYPE_SMALLINT, null, array('nullable'=>false, 'auto_increment'=>true, 'primary'=>true)) |
98
|
|
|
->addColumn('log', Table::TYPE_TEXT, null, array('nullable'=>false)) |
99
|
|
|
->addColumn('createdAt', Table::TYPE_TIMESTAMP, null, array('nullable'=>false, 'default'=>TIMESTAMP_INIT)); |
|
|
|
|
100
|
|
|
return $dbConnection->createTable($table); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param $exceptionMessage |
108
|
|
|
* |
109
|
|
|
* @throws \Zend_Db_Exception |
110
|
|
|
*/ |
111
|
|
|
private function insertLog($exceptionMessage) |
112
|
|
|
{ |
113
|
|
|
if ($exceptionMessage instanceof \Exception) { |
114
|
|
|
$this->checkDbLogTable(); |
115
|
|
|
$logObject = new \stdClass(); |
116
|
|
|
$logObject->message = $exceptionMessage->getMessage(); |
117
|
|
|
$logObject->code = $exceptionMessage->getCode(); |
118
|
|
|
$logObject->line = $exceptionMessage->getLine(); |
119
|
|
|
$logObject->file = $exceptionMessage->getFile(); |
120
|
|
|
$logObject->trace = $exceptionMessage->getTraceAsString(); |
121
|
|
|
|
122
|
|
|
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ |
123
|
|
|
$dbConnection = $this->dbObject->getConnection(); |
124
|
|
|
$tableName = $this->dbObject->getTableName(self::LOGS_TABLE); |
125
|
|
|
$dbConnection->insert($tableName, array('log' => json_encode($logObject))); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|