-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcardlink.php
228 lines (197 loc) · 9.06 KB
/
cardlink.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
/**
* @package Cardlink Payment Helper
* @version 4.2
* @company Cardlink
* @developer Cardlink
* @link http://www.cardlink.gr
* @copyright Copyright (C) 2022 Cardlink All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
defined('_JEXEC') or die('Restricted access');
// if (!class_exists('vmDefines')) {
// require_once (JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_virtuemart' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'vmdefines.php');
// vmDefines::defines('site');
// }
// if (!class_exists('vmPlugin')) {
// require_once (JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_virtuemart' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'vmplugin.php');
// }
// if (!class_exists('vmPSPlugin')) {
// require_once (JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_virtuemart' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'vmpsplugin.php');
// }
use Joomla\Database\DatabaseInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\Folder;
use Joomla\Plugin\CMSPlugin;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Router\ApiRouter;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Router\Router;
class plgSystemCardlink extends JPlugin
{
protected $debug = array();
protected $isNotify = 0;
protected $replacements = array();
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
}
public function onAfterInitialise()
{
$app = Factory::getApplication();
if ($app->isClient('admin')) {
return;
}
$session = $app->getSession();
$component = $app->input->get->get('com', '');
$option = $app->input->get->get('option', '');
$paymentMethod = $app->input->get->get('type', '');
$paymentStatus = $app->input->get->get('status', '');
$layout = $app->input->get->get('layout', '');
$actions = array('ok' => 'pluginresponsereceived', 'cancel' => 'pluginUserPaymentCancel', 'notify' => 'pluginNotification', 'none' => null);
$components = array('cardlink' => 'com_virtuemart');
$paymentMethodsList = array('card' => 'cardlinkcard', 'iris' => 'cardlinkiris');
$task = $paymentStatus;
if ($layout == 'orderdone') {
$app->allowCache(false);
$app->set('caching', 0);
}
if ($option == 'com_ajax') {
require_once (JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_virtuemart' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'vmdefines.php');
vmDefines::defines('site');
require_once (JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_virtuemart' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'vmplugin.php');
require_once (JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_virtuemart' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'vmpsplugin.php');
}
if (
(array_key_exists($paymentMethod, $paymentMethodsList) || in_array($paymentMethod, $paymentMethodsList))
&& (array_key_exists($component, $components) || in_array($option, $components))
&& $app->input->get('t') == 'checkout'
) {
$html = $session->get('cardlink_checkouthtml', null);
if (!empty($html)) {
echo '<!DOCTYPE html>
<html xmlns="//www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Redirecting to payment gateway...</title>
</head>
<body>
' . $html . '
</body>
</html>';
$session->set('cardlink_checkouthtml', '');
} else {
echo 'There was a problem with your request, please contact with us or go back to your order and try again.';
}
$app->close();
}
if (
(array_key_exists($paymentMethod, $paymentMethodsList) || in_array($paymentMethod, $paymentMethodsList))
&& (array_key_exists($component, $components) || in_array($option, $components))
&& count($_REQUEST) > 2
) {
$this->isNotify = 1;
if (array_key_exists($paymentMethod, $paymentMethodsList)) {
$paymentMethod = $paymentMethodsList[$paymentMethod];
}
if (array_key_exists($component, $components)) {
$option = $components[$component];
$this->setVar('option', $option);
}
if ($this->params->get('disablesef', 0)) {
$params = $app->getParams();
$params->set('sef', 0);
}
if ($option == 'com_virtuemart') {
$view = is_dir(JPATH_SITE . '/components/com_virtuemart/views/pluginresponse') ? 'pluginresponse' : 'vmplg';
$this->setVar('view', $view);
$this->setVar('task', isset($actions[$task]) ? $actions[$task] : $task);
if ($task == 'notify') {
$this->setVar('tmpl', 'component');
}
$orderid = $app->input->getCmd('oid', '');
$onumber = $app->input->getCmd('on', '');
if (empty($onumber) && $orderid) {
$app->input->set('on', $orderid);
}
}
$Itemid = (int) $this->params->get('Itemid', 0);
if ($Itemid) {
$this->setVar('Itemid', $Itemid);
}
$lang = $this->params->get('lang');
if (!empty($lang)) {
$this->setVar('lang', $lang);
}
if (method_exists($app, 'getRouter') && $this->params->get('router', 0)) {
$this->debug[] = 'Router Attached';
$router = Factory::getContainer()->get(ApiRouter::class);
$router->attachBuildRule(array($this, 'preprocessBuildRule'), Router::PROCESS_BEFORE);
}
}
}
protected function setVar($var, $value = NULL)
{
$app = Factory::getApplication();
$this->replacements[$var] = $_REQUEST[$var] = $_GET[$var] = $value;
$app->input->set($var, $value);
$this->debug[] = 'Var set ' . $var . '=' . $value;
}
public function onAfterRoute()
{
$app = Factory::getApplication();
if ($this->params->get('debug', 0)) {
$app->enqueueMessage('Router Vars:' . print_r(Factory::getContainer()->get(ApiRouter::class)->getVars(), true));
}
}
public function onAfterRender()
{
$app = Factory::getApplication();
if ($app->isClient('admin') || !$this->isNotify) {
return;
}
$session = $app->getSession();
$router = Factory::getContainer()->get(ApiRouter::class);
$redirectURL = $session->get('cardlink_redirect', null);
if ($this->params->get('debug', 0)) {
$buffer = Factory::getApplication()->getBody();
$debug = '<p>CARDLINK PLUGIN DEBUG</p>';
$debug .= '<p>Debug:<br/>' . implode("\n<br/>", $this->debug) . '</p>';
$debug .= '<p>Router:<br/><pre>' . print_r($router->getVars(), true) . '</pre></p>';
if (!empty($redirectURL)) {
$debug .= '<p>Redirect URL:' . Route::_($redirectURL) . '</p>';
}
$debug .= '<p>Option:' . $app->input->get('option') . ' View:' . $app->input->get('view') . ' Task:' . $app->input->get('task') . ' Lang:' . $app->input->get('lang') . ' Itemid:' . $app->input->get('Itemid') . '</p>';
$debug .= '<p>$_GET: <pre>' . print_r($_GET, true) . '</pre></p>';
$debug .= '<p>$_POST: <pre>' . print_r($_POST, true) . '</pre></p>';
$app->setBody(str_replace('</body>', $debug . '</body>', $buffer));
}
if (!$this->params->get('debug', 0) && !empty($redirectURL)) {
$session->set('cardlink_redirect', null);
$app->redirect(Route::_($redirectURL));
$app->close();
}
}
public function preprocessBuildRule(&$router, &$uri)
{
//$router->setVars($this->replacements);
foreach ($this->replacements as $k => $v) {
$uri->setVar($k, $v);
$router->setVar($k, $v);
}
$uri->delVar('b');
$uri->delVar('virtuemart_manufacturer_id');
$uri->delVar('virtuemart_category_id');
}
public function getOrderByID($virtuemart_order_id)
{
if (method_exists($this, 'getDatasByOrderId')) {
return $this->getDatasByOrderId($virtuemart_order_id);
}
$db = Factory::getContainer()->get(DatabaseInterface::class);
$q = 'SELECT * FROM `#__virtuemart_orders` '
. 'WHERE `order_number` = "' . $virtuemart_order_id . '" ';
$db->setQuery($q);
return $db->loadObjectList();
}
}