1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Pagantis\ModuleUtils\Exception\OrderNotFoundException; |
4
|
|
|
use Pagantis\OrdersApiClient\Model\Order\User\Address; |
5
|
|
|
use Pagantis\ModuleUtils\Exception\UnknownException; |
6
|
|
|
|
7
|
|
|
define('TABLE_PAGANTIS_LOG', 'pagantis_log'); |
8
|
|
|
define('TABLE_PAGANTIS_CONFIG', 'pagantis_config'); |
9
|
|
|
define('TABLE_PAGANTIS_ORDERS', 'pagantis_order'); |
10
|
|
|
define('TABLE_PAGANTIS_CONCURRENCY', 'pagantis_concurrency'); |
11
|
|
|
define('__ROOT__', dirname(dirname(__FILE__))); |
12
|
|
|
|
13
|
|
|
class pagantis |
14
|
|
|
{ |
15
|
|
|
/** @var String $is_guest */ |
16
|
|
|
public $is_guest; |
17
|
|
|
|
18
|
|
|
/** @var Array $extraConfig */ |
19
|
|
|
public $extraConfig; |
20
|
|
|
|
21
|
|
|
/** @var String $form_action_url */ |
22
|
|
|
public $form_action_url; |
23
|
|
|
|
24
|
|
|
/** @var String $base_url */ |
25
|
|
|
public $base_url; |
26
|
|
|
|
27
|
|
|
/** @var String $os_order_reference */ |
28
|
|
|
public $os_order_reference; |
29
|
|
|
|
30
|
|
|
/** @var notifyController $pgNotify */ |
31
|
|
|
public $pgNotify; |
32
|
|
|
|
33
|
|
|
public $defaultConfigs = array( |
34
|
|
|
'PAGANTIS_TITLE' => 'Instant Financing', |
35
|
|
|
'PAGANTIS_SIMULATOR_DISPLAY_TYPE' => 'pgSDK.simulator.types.SIMPLE', |
36
|
|
|
'PAGANTIS_SIMULATOR_DISPLAY_SKIN' => 'pgSDK.simulator.skins.BLUE', |
37
|
|
|
'PAGANTIS_SIMULATOR_DISPLAY_POSITION' => 'hookDisplayProductButtons', |
38
|
|
|
'PAGANTIS_SIMULATOR_START_INSTALLMENTS' => 3, |
39
|
|
|
'PAGANTIS_SIMULATOR_MAX_INSTALLMENTS' => 12, |
40
|
|
|
'PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR' => 'default', |
41
|
|
|
'PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION' => 'pgSDK.simulator.positions.INNER', |
42
|
|
|
'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR' => 'default', |
43
|
|
|
'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR' => 'default', |
44
|
|
|
'PAGANTIS_DISPLAY_MIN_AMOUNT' => 1, |
45
|
|
|
'PAGANTIS_URL_OK' => '', |
46
|
|
|
'PAGANTIS_URL_KO' => '', |
47
|
|
|
'PAGANTIS_TITLE_EXTRA' => 'Paga hasta en 12 cómodas cuotas con Paga+Tarde. Solicitud totalmente online y sin papeleos,¡y la respuesta es inmediata!' |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Constructor |
52
|
|
|
*/ |
53
|
|
|
public function __construct() |
54
|
|
|
{ |
55
|
|
|
$this->version = '8.0.0'; |
|
|
|
|
56
|
|
|
$this->code = 'pagantis'; |
|
|
|
|
57
|
|
|
$this->sort_order = 0; |
|
|
|
|
58
|
|
|
|
59
|
|
|
if (strpos($_SERVER[REQUEST_URI], "checkout_payment.php") <= 0) { |
|
|
|
|
60
|
|
|
$this->title = MODULE_PAYMENT_PAGANTIS_TEXT_ADMIN_TITLE; // Payment module title in Admin |
|
|
|
|
61
|
|
|
} else { |
62
|
|
|
$this->title = MODULE_PAYMENT_PAGANTIS_TEXT_CATALOG_TITLE; // Payment module title in Catalog |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$this->enabled = ((MODULE_PAYMENT_PAGANTIS_STATUS == 'True') ? true : false); |
|
|
|
|
66
|
|
|
|
67
|
|
|
$this->extraConfig = $this->getExtraConfig(); |
68
|
|
|
|
69
|
|
|
$this->base_url = dirname( |
70
|
|
|
sprintf( |
71
|
|
|
"%s://%s%s%s", |
72
|
|
|
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', |
73
|
|
|
$_SERVER['SERVER_NAME'], |
74
|
|
|
isset($_SERVER['SERVER_PORT']) ? ":" . $_SERVER['SERVER_PORT'] : '', |
75
|
|
|
$_SERVER['REQUEST_URI'] |
76
|
|
|
) |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$this->form_action_url = $this->base_url . '/ext/modules/payment/pagantis/bypass.php'; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/*************** |
83
|
|
|
* |
84
|
|
|
* CLASS METHODS |
85
|
|
|
* |
86
|
|
|
**************/ |
87
|
|
|
/** |
88
|
|
|
* Here you can implement using payment zones (refer to standard PayPal module as reference) |
89
|
|
|
*/ |
90
|
|
|
public function update_status() |
91
|
|
|
{ |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/* |
96
|
|
|
* Here you may define client side javascript that will verify any input fields you use in the payment method |
97
|
|
|
* selection page. Refer to standard cc module as reference (cc.php). |
98
|
|
|
*/ |
99
|
|
|
public function javascript_validation() |
100
|
|
|
{ |
101
|
|
|
return false; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/* |
105
|
|
|
* Llamada cuando el usuario esta en la pantalla de eleccion de tipo de pago |
106
|
|
|
* This function outputs the payment method title/text and if required, the input fields. |
107
|
|
|
* |
108
|
|
|
* Si hay un pedido generado previamente y no confirmado, se borra |
109
|
|
|
* Caso de uso: |
110
|
|
|
* - el usuario llega a la pantalla de confirmacion |
111
|
|
|
* - se genera el pedido (pero no se genera entrada en orders_status_history) |
112
|
|
|
* - el usuario decide realizar algun cambio en su compra antes de pasar a pagantis |
113
|
|
|
* - entra de nuevo en la pantalla de seleccion de tipo de pago (puede elegir otra forma de pago) |
114
|
|
|
* - se comprueba que no exista el pedido generado anteriormente |
115
|
|
|
* - se borra el pedido que se habia generado inicialmente. Ya no es valido |
116
|
|
|
* |
117
|
|
|
*/ |
118
|
|
|
public function selection() |
119
|
|
|
{ |
120
|
|
|
return array('id' => $this->code, 'module' => $this->title); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/* |
124
|
|
|
* Use this function implement any checks of any conditions after payment method has been selected. You most probably |
125
|
|
|
* don't need to implement anything here. |
126
|
|
|
*/ |
127
|
|
|
public function pre_confirmation_check() |
128
|
|
|
{ |
129
|
|
|
return false; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/* |
133
|
|
|
* Implement any checks or processing on the order information before proceeding to payment confirmation. You most |
134
|
|
|
probably don't need to implement anything here. |
135
|
|
|
* Llamada cuando el usuario entra en la pantalla de confirmacion |
136
|
|
|
* |
137
|
|
|
* Se genera el pedido: |
138
|
|
|
* - con el estado predefinido para el modulo pagantis |
139
|
|
|
* - sin notificacion a cliente ni administrador |
140
|
|
|
* - no se borra el carrito asociado al pedido |
141
|
|
|
* |
142
|
|
|
*/ |
143
|
|
|
public function confirmation() |
144
|
|
|
{ |
145
|
|
|
return false; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen. |
150
|
|
|
* This sends the data to the payment gateway for processing. |
151
|
|
|
* (These are hidden fields on the checkout confirmation page) |
152
|
|
|
*/ |
153
|
|
|
public function process_button() |
154
|
|
|
{ |
155
|
|
|
try { |
156
|
|
|
include_once('./ext/modules/payment/pagantis/vendor/autoload.php'); |
157
|
|
|
global $order, $customer_id, $sendto, $billto, $cart, $languages_id, $currency, $currencies, $shipping, |
158
|
|
|
$payment, $comments, $customer_default_address_id, $cartID; |
159
|
|
|
$global_vars = array(); |
160
|
|
|
$global_vars['customer_id'] = serialize($customer_id); |
161
|
|
|
$global_vars['sendTo'] = serialize($sendto); |
162
|
|
|
$global_vars['billTo'] = serialize($billto); |
163
|
|
|
$global_vars['cart'] = serialize($cart); |
164
|
|
|
$global_vars['languages_id'] = serialize($languages_id); |
165
|
|
|
$global_vars['currency'] = serialize($currency); |
166
|
|
|
$global_vars['currencies'] = serialize($currencies); |
167
|
|
|
$global_vars['shipping'] = serialize($shipping); |
168
|
|
|
$global_vars['payment'] = serialize($payment); |
169
|
|
|
$global_vars['comments'] = serialize($comments); |
170
|
|
|
$global_vars['$customer_default_address_id'] = serialize($customer_default_address_id); |
171
|
|
|
$global_vars['cartID'] = serialize($cartID); |
172
|
|
|
$global_vars['sessiontoken'] = serialize($_SESSION['sessiontoken']); |
173
|
|
|
|
174
|
|
|
if (!isset($order)) { |
175
|
|
|
throw new UnknownException("Order not found"); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
$id_hash = time() . serialize($order->products) . '' . serialize($order->customer) . '' . serialize($order->delivery); |
179
|
|
|
$this->os_order_reference = md5($id_hash); |
180
|
|
|
$_SESSION['order_id'] = $this->os_order_reference; |
181
|
|
|
|
182
|
|
|
$userAddress = new Address(); |
183
|
|
|
$userAddress |
184
|
|
|
->setZipCode($order->billing['postcode']) |
185
|
|
|
->setFullName($order->billing['firstname'] . ' ' . $order->billing['lastname']) |
186
|
|
|
->setCountryCode('ES') |
187
|
|
|
->setCity($order->billing['city']) |
188
|
|
|
->setAddress($order->billing['street_address']) |
189
|
|
|
->setFixPhone($order->customer['telephone']) |
190
|
|
|
->setMobilePhone($order->customer['telephone']); |
191
|
|
|
|
192
|
|
|
$orderBillingAddress = $userAddress; |
193
|
|
|
|
194
|
|
|
$orderShippingAddress = new Address(); |
195
|
|
|
$orderShippingAddress |
196
|
|
|
->setZipCode($order->delivery['postcode']) |
197
|
|
|
->setFullName($order->billing['firstname'] . ' ' . $order->billing['lastname']) |
198
|
|
|
->setCountryCode('ES') |
199
|
|
|
->setCity($order->delivery['city']) |
200
|
|
|
->setAddress($order->delivery['street_address']) |
201
|
|
|
->setFixPhone($order->customer['telephone']) |
202
|
|
|
->setMobilePhone($order->customer['telephone']); |
203
|
|
|
|
204
|
|
|
$orderUser = new \Pagantis\OrdersApiClient\Model\Order\User(); |
205
|
|
|
$orderUser |
206
|
|
|
->setAddress($userAddress) |
207
|
|
|
->setFullName($order->billing['firstname'] . ' ' . $order->billing['lastname']) |
208
|
|
|
->setBillingAddress($orderBillingAddress) |
209
|
|
|
->setEmail($order->customer['email_address']) |
210
|
|
|
->setFixPhone($order->customer['telephone']) |
211
|
|
|
->setMobilePhone($order->customer['telephone']) |
212
|
|
|
->setShippingAddress($orderShippingAddress); |
213
|
|
|
|
214
|
|
|
$previousOrders = $this->getOrders(); |
215
|
|
|
foreach ((array)$previousOrders as $k => $previousOrder) { |
216
|
|
|
$orderHistory = new \Pagantis\OrdersApiClient\Model\Order\User\OrderHistory(); |
217
|
|
|
$orderHistory |
218
|
|
|
->setAmount(intval(100 * $previousOrder['value'])) |
219
|
|
|
->setDate(new \DateTime($previousOrder['date_purchased'])); |
|
|
|
|
220
|
|
|
$orderUser->addOrderHistory($orderHistory); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
$details = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details(); |
224
|
|
|
$shippingCost = number_format($order->info['shipping_cost'], 2, '.', ''); |
225
|
|
|
$details->setShippingCost(intval(strval(100 * $shippingCost))); |
226
|
|
|
foreach ($order->products as $item) { |
227
|
|
|
$product = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details\Product(); |
228
|
|
|
$product |
229
|
|
|
->setAmount(intval(100 * number_format(($item['final_price'] * $item['qty']), 2))) |
230
|
|
|
->setQuantity(intval($item['qty'])) |
231
|
|
|
->setDescription($item['name']); |
232
|
|
|
$details->addProduct($product); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
$orderShoppingCart = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart(); |
236
|
|
|
$orderShoppingCart |
237
|
|
|
->setDetails($details) |
238
|
|
|
->setOrderReference($this->os_order_reference) |
239
|
|
|
->setPromotedAmount(0) |
240
|
|
|
->setTotalAmount(intval($order->info['total'] * 100)); |
241
|
|
|
|
242
|
|
|
$callback_url = $this->base_url . '/ext/modules/payment/pagantis/notify.php'; |
243
|
|
|
$checkoutProcessUrl = htmlspecialchars_decode |
244
|
|
|
( |
245
|
|
|
tep_href_link( |
|
|
|
|
246
|
|
|
FILENAME_CHECKOUT_PROCESS, |
|
|
|
|
247
|
|
|
"order_id=$this->os_order_reference&from=order", |
248
|
|
|
'SSL', |
249
|
|
|
true, |
250
|
|
|
false |
251
|
|
|
) |
252
|
|
|
); |
253
|
|
|
$cancelUrl = trim(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL', false)); |
|
|
|
|
254
|
|
|
$orderConfigurationUrls = new \Pagantis\OrdersApiClient\Model\Order\Configuration\Urls(); |
255
|
|
|
$orderConfigurationUrls |
256
|
|
|
->setCancel($cancelUrl) |
257
|
|
|
->setKo($cancelUrl) |
258
|
|
|
->setAuthorizedNotificationCallback($callback_url) |
259
|
|
|
->setRejectedNotificationCallback($callback_url) |
260
|
|
|
->setOk($checkoutProcessUrl); |
261
|
|
|
|
262
|
|
|
|
263
|
|
|
$orderChannel = new \Pagantis\OrdersApiClient\Model\Order\Configuration\Channel(); |
264
|
|
|
$orderChannel |
265
|
|
|
->setAssistedSale(false) |
266
|
|
|
->setType(\Pagantis\OrdersApiClient\Model\Order\Configuration\Channel::ONLINE); |
267
|
|
|
$orderConfiguration = new \Pagantis\OrdersApiClient\Model\Order\Configuration(); |
268
|
|
|
$orderConfiguration |
269
|
|
|
->setChannel($orderChannel) |
270
|
|
|
->setUrls($orderConfigurationUrls); |
271
|
|
|
|
272
|
|
|
$metadataOrder = new \Pagantis\OrdersApiClient\Model\Order\Metadata(); |
273
|
|
|
$metadata = array( |
274
|
|
|
'oscommerce' => PROJECT_VERSION, |
|
|
|
|
275
|
|
|
'pagantis' => $this->version, |
276
|
|
|
'php' => phpversion() |
277
|
|
|
); |
278
|
|
|
foreach ($metadata as $key => $metadatum) { |
279
|
|
|
$metadataOrder->addMetadata($key, $metadatum); |
280
|
|
|
} |
281
|
|
|
$orderApiClient = new \Pagantis\OrdersApiClient\Model\Order(); |
282
|
|
|
$orderApiClient |
283
|
|
|
->setConfiguration($orderConfiguration) |
284
|
|
|
->setMetadata($metadataOrder) |
285
|
|
|
->setShoppingCart($orderShoppingCart) |
286
|
|
|
->setUser($orderUser); |
287
|
|
|
|
288
|
|
|
$publicKey = trim(MODULE_PAYMENT_PAGANTIS_PK); |
|
|
|
|
289
|
|
|
$secretKey = trim(MODULE_PAYMENT_PAGANTIS_SK); |
|
|
|
|
290
|
|
|
$orderClient = new \Pagantis\OrdersApiClient\Client($publicKey, $secretKey); |
291
|
|
|
$pagantisOrder = $orderClient->createOrder($orderApiClient); |
292
|
|
|
if ($pagantisOrder instanceof \Pagantis\OrdersApiClient\Model\Order) { |
|
|
|
|
293
|
|
|
$url = $pagantisOrder->getActionUrls()->getForm(); |
294
|
|
|
$this->insertRow($this->os_order_reference, $pagantisOrder->getId(), serialize($global_vars)); |
295
|
|
|
} else { |
296
|
|
|
throw new OrderNotFoundException(); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
if ($url == "") { |
300
|
|
|
throw new UnknownException(_("No ha sido posible obtener una respuesta de Pagantis")); |
301
|
|
|
} else { |
302
|
|
|
$output = "\n"; |
303
|
|
|
$output .= tep_draw_hidden_field("formUrl", $url) . "\n"; |
|
|
|
|
304
|
|
|
$output .= tep_draw_hidden_field("cancelUrl", $cancelUrl) . "\n"; |
305
|
|
|
return $output; |
306
|
|
|
|
307
|
|
|
} //TODO IFRAME |
308
|
|
|
} catch (\Exception $exception) { |
309
|
|
|
tep_redirect($cancelUrl); |
|
|
|
|
310
|
|
|
return; |
311
|
|
|
} |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* |
316
|
|
|
*/ |
317
|
|
|
public function before_process() |
318
|
|
|
{ |
319
|
|
|
include_once('./ext/modules/payment/pagantis/notifyController.php'); |
320
|
|
|
$this->pgNotify = new notifyController(); |
321
|
|
|
$this->pgNotify->setOscommerceOrderId($_GET['order_id']); |
322
|
|
|
$this->pgNotify->setOrigin(isset($_GET['from']) ? ($_GET['from']) : 'order'); |
323
|
|
|
$this->pgNotify->processInformation(); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Post-processing activities |
328
|
|
|
* |
329
|
|
|
* @return boolean |
330
|
|
|
*/ |
331
|
|
|
public function after_process() |
332
|
|
|
{ |
333
|
|
|
$this->pgNotify->confirmInformation(); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
public function output_error() |
337
|
|
|
{ |
338
|
|
|
return false; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
public function check() |
342
|
|
|
{ |
343
|
|
|
if (!isset($this->_check)) { |
344
|
|
|
$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " |
|
|
|
|
345
|
|
|
where configuration_key = 'MODULE_PAYMENT_PAGANTIS_STATUS'"); |
346
|
|
|
$this->_check = tep_db_num_rows($check_query); |
|
|
|
|
347
|
|
|
} |
348
|
|
|
$this->installPagantisTables(); |
349
|
|
|
return $this->_check; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/* |
353
|
|
|
* This is where you define module's configurations (displayed in admin). |
354
|
|
|
*/ |
355
|
|
|
public function install() |
356
|
|
|
{ |
357
|
|
|
global $messageStack; |
358
|
|
|
|
359
|
|
|
if (defined('MODULE_PAYMENT_PAGANTIS_STATUS')) { |
360
|
|
|
tep_redirect(tep_href_link(FILENAME_MODULES, 'set=payment&module=pagantis', 'NONSSL')); |
|
|
|
|
361
|
|
|
return 'failed'; |
362
|
|
|
} |
363
|
|
|
tep_db_query("insert into " . TABLE_CONFIGURATION . " |
|
|
|
|
364
|
|
|
( |
365
|
|
|
configuration_title, |
366
|
|
|
configuration_key, |
367
|
|
|
configuration_value, |
368
|
|
|
configuration_description, |
369
|
|
|
configuration_group_id, |
370
|
|
|
sort_order, |
371
|
|
|
set_function, |
372
|
|
|
date_added) |
373
|
|
|
values |
374
|
|
|
( |
375
|
|
|
'Enable Pagantis module', |
376
|
|
|
'MODULE_PAYMENT_PAGANTIS_STATUS', |
377
|
|
|
'True', |
378
|
|
|
'', |
379
|
|
|
'6', |
380
|
|
|
'0', |
381
|
|
|
'tep_cfg_select_option(array(\'True\', |
382
|
|
|
\'False\'), |
383
|
|
|
', |
384
|
|
|
now() |
385
|
|
|
)"); |
386
|
|
|
tep_db_query("insert into " . TABLE_CONFIGURATION . " |
387
|
|
|
( |
388
|
|
|
configuration_title, |
389
|
|
|
configuration_key, |
390
|
|
|
configuration_value, |
391
|
|
|
configuration_description, |
392
|
|
|
configuration_group_id, |
393
|
|
|
sort_order, |
394
|
|
|
date_added |
395
|
|
|
) |
396
|
|
|
values |
397
|
|
|
( |
398
|
|
|
'Public Key', |
399
|
|
|
'MODULE_PAYMENT_PAGANTIS_PK', |
400
|
|
|
'', |
401
|
|
|
'MANDATORY. You can get in your pagantis profile', |
402
|
|
|
'6', |
403
|
|
|
'0', |
404
|
|
|
now() |
405
|
|
|
)"); |
406
|
|
|
tep_db_query("insert into " . TABLE_CONFIGURATION . " |
407
|
|
|
( |
408
|
|
|
configuration_title, |
409
|
|
|
configuration_key, |
410
|
|
|
configuration_value, |
411
|
|
|
configuration_description, |
412
|
|
|
configuration_group_id, |
413
|
|
|
sort_order, |
414
|
|
|
date_added |
415
|
|
|
) |
416
|
|
|
values |
417
|
|
|
( |
418
|
|
|
'Secret Key', |
419
|
|
|
'MODULE_PAYMENT_PAGANTIS_SK', |
420
|
|
|
'', |
421
|
|
|
'MANDATORY. You can get in your pagantis profile', |
422
|
|
|
'6', |
423
|
|
|
'0', |
424
|
|
|
now() |
425
|
|
|
)"); |
426
|
|
|
|
427
|
|
|
$this->installPagantisTables(); |
428
|
|
|
|
429
|
|
|
$this->installSimulator(); |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* Create the neccesary tables for the module |
434
|
|
|
*/ |
435
|
|
|
private function installPagantisTables() |
436
|
|
|
{ |
437
|
|
|
$sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_LOG . " ( |
438
|
|
|
id int NOT NULL AUTO_INCREMENT, |
439
|
|
|
log text NOT NULL, |
440
|
|
|
createdAt timestamp DEFAULT CURRENT_TIMESTAMP, |
441
|
|
|
UNIQUE KEY id (id))"; |
442
|
|
|
tep_db_query($sql); |
|
|
|
|
443
|
|
|
|
444
|
|
|
$sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_CONFIG . " ( |
445
|
|
|
id int NOT NULL AUTO_INCREMENT, |
446
|
|
|
config varchar(60) NOT NULL, |
447
|
|
|
value varchar(200) NOT NULL, |
448
|
|
|
UNIQUE KEY id(id))"; |
449
|
|
|
tep_db_query($sql); |
450
|
|
|
|
451
|
|
|
// check if table has records |
452
|
|
|
$check_query = tep_db_query("select value from " . TABLE_PAGANTIS_CONFIG); |
453
|
|
|
if (tep_db_num_rows($check_query) === 0) { |
|
|
|
|
454
|
|
|
foreach ((array)$this->defaultConfigs as $configKey => $configValue) { |
455
|
|
|
$query = "INSERT INTO " . TABLE_PAGANTIS_CONFIG . " |
456
|
|
|
( |
457
|
|
|
config, |
458
|
|
|
value |
459
|
|
|
) |
460
|
|
|
values |
461
|
|
|
( |
462
|
|
|
'$configKey', |
463
|
|
|
'$configValue' |
464
|
|
|
)"; |
465
|
|
|
tep_db_query($query); |
466
|
|
|
} |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
$sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_ORDERS . " ( |
470
|
|
|
id int NOT NULL AUTO_INCREMENT, |
471
|
|
|
os_order_id varchar(50), |
472
|
|
|
os_order_reference varchar(50) NOT NULL, |
473
|
|
|
pagantis_order_id varchar(50) NOT NULL, |
474
|
|
|
globals text, |
475
|
|
|
UNIQUE KEY id(id))"; |
476
|
|
|
tep_db_query($sql); |
477
|
|
|
|
478
|
|
|
$sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_CONCURRENCY . " ( |
479
|
|
|
id varchar(50) NOT NULL, |
480
|
|
|
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, |
481
|
|
|
UNIQUE KEY id(id))"; |
482
|
|
|
tep_db_query($sql); |
483
|
|
|
} |
484
|
|
|
|
485
|
|
|
/* |
486
|
|
|
* Standard functionality to uninstall the module. |
487
|
|
|
*/ |
488
|
|
|
public function remove() |
489
|
|
|
{ |
490
|
|
|
$checkTable = tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_LOG . "'"); |
|
|
|
|
491
|
|
|
if (tep_db_num_rows($checkTable) > 0) { |
|
|
|
|
492
|
|
|
tep_db_query("drop table " . TABLE_PAGANTIS_LOG); |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
$checkTable = tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_CONFIG . "'"); |
496
|
|
|
if (tep_db_num_rows($checkTable) > 0) { |
497
|
|
|
tep_db_query("drop table " . TABLE_PAGANTIS_CONFIG); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
$checkTable = tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_ORDERS . "'"); |
501
|
|
|
if (tep_db_num_rows($checkTable) > 0) { |
502
|
|
|
tep_db_query("drop table " . TABLE_PAGANTIS_ORDERS); |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
$checkTable = tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_CONCURRENCY . "'"); |
506
|
|
|
if (tep_db_num_rows($checkTable) > 0) { |
507
|
|
|
tep_db_query("drop table " . TABLE_PAGANTIS_CONCURRENCY); |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
$query = "delete from " . TABLE_ORDERS_STATUS . " where orders_status_id='6'"; |
|
|
|
|
511
|
|
|
tep_db_query($query); |
512
|
|
|
|
513
|
|
|
$query = "delete from " . TABLE_CONFIGURATION . " where configuration_key like '%_PAGANTIS_%'"; |
|
|
|
|
514
|
|
|
tep_db_query($query); |
515
|
|
|
|
516
|
|
|
$this->uninstallSimulator(); |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
/** |
520
|
|
|
* Internal list of configuration keys used for configuration of the module |
521
|
|
|
* |
522
|
|
|
* @return array |
523
|
|
|
*/ |
524
|
|
|
public function keys() |
525
|
|
|
{ |
526
|
|
|
return array('MODULE_PAYMENT_PAGANTIS_STATUS', |
527
|
|
|
'MODULE_PAYMENT_PAGANTIS_PK', |
528
|
|
|
'MODULE_PAYMENT_PAGANTIS_SK' |
529
|
|
|
); |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
/** |
533
|
|
|
* @return array |
534
|
|
|
*/ |
535
|
|
|
private function getOrders() |
536
|
|
|
{ |
537
|
|
|
$this->is_guest = 'true'; |
538
|
|
|
if (trim($_SESSION['customer_id']) != '') { |
539
|
|
|
$this->is_guest = 'false'; |
540
|
|
|
$query = sprintf( |
541
|
|
|
"select orders_total.value, orders.date_purchased from orders |
542
|
|
|
JOIN orders_status_history ON orders.orders_id=orders_status_history.orders_id |
543
|
|
|
JOIN orders_total ON orders.orders_id=orders_total.orders_id |
544
|
|
|
where orders.customers_id='%s' and orders_status_history.orders_status_id in ('2','3') |
545
|
|
|
and orders_total.class='ot_total'", |
546
|
|
|
$_SESSION['customer_id'] |
547
|
|
|
); |
548
|
|
|
|
549
|
|
|
$response = array(); |
550
|
|
|
$resultsSelect = tep_db_query($query); |
|
|
|
|
551
|
|
|
while ($orderRow = tep_db_fetch_array($resultsSelect)) { |
|
|
|
|
552
|
|
|
$response[] = $orderRow; |
553
|
|
|
} |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
return $response; |
|
|
|
|
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
/** |
560
|
|
|
* @param $orderId |
561
|
|
|
* @param $pagantisOrderId |
562
|
|
|
* @param $globalVars |
563
|
|
|
*/ |
564
|
|
|
private function insertRow($orderId, $pagantisOrderId, $globalVars) |
565
|
|
|
{ |
566
|
|
|
$query = "select * from " . TABLE_PAGANTIS_ORDERS . " where os_order_reference='$orderId'"; |
567
|
|
|
$resultsSelect = tep_db_query($query); |
|
|
|
|
568
|
|
|
$countResults = tep_db_num_rows($resultsSelect); |
|
|
|
|
569
|
|
|
if ($countResults == 0) { |
570
|
|
|
$query = "INSERT INTO " . TABLE_PAGANTIS_ORDERS . " |
571
|
|
|
(os_order_reference, pagantis_order_id, globals) values ('$orderId', '$pagantisOrderId','$globalVars')"; |
572
|
|
|
} else { |
573
|
|
|
$query = "UPDATE " . TABLE_PAGANTIS_ORDERS . " set pagantis_order_id='$pagantisOrderId' |
574
|
|
|
where os_order_reference='$orderId'"; |
575
|
|
|
} |
576
|
|
|
tep_db_query($query); |
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
/** |
580
|
|
|
* @return array |
581
|
|
|
*/ |
582
|
|
|
private function getExtraConfig() |
583
|
|
|
{ |
584
|
|
|
$checkTable = tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_CONFIG . "'"); |
|
|
|
|
585
|
|
|
$response = array(); |
586
|
|
|
if (tep_db_num_rows($checkTable) > 0) { |
|
|
|
|
587
|
|
|
$query = "select * from " . TABLE_PAGANTIS_CONFIG; |
588
|
|
|
$result = tep_db_query($query); |
589
|
|
|
$resultArray = tep_db_fetch_array($result); |
|
|
|
|
590
|
|
|
$response = array(); |
591
|
|
|
foreach ((array)$resultArray as $key => $value) { |
592
|
|
|
$response[$key] = $value; |
593
|
|
|
} |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
return $response; |
597
|
|
|
} |
598
|
|
|
|
599
|
|
|
private function installSimulator() |
600
|
|
|
{ |
601
|
|
|
$checkSimulator = tep_db_query("select configuration_key, configuration_value from " .TABLE_CONFIGURATION ." |
|
|
|
|
602
|
|
|
where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED' |
603
|
|
|
and configuration_value like '%ht_pagantis.php%';"); |
604
|
|
|
if (tep_db_num_rows($checkSimulator) > 0) { |
|
|
|
|
605
|
|
|
return true; |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
$query = "UPDATE " . TABLE_CONFIGURATION . " set configuration_value = concat(configuration_value, ';ht_pagantis.php') |
609
|
|
|
where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED'"; |
610
|
|
|
tep_db_query($query); |
611
|
|
|
|
612
|
|
|
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Pagantis Module', 'MODULE_HEADER_TAGS_PAGANTIS_STATUS', 'True', '', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
private function uninstallSimulator() |
616
|
|
|
{ |
617
|
|
|
$checkSimulator = tep_db_query("select configuration_key, configuration_value from " .TABLE_CONFIGURATION ." |
|
|
|
|
618
|
|
|
where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED' |
619
|
|
|
and configuration_value like '%ht_pagantis.php%';"); |
620
|
|
|
if (tep_db_num_rows($checkSimulator) == 0) { |
|
|
|
|
621
|
|
|
return true; |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
$query = "UPDATE " . TABLE_CONFIGURATION . " set configuration_value = REPLACE(configuration_value, ';ht_pagantis.php', '') |
625
|
|
|
where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED'"; |
626
|
|
|
tep_db_query($query); |
627
|
|
|
|
628
|
|
|
$query = "delete from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_HEADER_TAGS_PAGANTIS_STATUS'"; |
629
|
|
|
tep_db_query($query); |
630
|
|
|
} |
631
|
|
|
} |