1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Pagantis\ModuleUtils\Exception\OrderNotFoundException; |
4
|
|
|
use Pagantis\OrdersApiClient\Model\Order\User\Address; |
5
|
|
|
use Pagantis\ModuleUtils\Exception\UnknownException; |
6
|
|
|
use Pagantis\ModuleUtils\Model\Log\LogEntry; |
7
|
|
|
|
8
|
|
|
define('TABLE_PAGANTIS_LOG', 'pagantis_log'); |
9
|
|
|
define('TABLE_PAGANTIS_CONFIG', 'pagantis_config'); |
10
|
|
|
define('TABLE_PAGANTIS_ORDERS', 'pagantis_order'); |
11
|
|
|
define('TABLE_PAGANTIS_CONCURRENCY', 'pagantis_concurrency'); |
12
|
|
|
define('MODULE_PAYMENT_PAGANTIS_TEXT_ADMIN_TITLE', 'Pagantis'); |
13
|
|
|
define('__ROOT__', dirname(dirname(__FILE__))); |
14
|
|
|
|
15
|
|
|
class pagantis |
16
|
|
|
{ |
17
|
|
|
/** @var String $is_guest */ |
18
|
|
|
public $is_guest; |
19
|
|
|
|
20
|
|
|
/** @var Array $extraConfig */ |
21
|
|
|
public $extraConfig; |
22
|
|
|
|
23
|
|
|
/** @var String $form_action_url */ |
24
|
|
|
public $form_action_url; |
25
|
|
|
|
26
|
|
|
/** @var String $base_url */ |
27
|
|
|
public $base_url; |
28
|
|
|
|
29
|
|
|
/** @var String $os_order_reference */ |
30
|
|
|
public $os_order_reference; |
31
|
|
|
|
32
|
|
|
/** @var notifyController $pgNotify */ |
33
|
|
|
public $pgNotify; |
34
|
|
|
|
35
|
|
|
/** @var string $langCode */ |
36
|
|
|
public $langCode = null; |
37
|
|
|
|
38
|
|
|
/** @var string $errorMessage */ |
39
|
|
|
public $errorMessage; |
40
|
|
|
|
41
|
|
|
/** @var string $errorLinkMessage */ |
42
|
|
|
public $errorLinkMessage; |
43
|
|
|
|
44
|
|
|
public $defaultConfigs = array( |
45
|
|
|
'PAGANTIS_SIMULATOR_DISPLAY_TYPE'=>'sdk.simulator.types.PRODUCT_PAGE', |
46
|
|
|
'PAGANTIS_SIMULATOR_DISPLAY_TYPE_CHECKOUT'=>'sdk.simulator.types.CHECKOUT_PAGE', |
47
|
|
|
'PAGANTIS_SIMULATOR_DISPLAY_SKIN'=>'sdk.simulator.skins.BLUE', |
48
|
|
|
'PAGANTIS_SIMULATOR_DISPLAY_POSITION'=>'hookDisplayProductButtons', |
49
|
|
|
'PAGANTIS_SIMULATOR_START_INSTALLMENTS'=>3, |
50
|
|
|
'PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'=>12, |
51
|
|
|
'PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'=>'default', |
52
|
|
|
'PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'=>'sdk.simulator.positions.INNER', |
53
|
|
|
'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'=>'default', |
54
|
|
|
'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'=>'default', |
55
|
|
|
'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR_CHECKOUT'=>'default', |
56
|
|
|
'PAGANTIS_FORM_DISPLAY_TYPE'=>0, |
57
|
|
|
'PAGANTIS_DISPLAY_MIN_AMOUNT'=>1, |
58
|
|
|
'PAGANTIS_URL_OK'=>'', |
59
|
|
|
'PAGANTIS_URL_KO'=>'', |
60
|
|
|
'PAGANTIS_TITLE_EXTRA' => 'Paga hasta en 12 cómodas cuotas con Pagantis. Solicitud totalmente online y sin papeleos,¡y la respuesta es inmediata!', |
61
|
|
|
'PAGANTIS_PROMOTION' => '', |
62
|
|
|
'PAGANTIS_PROMOTED_PRODUCT_CODE' => 'Finance this product <span class="pmt-no-interest">without interest!</span>', |
63
|
|
|
'PAGANTIS_ALLOWED_COUNTRIES' => 'a:3:{i:0;s:2:"es";i:1;s:2:"it";i:2;s:2:"fr";}', |
64
|
|
|
'PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR' => '.', |
65
|
|
|
'PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR' => ',' |
66
|
|
|
|
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Constructor |
71
|
|
|
*/ |
72
|
|
|
public function __construct() |
73
|
|
|
{ |
74
|
|
|
$this->version = '8.2.0'; |
|
|
|
|
75
|
|
|
$this->code = 'pagantis'; |
|
|
|
|
76
|
|
|
$this->sort_order = 0; |
|
|
|
|
77
|
|
|
$this->description = $this->getDescription(); |
|
|
|
|
78
|
|
|
$this->extraConfig = $this->getExtraConfig(); |
79
|
|
|
|
80
|
|
|
if (strpos($_SERVER[REQUEST_URI], "checkout_payment.php") <= 0) { |
|
|
|
|
81
|
|
|
$this->title = MODULE_PAYMENT_PAGANTIS_TEXT_ADMIN_TITLE; // Payment module title in Admin |
|
|
|
|
82
|
|
|
} else { |
83
|
|
|
$this->title = MODULE_PAYMENT_PAGANTIS_TEXT_CHECKOUT .'<br/><br/><div class="buttonSet" style="display:none"></div><br/>'; // Payment module title in Catalog |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if (defined('MODULE_PAYMENT_PAGANTIS_LANG_CODE')) { |
87
|
|
|
$this->langCode = strtoupper(MODULE_PAYMENT_PAGANTIS_LANG_CODE); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']); |
91
|
|
|
|
92
|
|
|
$this->enabled = ((MODULE_PAYMENT_PAGANTIS_STATUS == 'True' && in_array(strtolower($this->langCode), $allowedCountries)) ? true : false); |
|
|
|
|
93
|
|
|
|
94
|
|
|
$this->base_url = dirname( |
95
|
|
|
sprintf( |
96
|
|
|
"%s://%s%s%s", |
97
|
|
|
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', |
98
|
|
|
$_SERVER['SERVER_NAME'], |
99
|
|
|
isset($_SERVER['SERVER_PORT']) ? ":" . $_SERVER['SERVER_PORT'] : '', |
100
|
|
|
$_SERVER['REQUEST_URI'] |
101
|
|
|
) |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
$this->form_action_url = $this->base_url . '/ext/modules/payment/pagantis/bypass.php'; |
105
|
|
|
|
106
|
|
|
if (defined('MODULE_PAYMENT_PAGANTIS_ERROR_MESSAGE')) { |
107
|
|
|
$this->errorMessage = strtoupper(MODULE_PAYMENT_PAGANTIS_ERROR_MESSAGE); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if (defined('MODULE_PAYMENT_PAGANTIS_ERROR_MESSAGE')) { |
111
|
|
|
$this->errorLinkMessage = strtoupper(MODULE_PAYMENT_PAGANTIS_ERROR_LINK_MESSAGE); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/*************** |
116
|
|
|
* |
117
|
|
|
* CLASS METHODS |
118
|
|
|
* |
119
|
|
|
**************/ |
120
|
|
|
/** |
121
|
|
|
* Here you can implement using payment zones (refer to standard PayPal module as reference) |
122
|
|
|
*/ |
123
|
|
|
public function update_status() |
124
|
|
|
{ |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/* |
129
|
|
|
* Here you may define client side javascript that will verify any input fields you use in the payment method |
130
|
|
|
* selection page. Refer to standard cc module as reference (cc.php). |
131
|
|
|
*/ |
132
|
|
|
public function javascript_validation() |
133
|
|
|
{ |
134
|
|
|
return false; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/* |
138
|
|
|
* Llamada cuando el usuario esta en la pantalla de eleccion de tipo de pago |
139
|
|
|
* This function outputs the payment method title/text and if required, the input fields. |
140
|
|
|
* |
141
|
|
|
* Si hay un pedido generado previamente y no confirmado, se borra |
142
|
|
|
* Caso de uso: |
143
|
|
|
* - el usuario llega a la pantalla de confirmacion |
144
|
|
|
* - se genera el pedido (pero no se genera entrada en orders_status_history) |
145
|
|
|
* - el usuario decide realizar algun cambio en su compra antes de pasar a pagantis |
146
|
|
|
* - entra de nuevo en la pantalla de seleccion de tipo de pago (puede elegir otra forma de pago) |
147
|
|
|
* - se comprueba que no exista el pedido generado anteriormente |
148
|
|
|
* - se borra el pedido que se habia generado inicialmente. Ya no es valido |
149
|
|
|
* |
150
|
|
|
*/ |
151
|
|
|
public function selection() |
152
|
|
|
{ |
153
|
|
|
return array('id' => $this->code, 'module' => $this->title); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/* |
157
|
|
|
* Use this function implement any checks of any conditions after payment method has been selected. You most probably |
158
|
|
|
* don't need to implement anything here. |
159
|
|
|
*/ |
160
|
|
|
public function pre_confirmation_check() |
161
|
|
|
{ |
162
|
|
|
return false; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/* |
166
|
|
|
* Implement any checks or processing on the order information before proceeding to payment confirmation. You most |
167
|
|
|
probably don't need to implement anything here. |
168
|
|
|
* Llamada cuando el usuario entra en la pantalla de confirmacion |
169
|
|
|
* |
170
|
|
|
* Se genera el pedido: |
171
|
|
|
* - con el estado predefinido para el modulo pagantis |
172
|
|
|
* - sin notificacion a cliente ni administrador |
173
|
|
|
* - no se borra el carrito asociado al pedido |
174
|
|
|
* |
175
|
|
|
*/ |
176
|
|
|
public function confirmation() |
177
|
|
|
{ |
178
|
|
|
return false; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen. |
183
|
|
|
* This sends the data to the payment gateway for processing. |
184
|
|
|
* (These are hidden fields on the checkout confirmation page) |
185
|
|
|
*/ |
186
|
|
|
public function process_button() |
187
|
|
|
{ |
188
|
|
|
try { |
189
|
|
|
include_once('./ext/modules/payment/pagantis/vendor/autoload.php'); |
190
|
|
|
global $order, $customer_id, $sendto, $billto, $cart, $languages_id, $currency, $currencies, $shipping, |
191
|
|
|
$payment, $comments, $customer_default_address_id, $cartID; |
192
|
|
|
$global_vars = array(); |
193
|
|
|
$global_vars['customer_id'] = serialize($customer_id); |
194
|
|
|
$global_vars['sendTo'] = serialize($sendto); |
195
|
|
|
$global_vars['billTo'] = serialize($billto); |
196
|
|
|
$global_vars['cart'] = serialize($cart); |
197
|
|
|
$global_vars['languages_id'] = serialize($languages_id); |
198
|
|
|
$global_vars['currency'] = serialize($currency); |
199
|
|
|
$global_vars['currencies'] = serialize($currencies); |
200
|
|
|
$global_vars['shipping'] = serialize($shipping); |
201
|
|
|
$global_vars['payment'] = serialize($payment); |
202
|
|
|
$global_vars['comments'] = serialize($comments); |
203
|
|
|
$global_vars['$customer_default_address_id'] = serialize($customer_default_address_id); |
204
|
|
|
$global_vars['cartID'] = serialize($cartID); |
205
|
|
|
$global_vars['sessiontoken'] = serialize($_SESSION['sessiontoken']); |
206
|
|
|
|
207
|
|
|
if (!isset($order)) { |
208
|
|
|
throw new UnknownException("Order not found"); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
$id_hash = time().serialize($order->products).''.serialize($order->customer).''.serialize($order->delivery); |
212
|
|
|
$this->os_order_reference = md5($id_hash); |
213
|
|
|
$_SESSION['order_id'] = $this->os_order_reference; |
214
|
|
|
|
215
|
|
|
$national_id = $this->getNationalId(); |
|
|
|
|
216
|
|
|
$tax_id = $this->getTaxId(); |
|
|
|
|
217
|
|
|
|
218
|
|
|
$fullName = $order->billing['firstname'] . ' ' . $order->billing['lastname']; |
219
|
|
|
if ($fullName == ' ') { |
220
|
|
|
$fullName = $order->customer['firstname'] . ' ' . $order->customer['lastname']; |
221
|
|
|
} |
222
|
|
|
if ($fullName == ' ') { |
223
|
|
|
$fullName = $order->delivery['firstname'] . ' ' . $order->delivery['lastname']; |
224
|
|
|
} |
225
|
|
|
$fullName = utf8_encode($fullName); |
226
|
|
|
$userAddress = new Address(); |
227
|
|
|
$userAddress |
228
|
|
|
->setZipCode($order->billing['postcode']) |
229
|
|
|
->setFullName($fullName) |
230
|
|
|
->setCountryCode($order->billing['country']['iso_code']) |
231
|
|
|
->setCity($order->billing['city']) |
232
|
|
|
->setAddress($order->billing['street_address']) |
233
|
|
|
->setFixPhone($order->customer['telephone']) |
234
|
|
|
->setMobilePhone($order->customer['telephone']) |
235
|
|
|
->setNationalId($national_id) |
236
|
|
|
->setTaxId($tax_id); |
237
|
|
|
|
238
|
|
|
$orderBillingAddress = $userAddress; |
239
|
|
|
$orderShippingAddress = new Address(); |
240
|
|
|
$orderShippingAddress |
241
|
|
|
->setZipCode($order->delivery['postcode']) |
242
|
|
|
->setFullName($fullName) |
243
|
|
|
->setCountryCode($order->delivery['country']['iso_code']) |
244
|
|
|
->setCity($order->delivery['city']) |
245
|
|
|
->setAddress($order->delivery['street_address']) |
246
|
|
|
->setFixPhone($order->customer['telephone']) |
247
|
|
|
->setMobilePhone($order->customer['telephone']); |
248
|
|
|
|
249
|
|
|
$orderUser = new \Pagantis\OrdersApiClient\Model\Order\User(); |
250
|
|
|
$orderUser |
251
|
|
|
->setAddress($userAddress) |
252
|
|
|
->setFullName($fullName) |
253
|
|
|
->setBillingAddress($orderBillingAddress) |
254
|
|
|
->setEmail($order->customer['email_address']) |
255
|
|
|
->setFixPhone($order->customer['telephone']) |
256
|
|
|
->setMobilePhone($order->customer['telephone']) |
257
|
|
|
->setShippingAddress($orderShippingAddress) |
258
|
|
|
->setNationalId($national_id) |
259
|
|
|
->setTaxId($tax_id); |
260
|
|
|
|
261
|
|
|
$previousOrders = $this->getOrders(); |
262
|
|
|
foreach ((array)$previousOrders as $k => $previousOrder) { |
263
|
|
|
$orderHistory = new \Pagantis\OrdersApiClient\Model\Order\User\OrderHistory(); |
264
|
|
|
$orderHistory |
265
|
|
|
->setAmount(intval(100 * $previousOrder['value'])) |
266
|
|
|
->setDate(new \DateTime($previousOrder['date_purchased'])); |
|
|
|
|
267
|
|
|
$orderUser->addOrderHistory($orderHistory); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
$details = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details(); |
271
|
|
|
$shippingCost = number_format($order->info['shipping_cost'], 2, '.', ''); |
272
|
|
|
$details->setShippingCost(intval(strval(100 * $shippingCost))); |
273
|
|
|
|
274
|
|
|
$metadataOrder = new \Pagantis\OrdersApiClient\Model\Order\Metadata(); |
275
|
|
|
$metadata = array( |
276
|
|
|
'member_since' => $this->getMemberSince(), |
277
|
|
|
'pg_module' => 'oscommerce', |
278
|
|
|
'pg_version' => $this->version, |
279
|
|
|
'ec_module' => 'oscommerce', |
280
|
|
|
'ec_version' => PROJECT_VERSION |
|
|
|
|
281
|
|
|
); |
282
|
|
|
foreach ($metadata as $key => $metadatum) { |
283
|
|
|
$metadataOrder->addMetadata($key, $metadatum); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
$promotedAmount = 0; |
287
|
|
|
foreach ($order->products as $item) { |
288
|
|
|
$promotedProduct = $this->isPromoted($item); |
289
|
|
|
$product = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details\Product(); |
290
|
|
|
$product |
291
|
|
|
->setAmount(intval(100 * number_format(($item['final_price'] * $item['qty']), 2))) |
292
|
|
|
->setQuantity(intval($item['qty'])) |
293
|
|
|
->setDescription($item['name']); |
294
|
|
|
if ($promotedProduct) { |
295
|
|
|
$promotedAmount+=$product->getAmount(); |
296
|
|
|
$promotedMessage = $product->getDescription()."-Price:".$item['final_price']."-Qty:".$product->getQuantity(); |
297
|
|
|
$metadataOrder->addMetadata('promotedProduct', $promotedMessage); |
298
|
|
|
} |
299
|
|
|
$details->addProduct($product); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
$orderShoppingCart = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart(); |
303
|
|
|
$orderShoppingCart |
304
|
|
|
->setDetails($details) |
305
|
|
|
->setOrderReference($this->os_order_reference) |
306
|
|
|
->setTotalAmount(intval($order->info['total'] * 100)) |
307
|
|
|
->setPromotedAmount($promotedAmount); |
308
|
|
|
|
309
|
|
|
$callback_url = $this->base_url.'/ext/modules/payment/pagantis/callback.php?order_id='.$this->os_order_reference; |
310
|
|
|
$checkoutProcessUrl = htmlspecialchars_decode( |
311
|
|
|
tep_href_link(FILENAME_CHECKOUT_PROCESS, "order_id=$this->os_order_reference&from=order", 'SSL', true) |
|
|
|
|
312
|
|
|
); |
313
|
|
|
|
314
|
|
|
$cancelUrl = trim(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL', false)); |
|
|
|
|
315
|
|
|
if ($this->extraConfig['PAGANTIS_URL_KO']!='') { |
316
|
|
|
$koUrl = $this->extraConfig['PAGANTIS_URL_KO']; |
317
|
|
|
} else { |
318
|
|
|
$koUrl = $cancelUrl; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
$orderConfigurationUrls = new \Pagantis\OrdersApiClient\Model\Order\Configuration\Urls(); |
322
|
|
|
$orderConfigurationUrls |
323
|
|
|
->setCancel($cancelUrl) |
324
|
|
|
->setKo($koUrl) |
325
|
|
|
->setAuthorizedNotificationCallback($callback_url) |
326
|
|
|
->setRejectedNotificationCallback($callback_url) |
327
|
|
|
->setOk($checkoutProcessUrl); |
328
|
|
|
|
329
|
|
|
|
330
|
|
|
$orderChannel = new \Pagantis\OrdersApiClient\Model\Order\Configuration\Channel(); |
331
|
|
|
$orderChannel |
332
|
|
|
->setAssistedSale(false) |
333
|
|
|
->setType(\Pagantis\OrdersApiClient\Model\Order\Configuration\Channel::ONLINE); |
334
|
|
|
$orderConfiguration = new \Pagantis\OrdersApiClient\Model\Order\Configuration(); |
335
|
|
|
$orderConfiguration |
336
|
|
|
->setChannel($orderChannel) |
337
|
|
|
->setUrls($orderConfigurationUrls) |
338
|
|
|
->setPurchaseCountry($this->langCode) |
339
|
|
|
; |
340
|
|
|
|
341
|
|
|
$orderApiClient = new \Pagantis\OrdersApiClient\Model\Order(); |
342
|
|
|
$orderApiClient |
343
|
|
|
->setConfiguration($orderConfiguration) |
344
|
|
|
->setMetadata($metadataOrder) |
345
|
|
|
->setShoppingCart($orderShoppingCart) |
346
|
|
|
->setUser($orderUser); |
347
|
|
|
|
348
|
|
|
$publicKey = trim(MODULE_PAYMENT_PAGANTIS_PK); |
|
|
|
|
349
|
|
|
$secretKey = trim(MODULE_PAYMENT_PAGANTIS_SK); |
|
|
|
|
350
|
|
|
$orderClient = new \Pagantis\OrdersApiClient\Client($publicKey, $secretKey); |
351
|
|
|
$pagantisOrder = $orderClient->createOrder($orderApiClient); |
352
|
|
|
if ($pagantisOrder instanceof \Pagantis\OrdersApiClient\Model\Order) { |
|
|
|
|
353
|
|
|
$url = $pagantisOrder->getActionUrls()->getForm(); |
354
|
|
|
$this->insertRow($this->os_order_reference, $pagantisOrder->getId(), serialize($global_vars)); |
355
|
|
|
} else { |
356
|
|
|
throw new OrderNotFoundException(); |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
if ($url == "") { |
360
|
|
|
throw new UnknownException(_("No ha sido posible obtener una respuesta de Pagantis")); |
361
|
|
|
} else { |
362
|
|
|
$output = "\n"; |
363
|
|
|
$output .= tep_draw_hidden_field("formUrl", $url) . "\n"; |
|
|
|
|
364
|
|
|
$output .= tep_draw_hidden_field("cancelUrl", $cancelUrl) . "\n"; |
365
|
|
|
return $output; |
366
|
|
|
|
367
|
|
|
} //TODO IFRAME |
368
|
|
|
} catch (\Exception $exception) { |
369
|
|
|
$this->insertLog($exception); |
370
|
|
|
$output = "\n"; |
371
|
|
|
$output .= tep_draw_hidden_field("cancelUrl", $cancelUrl) . "\n"; |
372
|
|
|
$output .= tep_draw_hidden_field("errorMessage", $exception->getMessage()) . "\n"; |
373
|
|
|
$output .= tep_draw_hidden_field("errorCode", $exception->getCode()) . "\n"; |
374
|
|
|
$output .= "<p>".$this->errorMessage.", <a href='$cancelUrl' style='text-decoration:underline'><b>"; |
375
|
|
|
$output .= $this->errorLinkMessage." </b></a></p>"; |
376
|
|
|
|
377
|
|
|
return $output; |
378
|
|
|
} |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* @throws Exception |
383
|
|
|
*/ |
384
|
|
|
public function before_process() |
385
|
|
|
{ |
386
|
|
|
include_once('./ext/modules/payment/pagantis/notifyController.php'); |
387
|
|
|
$this->pgNotify = new notifyController(); |
388
|
|
|
$this->pgNotify->setOscommerceOrderId($_GET['order_id']); |
389
|
|
|
$this->pgNotify->setOrigin(isset($_GET['from']) ? ($_GET['from']) : 'order'); |
390
|
|
|
$this->pgNotify->processInformation(); |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Post-processing activities |
395
|
|
|
* |
396
|
|
|
* @return boolean |
397
|
|
|
*/ |
398
|
|
|
public function after_process() |
399
|
|
|
{ |
400
|
|
|
$this->pgNotify->confirmInformation(); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* @return bool |
405
|
|
|
*/ |
406
|
|
|
public function output_error() |
407
|
|
|
{ |
408
|
|
|
return false; |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* @return mixed |
413
|
|
|
*/ |
414
|
|
|
public function check() |
415
|
|
|
{ |
416
|
|
|
if (!isset($this->_check)) { |
417
|
|
|
$query = "select * from ".TABLE_CONFIGURATION." where configuration_key = 'MODULE_PAYMENT_PAGANTIS_STATUS'"; |
|
|
|
|
418
|
|
|
$check_query = tep_db_query($query); |
|
|
|
|
419
|
|
|
$this->_check = tep_db_num_rows($check_query); |
|
|
|
|
420
|
|
|
} |
421
|
|
|
$this->installPagantisTables(); |
422
|
|
|
return $this->_check; |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
/** |
426
|
|
|
* This is where you define module's configurations (displayed in admin). |
427
|
|
|
*/ |
428
|
|
|
public function install() |
429
|
|
|
{ |
430
|
|
|
global $messageStack; |
431
|
|
|
|
432
|
|
|
if (defined('MODULE_PAYMENT_PAGANTIS_STATUS')) { |
433
|
|
|
tep_redirect(tep_href_link(FILENAME_MODULES, 'set=payment&module=pagantis', 'NONSSL')); |
|
|
|
|
434
|
|
|
return 'failed'; |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
tep_db_query("insert into " . TABLE_CONFIGURATION . " |
|
|
|
|
438
|
|
|
( |
439
|
|
|
configuration_title, |
440
|
|
|
configuration_key, |
441
|
|
|
configuration_value, |
442
|
|
|
configuration_description, |
443
|
|
|
configuration_group_id, |
444
|
|
|
sort_order, |
445
|
|
|
set_function, |
446
|
|
|
date_added) |
447
|
|
|
values |
448
|
|
|
( |
449
|
|
|
'Enable module', |
450
|
|
|
'MODULE_PAYMENT_PAGANTIS_STATUS', |
451
|
|
|
'True', |
452
|
|
|
'', |
453
|
|
|
'6', |
454
|
|
|
'0', |
455
|
|
|
'tep_cfg_select_option(array(\'True\', |
456
|
|
|
\'False\'), |
457
|
|
|
', |
458
|
|
|
now() |
459
|
|
|
)"); |
460
|
|
|
tep_db_query("insert into " . TABLE_CONFIGURATION . " |
461
|
|
|
( |
462
|
|
|
configuration_title, |
463
|
|
|
configuration_key, |
464
|
|
|
configuration_value, |
465
|
|
|
configuration_description, |
466
|
|
|
configuration_group_id, |
467
|
|
|
sort_order, |
468
|
|
|
date_added |
469
|
|
|
) |
470
|
|
|
values |
471
|
|
|
( |
472
|
|
|
'Public Key', |
473
|
|
|
'MODULE_PAYMENT_PAGANTIS_PK', |
474
|
|
|
'', |
475
|
|
|
'MANDATORY. You can get in your pagantis profile', |
476
|
|
|
'6', |
477
|
|
|
'0', |
478
|
|
|
now() |
479
|
|
|
)"); |
480
|
|
|
tep_db_query("insert into " . TABLE_CONFIGURATION . " |
481
|
|
|
( |
482
|
|
|
configuration_title, |
483
|
|
|
configuration_key, |
484
|
|
|
configuration_value, |
485
|
|
|
configuration_description, |
486
|
|
|
configuration_group_id, |
487
|
|
|
sort_order, |
488
|
|
|
date_added |
489
|
|
|
) |
490
|
|
|
values |
491
|
|
|
( |
492
|
|
|
'Secret Key', |
493
|
|
|
'MODULE_PAYMENT_PAGANTIS_SK', |
494
|
|
|
'', |
495
|
|
|
'MANDATORY. You can get in your pagantis profile', |
496
|
|
|
'6', |
497
|
|
|
'0', |
498
|
|
|
now() |
499
|
|
|
)"); |
500
|
|
|
tep_db_query("insert into " . TABLE_CONFIGURATION . " |
501
|
|
|
( |
502
|
|
|
configuration_title, |
503
|
|
|
configuration_key, |
504
|
|
|
configuration_value, |
505
|
|
|
configuration_description, |
506
|
|
|
configuration_group_id, |
507
|
|
|
sort_order, |
508
|
|
|
set_function, |
509
|
|
|
date_added |
510
|
|
|
) |
511
|
|
|
values |
512
|
|
|
( |
513
|
|
|
'Include simulator', |
514
|
|
|
'MODULE_PAYMENT_PAGANTIS_SIMULATOR', |
515
|
|
|
'True', |
516
|
|
|
'Do you want to include Pagantis simulator', |
517
|
|
|
'6', |
518
|
|
|
'3', |
519
|
|
|
'tep_cfg_select_option(array(\'True\',\'False\'), ', |
520
|
|
|
now())" |
521
|
|
|
); |
522
|
|
|
$this->installPagantisTables(); |
523
|
|
|
|
524
|
|
|
$this->installSimulator(); |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
/** |
528
|
|
|
* Create the neccesary tables for the module |
529
|
|
|
*/ |
530
|
|
|
private function installPagantisTables() |
531
|
|
|
{ |
532
|
|
|
$sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_LOG . " ( |
533
|
|
|
id int NOT NULL AUTO_INCREMENT, |
534
|
|
|
log text NOT NULL, |
535
|
|
|
createdAt timestamp DEFAULT CURRENT_TIMESTAMP, |
536
|
|
|
UNIQUE KEY id (id))"; |
537
|
|
|
tep_db_query($sql); |
|
|
|
|
538
|
|
|
|
539
|
|
|
$sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_CONFIG . " ( |
540
|
|
|
id int NOT NULL AUTO_INCREMENT, |
541
|
|
|
config varchar(60) NOT NULL, |
542
|
|
|
value varchar(200) NOT NULL, |
543
|
|
|
UNIQUE KEY id(id))"; |
544
|
|
|
tep_db_query($sql); |
545
|
|
|
|
546
|
|
|
// check if table has records |
547
|
|
|
$check_query = tep_db_query("select value from " . TABLE_PAGANTIS_CONFIG); |
548
|
|
|
if (tep_db_num_rows($check_query) === 0) { |
|
|
|
|
549
|
|
|
foreach ((array)$this->defaultConfigs as $configKey => $configValue) { |
550
|
|
|
$query = "INSERT INTO " . TABLE_PAGANTIS_CONFIG . " |
551
|
|
|
( |
552
|
|
|
config, |
553
|
|
|
value |
554
|
|
|
) |
555
|
|
|
values |
556
|
|
|
( |
557
|
|
|
'$configKey', |
558
|
|
|
'$configValue' |
559
|
|
|
)"; |
560
|
|
|
tep_db_query($query); |
561
|
|
|
} |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
$sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_ORDERS . " ( |
565
|
|
|
id int NOT NULL AUTO_INCREMENT, |
566
|
|
|
os_order_id varchar(50), |
567
|
|
|
os_order_reference varchar(50) NOT NULL, |
568
|
|
|
pagantis_order_id varchar(50) NOT NULL, |
569
|
|
|
globals text, |
570
|
|
|
UNIQUE KEY id(id))"; |
571
|
|
|
tep_db_query($sql); |
572
|
|
|
|
573
|
|
|
$sql = "CREATE TABLE IF NOT EXISTS " . TABLE_PAGANTIS_CONCURRENCY . " ( |
574
|
|
|
id varchar(50) NOT NULL, |
575
|
|
|
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, |
576
|
|
|
UNIQUE KEY id(id))"; |
577
|
|
|
tep_db_query($sql); |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* Standard functionality to uninstall the module. |
582
|
|
|
*/ |
583
|
|
|
public function remove() |
584
|
|
|
{ |
585
|
|
|
$checkTable = tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_LOG . "'"); |
|
|
|
|
586
|
|
|
if (tep_db_num_rows($checkTable) > 0) { |
|
|
|
|
587
|
|
|
tep_db_query("drop table " . TABLE_PAGANTIS_LOG); |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
$checkTable = tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_CONFIG . "'"); |
591
|
|
|
if (tep_db_num_rows($checkTable) > 0) { |
592
|
|
|
tep_db_query("drop table " . TABLE_PAGANTIS_CONFIG); |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
$checkTable = tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_ORDERS . "'"); |
596
|
|
|
if (tep_db_num_rows($checkTable) > 0) { |
597
|
|
|
tep_db_query("drop table " . TABLE_PAGANTIS_ORDERS); |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
$checkTable = tep_db_query("SHOW TABLES LIKE '" . TABLE_PAGANTIS_CONCURRENCY . "'"); |
601
|
|
|
if (tep_db_num_rows($checkTable) > 0) { |
602
|
|
|
tep_db_query("drop table " . TABLE_PAGANTIS_CONCURRENCY); |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
tep_db_query("DELETE FROM ". TABLE_CONFIGURATION ." where configuration_key in ('MODULE_PAYMENT_PAGANTIS_STATUS','MODULE_PAYMENT_PAGANTIS_PK','MODULE_PAYMENT_PAGANTIS_SK')"); |
|
|
|
|
606
|
|
|
|
607
|
|
|
$query = "delete from " . TABLE_CONFIGURATION . " where configuration_key like '%_PAGANTIS_%'"; |
608
|
|
|
tep_db_query($query); |
609
|
|
|
|
610
|
|
|
$this->uninstallSimulator(); |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
/** |
614
|
|
|
* Internal list of configuration keys used for configuration of the module |
615
|
|
|
* |
616
|
|
|
* @return array |
617
|
|
|
*/ |
618
|
|
|
public function keys() |
619
|
|
|
{ |
620
|
|
|
return array( |
621
|
|
|
'MODULE_PAYMENT_PAGANTIS_STATUS', |
622
|
|
|
'MODULE_PAYMENT_PAGANTIS_PK', |
623
|
|
|
'MODULE_PAYMENT_PAGANTIS_SK', |
624
|
|
|
'MODULE_PAYMENT_PAGANTIS_SIMULATOR' |
625
|
|
|
); |
626
|
|
|
} |
627
|
|
|
|
628
|
|
|
/** |
629
|
|
|
* @return array |
630
|
|
|
*/ |
631
|
|
|
private function getOrders() |
632
|
|
|
{ |
633
|
|
|
$this->is_guest = 'true'; |
634
|
|
|
if (trim($_SESSION['customer_id']) != '') { |
635
|
|
|
$this->is_guest = 'false'; |
636
|
|
|
$query = sprintf( |
637
|
|
|
"select orders_total.value, orders.date_purchased from orders |
638
|
|
|
JOIN orders_status_history ON orders.orders_id=orders_status_history.orders_id |
639
|
|
|
JOIN orders_total ON orders.orders_id=orders_total.orders_id |
640
|
|
|
where orders.customers_id='%s' and orders_status_history.orders_status_id in ('2','3') |
641
|
|
|
and orders_total.class='ot_total'", |
642
|
|
|
$_SESSION['customer_id'] |
643
|
|
|
); |
644
|
|
|
|
645
|
|
|
$response = array(); |
646
|
|
|
$resultsSelect = tep_db_query($query); |
|
|
|
|
647
|
|
|
while ($orderRow = tep_db_fetch_array($resultsSelect)) { |
|
|
|
|
648
|
|
|
$response[] = $orderRow; |
649
|
|
|
} |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
return $response; |
|
|
|
|
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
/** |
656
|
|
|
* @return array |
657
|
|
|
*/ |
658
|
|
|
private function getMemberSince() |
659
|
|
|
{ |
660
|
|
|
$memberSince = null; |
661
|
|
|
if (trim($_SESSION['customer_id']) != '') { |
662
|
|
|
$query = sprintf( |
663
|
|
|
"select customers_info_date_account_created from customers_info where customers_info_id='%s'", |
664
|
|
|
$_SESSION['customer_id'] |
665
|
|
|
); |
666
|
|
|
|
667
|
|
|
$response = array(); |
|
|
|
|
668
|
|
|
$resultsSelect = tep_db_query($query); |
|
|
|
|
669
|
|
|
$orderRow = tep_db_fetch_array($resultsSelect); |
|
|
|
|
670
|
|
|
$memberSince = date('Y-m-d', strtotime($orderRow['customers_info_date_account_created'])); |
671
|
|
|
} |
672
|
|
|
return $memberSince; |
|
|
|
|
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
/** |
676
|
|
|
* @param $orderId |
677
|
|
|
* @param $pagantisOrderId |
678
|
|
|
* @param $globalVars |
679
|
|
|
*/ |
680
|
|
|
private function insertRow($orderId, $pagantisOrderId, $globalVars) |
681
|
|
|
{ |
682
|
|
|
$query = "select * from " . TABLE_PAGANTIS_ORDERS . " where os_order_reference='$orderId'"; |
683
|
|
|
$resultsSelect = tep_db_query($query); |
|
|
|
|
684
|
|
|
$countResults = tep_db_num_rows($resultsSelect); |
|
|
|
|
685
|
|
|
if ($countResults == 0) { |
686
|
|
|
$query = "INSERT INTO " . TABLE_PAGANTIS_ORDERS . " |
687
|
|
|
(os_order_reference, pagantis_order_id, globals) values ('$orderId', '$pagantisOrderId','$globalVars')"; |
688
|
|
|
} else { |
689
|
|
|
$query = "UPDATE ".TABLE_PAGANTIS_ORDERS." set pagantis_order_id='$pagantisOrderId' |
690
|
|
|
where os_order_reference='$orderId'"; |
691
|
|
|
} |
692
|
|
|
tep_db_query($query); |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
/** |
696
|
|
|
* @return array |
697
|
|
|
*/ |
698
|
|
|
private function getExtraConfig() |
699
|
|
|
{ |
700
|
|
|
$checkTable = tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS_CONFIG."'"); |
|
|
|
|
701
|
|
|
$response = array(); |
702
|
|
|
if (tep_db_num_rows($checkTable) > 0) { |
|
|
|
|
703
|
|
|
$query = "select * from ".TABLE_PAGANTIS_CONFIG; |
704
|
|
|
$result = tep_db_query($query); |
705
|
|
|
$response = array(); |
706
|
|
|
while ($resultArray = tep_db_fetch_array($result)) { |
|
|
|
|
707
|
|
|
$response[$resultArray['config']] = $resultArray['value']; |
708
|
|
|
} |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
return $response; |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
/** |
715
|
|
|
* @param $item |
716
|
|
|
* |
717
|
|
|
* @return bool |
718
|
|
|
*/ |
719
|
|
|
private function isPromoted($item) |
720
|
|
|
{ |
721
|
|
|
$productId = explode('{', $item['id'], 1); |
722
|
|
|
$productId = $productId['0']; |
723
|
|
|
|
724
|
|
|
if ($this->extraConfig['PAGANTIS_PROMOTION'] == '') { |
725
|
|
|
$promotedProducts = array(); |
726
|
|
|
} else { |
727
|
|
|
$promotedProducts = array_values((array)unserialize($this->extraConfig['PAGANTIS_PROMOTION'])); |
728
|
|
|
} |
729
|
|
|
|
730
|
|
|
return (in_array($productId, $promotedProducts)); |
731
|
|
|
} |
732
|
|
|
|
733
|
|
|
/** |
734
|
|
|
* @return string |
735
|
|
|
*/ |
736
|
|
|
private function getDescription() |
737
|
|
|
{ |
738
|
|
|
$descriptionCode = "<img src=\"images/icon_info.gif\" border=\"0\" alt=\"Info\" title=\"Info\"> <strong>Module version:</strong> $this->version<br/><br/>"; |
739
|
|
|
$descriptionCode.= "<img src=\"images/icon_info.gif\" border=\"0\"> <a href='https://developer.pagantis.com/' target=\"_blank\" style=\"text-decoration: underline; font-weight: bold;\">View Online Documentation</a><br/><br/>"; |
740
|
|
|
$descriptionCode.= "<img src='images/icon_popup.gif' border='0'> <a href='http://pagantis.com' target='_blank' style='text-decoration: underline; font-weight: bold;'>Visit Pagantis Website</a><br/><br/><br/>"; |
741
|
|
|
|
742
|
|
|
if (MODULE_PAYMENT_PAGANTIS_STATUS == 'True') { |
|
|
|
|
743
|
|
|
$pagantisPromotionUrl = $this->base_url.'/admin/promotion.php'; |
744
|
|
|
$linkDescription = "Si deseas ofrecer financiación sin intereses para alguno de tus productos "; |
745
|
|
|
$descriptionCode.= "<img src='images/icon_info.gif' border='0'/> $linkDescription<a href='$pagantisPromotionUrl' style='text-decoration: underline; font-weight: bold;'>haz click aquí</a>"; |
746
|
|
|
|
747
|
|
|
$pagantisAllowedCountriesUrl = $this->base_url.'/admin/allowedCountries.php'; |
748
|
|
|
$linkDescription = "Para gestionar paises en los que operar con Pagantis "; |
749
|
|
|
$descriptionCode.= "<br/><br/><img src='images/icon_info.gif' border='0'/> $linkDescription<a href='$pagantisAllowedCountriesUrl' style='text-decoration: underline; font-weight: bold;'>haz click aquí</a>"; |
750
|
|
|
} |
751
|
|
|
|
752
|
|
|
return $descriptionCode; |
753
|
|
|
} |
754
|
|
|
|
755
|
|
|
/** |
756
|
|
|
* @return bool |
757
|
|
|
*/ |
758
|
|
|
private function installSimulator() |
759
|
|
|
{ |
760
|
|
|
$checkSimulator = tep_db_query("select configuration_key, configuration_value from " .TABLE_CONFIGURATION ." |
|
|
|
|
761
|
|
|
where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED' |
762
|
|
|
and configuration_value like '%ht_pagantis.php%';"); |
763
|
|
|
if (tep_db_num_rows($checkSimulator) > 0) { |
|
|
|
|
764
|
|
|
return true; |
765
|
|
|
} |
766
|
|
|
|
767
|
|
|
$query = "UPDATE " . TABLE_CONFIGURATION . " set configuration_value = concat(configuration_value, ';ht_pagantis.php') |
768
|
|
|
where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED'"; |
769
|
|
|
tep_db_query($query); |
770
|
|
|
|
771
|
|
|
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())"); |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
/** |
775
|
|
|
* @return bool |
776
|
|
|
*/ |
777
|
|
|
private function uninstallSimulator() |
778
|
|
|
{ |
779
|
|
|
$checkSimulator = tep_db_query("select configuration_key, configuration_value from " .TABLE_CONFIGURATION ." |
|
|
|
|
780
|
|
|
where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED' |
781
|
|
|
and configuration_value like '%ht_pagantis.php%';"); |
782
|
|
|
if (tep_db_num_rows($checkSimulator) == 0) { |
|
|
|
|
783
|
|
|
return true; |
784
|
|
|
} |
785
|
|
|
|
786
|
|
|
$query = "UPDATE " . TABLE_CONFIGURATION . " set configuration_value = REPLACE(configuration_value, ';ht_pagantis.php', '') |
787
|
|
|
where configuration_key like 'MODULE_HEADER_TAGS_INSTALLED'"; |
788
|
|
|
tep_db_query($query); |
789
|
|
|
|
790
|
|
|
$query = "delete from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_HEADER_TAGS_PAGANTIS_STATUS'"; |
791
|
|
|
tep_db_query($query); |
792
|
|
|
} |
793
|
|
|
|
794
|
|
|
/** |
795
|
|
|
* @param $exception |
796
|
|
|
*/ |
797
|
|
|
private function insertLog($exception) |
798
|
|
|
{ |
799
|
|
|
if ($exception instanceof \Exception) { |
800
|
|
|
$logEntry= new LogEntry(); |
801
|
|
|
$logEntryJson = $logEntry->error($exception)->toJson(); |
802
|
|
|
$logEntryJson = addslashes($logEntryJson); |
803
|
|
|
|
804
|
|
|
$query = "insert into ".TABLE_PAGANTIS_LOG."(log) values ('$logEntryJson')"; |
805
|
|
|
tep_db_query($query); |
|
|
|
|
806
|
|
|
} |
807
|
|
|
} |
808
|
|
|
|
809
|
|
|
/** |
810
|
|
|
* @return null |
811
|
|
|
*/ |
812
|
|
|
private function getNationalId() |
813
|
|
|
{ |
814
|
|
|
global $order; |
815
|
|
|
if (isset($order->customer['national_id'])) { |
816
|
|
|
return $order->customer['national_id']; |
817
|
|
|
} elseif (isset($order->billing['piva'])) { |
818
|
|
|
return $order->billing['piva']; |
819
|
|
|
} else { |
820
|
|
|
return null; |
821
|
|
|
} |
822
|
|
|
} |
823
|
|
|
|
824
|
|
|
/** |
825
|
|
|
* @return null |
826
|
|
|
*/ |
827
|
|
|
private function getTaxId() |
828
|
|
|
{ |
829
|
|
|
global $order; |
830
|
|
|
if (isset($order->customer['tax_id'])) { |
831
|
|
|
return $order->customer['tax_id']; |
832
|
|
|
} elseif (isset($order->billing['cf'])) { |
833
|
|
|
return $order->billing['cf']; |
834
|
|
|
} else { |
835
|
|
|
return null; |
836
|
|
|
} |
837
|
|
|
} |
838
|
|
|
} |
839
|
|
|
|