Cheetah
ChPmtModule.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbModule');
9 ch_import('ChWsbAdminSettings');
10 
11 define('CH_PMT_ORDERS_TYPE_PENDING', 'pending');
12 define('CH_PMT_ORDERS_TYPE_PROCESSED', 'processed');
13 define('CH_PMT_ORDERS_TYPE_SUBSCRIPTION', 'subscription');
14 define('CH_PMT_ORDERS_TYPE_HISTORY', 'history');
15 
16 define('CH_PMT_EMPTY_ID', -1);
17 define('CH_PMT_ADMINISTRATOR_ID', 0);
18 define('CH_PMT_ADMINISTRATOR_USERNAME', 'administrator');
19 
78 class ChPmtModule extends ChWsbModule
79 {
80  var $_iUserId;
82  var $_oCart;
83  var $_oOrders;
88 
91 
96  {
97  parent::__construct($aModule);
98 
99  $this->_oConfig->init($this->_oDb);
100 
101  $this->_iUserId = $this->getUserId();
102  $this->_sGeneralPrefix = $this->_oConfig->getGeneralPrefix();
103  $this->_sLangsPrefix = $this->_oConfig->getLangsPrefix();
104  $this->_sEmailTemplatesPrefix = $this->_oConfig->getEmailTemplatesPrefix();
105 
106  $this->_sSessionKeyPending = $this->_sGeneralPrefix . 'pending_id';
107  $this->_sRequestKeyPending = $this->_sGeneralPrefix . 'pending_id';
108 
109  $sClassPrefix = $this->_oConfig->getClassPrefix();
110 
111  ch_import('Cart', $aModule);
112  $sClassName = $sClassPrefix . 'Cart';
113  $this->_oCart = new $sClassName($this->_oDb, $this->_oConfig, $this->_oTemplate);
114 
115  ch_import('Details', $aModule);
116  $sClassName = $sClassPrefix . 'Details';
117  $this->_oDetails = new $sClassName($this->_oDb, $this->_oConfig);
118 
119  ch_import('Orders', $aModule);
120  $sClassName = $sClassPrefix . 'Orders';
121  $this->_oOrders = new $sClassName($this->_iUserId, $this->_oDb, $this->_oConfig, $this->_oTemplate);
122 
123  $this->_aOrderTypes = array(
128  );
129  }
130 
131 
137  function getExtraJs($sType)
138  {
139  $sResult = "";
140  switch($sType) {
141  case 'orders':
142  $sResult = $this->_oOrders->getExtraJs();
143  break;
144  }
145  return $sResult;
146  }
147 
148 
154  function getMoreWindow()
155  {
156  return $this->_oOrders->getMoreWindow();
157  }
159  {
160  return $this->_oOrders->getManualOrderWindow();
161  }
162  function getOrdersBlock($sType, $iUserId = CH_PMT_EMPTY_ID)
163  {
164  return $this->_oOrders->getOrdersBlock($sType, $iUserId);
165  }
167  {
168  if(!$this->isLogged())
169  return '';
170 
171  return CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'orders/';
172  }
173  function actionGetItems($iModuleId)
174  {
175  $aItems = ChWsbService::call((int)$iModuleId, 'get_items', array($this->_iUserId));
176  if(is_array($aItems) && !empty($aItems)) {
177  $aResult = array('code' => 0, 'message' => '', 'data' => $this->_oTemplate->displayItems($aItems));
178  if(isset($aItems[0]['vendor_id']))
179  $aResult['vendor_id'] = $aItems[0]['vendor_id'];
180  } else
181  $aResult = array('code' => 1, 'message' => MsgBox(_t($this->_sLangsPrefix . 'msg_no_results')));
182 
183  header('Content-Type:text/javascript; charset=utf-8');
184  return json_encode($aResult);
185  }
186  function actionGetOrder()
187  {
188  $aData = &$_POST;
189 
190  header('Content-Type:text/javascript; charset=utf-8');
191 
192  if(!isset($aData['type']) || !in_array($aData['type'], $this->_aOrderTypes))
193  return json_encode(array('code' => 1, 'message' => MsgBox(_t($this->_sLangsPrefix . 'err_wrong_data'))));
194 
195  $iId = 0;
196  if(isset($aData['id']))
197  $iId = (int)$aData['id'];
198 
199  $sData = $this->_oOrders->getOrder($aData['type'], $iId);
200  return json_encode(array('code' => 0, 'message' => '', 'data' => $sData));
201  }
202  function actionGetOrders()
203  {
204  $aData = &$_POST;
205 
206  header('Content-Type:text/javascript; charset=utf-8');
207 
208  if(!isset($aData['type']) || !in_array($aData['type'], $this->_aOrderTypes))
209  return json_encode(array('code' => 1, 'message' => $this->_sLangsPrefix . 'err_wrong_data'));
210 
211  $iStart = 0;
212  if(isset($aData['start']))
213  $iStart = (int)$aData['start'];
214 
215  $iPerPage = 0;
216  if(isset($aData['per_page']))
217  $iPerPage = (int)$aData['per_page'];
218 
219  $sFilter = "";
220  if(isset($aData['filter']))
221  $sFilter = process_db_input($aData['filter'], CH_TAGS_STRIP);
222 
223  $aParams = array(
224  'start' => $iStart,
225  'per_page' => $iPerPage,
226  'filter' => $sFilter,
227  'seller_id' => (int)$aData['seller_id']
228  );
229  if($aData['type'] == CH_PMT_ORDERS_TYPE_HISTORY)
230  $aParams['user_id'] = (int)$this->_iUserId;
231 
232  $sData = $this->_oOrders->getOrders($aData['type'], $aParams);
233  return json_encode(array('code' => 0, 'message' => '', 'data' => $sData));
234  }
236  {
237  $aResult = array(
238  'js_object' => $this->_oConfig->getJsObject('orders'),
239  'parent_id' => 'pmt-mo-content'
240  );
241 
242  if(!$this->isLogged())
243  return $this->_onResultInline(array_merge($aResult, array('code' => 1, 'message' => $this->_sLangsPrefix . 'err_required_login')));
244 
245  $mixedResult = $this->_oOrders->addManualOrder($_POST);
246  if(is_array($mixedResult))
247  return $this->_onResultInline(array_merge($aResult, $mixedResult));
248 
249  $this->_oCart->updateInfo((int)$mixedResult);
250  return $this->_onResultInline(array_merge($aResult, array('code' => 0, 'message' => '')));
251  }
253  {
254  $aResult = array(
255  'js_object' => $this->_oConfig->getJsObject('orders'),
256  'parent_id' => 'pmt-form-' . $sType
257  );
258 
259  if(!$this->isLogged())
260  return $this->_onResultInline(array_merge($aResult, array('code' => 1, 'message' => $this->_sLangsPrefix . 'err_required_login')));
261 
262  $aData = &$_POST;
263 
264  if(!isset($aData['orders']) || !is_array($aData['orders']) || empty($aData['orders']))
265  return $this->_onResultInline(array_merge($aResult, array('code' => 2, 'message' => $this->_sLangsPrefix . 'err_nothing_selected')));
266 
267  $mixedResult = true;
268  $sType = $aData['type'];
269  if(isset($aData['pmt-report']) && !empty($aData['pmt-report']))
270  $mixedResult = $this->_oOrders->report($sType, $aData['orders']);
271  else if(isset($aData['pmt-cancel']) && !empty($aData['pmt-cancel']))
272  $mixedResult = $this->_oOrders->cancel($sType, $aData['orders']);
273  else if(isset($aData['pmt-process']) && !empty($aData['pmt-process']) && $sType == CH_PMT_ORDERS_TYPE_PENDING)
274  foreach($aData['orders'] as $iOrderId) {
275  $sKey = 'order-data-' . $iOrderId;
276  if(!isset($aData[$sKey]) || empty($aData[$sKey])) {
277  $mixedResult = array('code' => 4, 'message' => $this->_sLangsPrefix . 'err_empty_orders');
278  break;
279  }
280  $this->_oDb->updatePending($iOrderId, array(
281  'order' => $aData[$sKey],
282  'error_code' => 1,
283  'error_msg' => 'Manually processed'
284  ));
285  $this->_oCart->updateInfo((int)$iOrderId);
286  } else
287  $mixedResult = array('code' => 3, 'message' => $this->_sLangsPrefix . 'err_unknown');
288 
289  if(is_array($mixedResult))
290  return $this->_onResultInline(array_merge($aResult, $mixedResult));
291 
292  return $this->_onResultInline(array_merge($aResult, array('code' => 0, 'message' => '')));
293  }
294 
295 
296 
302  function getDetailsForm($iUserId = CH_PMT_EMPTY_ID)
303  {
304  return $this->_oDetails->getFormBlock($iUserId);
305  }
307  {
308  return array(
309  'sign' => $this->_oConfig->getCurrencySign(),
310  'code' => $this->_oConfig->getCurrencyCode()
311  );
312  }
313  function serviceGetAdmins()
314  {
315  $aIds = $this->_oDb->getAdminsIds();
316 
317  $aResult = array(
318  array('key' => '', 'value' => _t($this->_sLangsPrefix . 'txt_select_one'))
319  );
320  foreach($aIds as $iId)
321  $aResult[] = array(
322  'key' => $iId,
323  'value' => getNickName($iId)
324  );
325 
326  return $aResult;
327  }
328 
334  function getSettingsForm($mixedResult)
335  {
336  $sCategory = $this->_oConfig->getOptionsCategory();
337  $sLangsPrefix = $this->_oConfig->getLangsPrefix();
338 
339  $iId = (int)$this->_oDb->getOne("SELECT `ID` FROM `sys_options_cats` WHERE `name`='" . $sCategory . "'");
340  if(empty($iId))
341  return MsgBox(_t($sLangsPrefix . 'msg_no_results'));
342 
344  $sResult = $oSettings->getForm();
345 
346  if($mixedResult !== true && !empty($mixedResult))
347  $sResult = $mixedResult . $sResult;
348 
349  return $sResult;
350  }
351  function setSettings($aData)
352  {
353  $sCategory = $this->_oConfig->getOptionsCategory();
354  $sLangsPrefix = $this->_oConfig->getLangsPrefix();
355 
356  $iId = (int)$this->_oDb->getOne("SELECT `ID` FROM `sys_options_cats` WHERE `name`='" . $sCategory . "'");
357  if(empty($iId))
358  return MsgBox(_t($sLangsPrefix . 'err_wrong_data'));
359 
361  return $oSettings->saveChanges($_POST);
362  }
363  function serviceUpdateDependentModules($sModuleUri = 'all', $bInstall = true)
364  {
365  $aModules = $sModuleUri == 'all' ? $this->_oDb->getModulesBy() : array($this->_oDb->getModuleByUri($sModuleUri));
366 
367  foreach($aModules as $aModule) {
368  if(!ChWsbRequest::serviceExists($aModule, 'get_payment_data'))
369  continue;
370 
371  $aData = ChWsbService::call($aModule['uri'], 'get_payment_data');
372  if($bInstall)
373  $this->_oDb->insertData($aData);
374  else
375  $this->_oDb->deleteData($aData);
376  }
377  }
378 
379 
385  function getCartHistory($iVendorId)
386  {
387  $aTopMenu = array(
388  'pmt-cart' => array('href' => CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'cart/', 'title' => _t($this->_sLangsPrefix . 'btn_cart')),
389  'pmt-cart-history' => array('href' => CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'history/' . ($iVendorId == CH_PMT_ADMINISTRATOR_ID ? 'site/' : ''), 'title' => _t($this->_sLangsPrefix . 'btn_history'), 'active' => 1)
390  );
391 
392  $sResult = $this->_oCart->getHistoryBlock($this->_iUserId, $iVendorId);
393  return array($sResult, $aTopMenu, array(), true, 'getBlockCaptionMenu');
394  }
395  function getCartContent($mixedVendor = null)
396  {
397  if(!$this->isLogged())
398  return MsgBox(_t($this->_sLangsPrefix . 'err_required_login'));
399 
400  $iVendorId = CH_PMT_EMPTY_ID;
401  if(is_string($mixedVendor))
402  $iVendorId = $this->_oDb->getVendorId($mixedVendor);
403  else if(is_int($mixedVendor))
404  $iVendorId = $mixedVendor;
405 
406  $aCartInfo = $this->_oCart->getInfo($this->_iUserId, $iVendorId);
407  if($iVendorId == CH_PMT_EMPTY_ID)
408  unset($aCartInfo[$this->_oConfig->getAdminId()]);
409 
410  $aTopMenu = array(
411  'pmt-cart' => array('href' => CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'cart/', 'title' => _t($this->_sLangsPrefix . 'btn_cart'), 'active' => 1),
412  'pmt-cart-history' => array('href' => CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'history/' . ($iVendorId == CH_PMT_ADMINISTRATOR_ID ? 'site/' : ''), 'title' => _t($this->_sLangsPrefix . 'btn_history'))
413  );
414 
415  $sResult = !empty($aCartInfo) ? $this->_oTemplate->displayCartContent($aCartInfo, $iVendorId) : MsgBox(_t($this->_sLangsPrefix . 'msg_no_results'));
416  return array($sResult, $aTopMenu, array(), true, 'getBlockCaptionMenu');
417  }
418  function serviceGetCartJs($bWrapped = true)
419  {
420  return $this->_oCart->getCartJs($bWrapped);
421  }
422  function serviceGetAddToCartJs($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect = false, $bWrapped = true)
423  {
424  if(is_string($mixedModuleId)) {
425  $aModuleInfo = $this->_oDb->getModuleByUri($mixedModuleId);
426  $iModuleId = isset($aModuleInfo['id']) ? (int)$aModuleInfo['id'] : 0;
427  } else
428  $iModuleId = (int)$mixedModuleId;
429 
430  if(empty($iModuleId))
431  return "";
432 
433  return $this->_oCart->getAddToCartJs($iVendorId, $iModuleId, $iItemId, $iItemCount, $bNeedRedirect, $bWrapped);
434  }
435  function serviceGetAddToCartLink($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect = false)
436  {
437  if(is_string($mixedModuleId)) {
438  $aModuleInfo = $this->_oDb->getModuleByUri($mixedModuleId);
439  $iModuleId = isset($aModuleInfo['id']) ? (int)$aModuleInfo['id'] : 0;
440  } else
441  $iModuleId = (int)$mixedModuleId;
442 
443  if(empty($iModuleId))
444  return "";
445 
446  return $this->_oCart->getAddToCartLink($iVendorId, $iModuleId, $iItemId, $iItemCount, $bNeedRedirect);
447  }
448  function serviceGetCartItemCount($iUserId, $iOldCount = 0)
449  {
450  if(!$this->isLogged())
451  return array('count' => 0, 'messages' => array());
452 
453  $aInfo = $this->_oCart->getInfo($this->_iUserId);
454 
455  $iCount = 0;
456  foreach($aInfo as $iVendorId => $aVendorCart)
457  $iCount += $aVendorCart['items_count'];
458 
459  return array(
460  'count' => $iCount,
461  'messages' => array()
462  );
463  }
465  {
466  if(!$this->isLogged())
467  return MsgBox(_t($this->_sLangsPrefix . 'err_required_login'));
468 
469  $aInfo = $this->_oCart->getInfo($this->_iUserId);
470  if(empty($aInfo))
471  return MsgBox(_t($this->_sLangsPrefix . 'msg_no_results'));
472 
473  return $this->_oTemplate->displayToolbarSubmenu($aInfo);
474  }
475  function serviceGetCartUrl()
476  {
477  if(!$this->isLogged())
478  return '';
479 
480  return CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'cart/';
481  }
482  function serviceGetCartItemDescriptor($iVendorId, $iModuleId, $iItemId, $iItemCount)
483  {
484  return $this->_oCart->getDescriptor($iVendorId, $iModuleId, $iItemId, $iItemCount);
485  }
486  function actionCartSubmit()
487  {
488  if(!$this->isLogged()) {
489  $this->_oTemplate->getPageCodeError($this->_sLangsPrefix . 'err_required_login');
490  return;
491  }
492 
493  $aData = &$_POST;
494 
495  if(isset($aData['pmt-delete']) && !empty($aData['items']))
496  foreach($aData['items'] as $sItem) {
497  list($iVendorId, $iModuleId, $iItemId, $iItemCount) = explode('_', $sItem);
498  $this->_oCart->deleteFromCart($this->_iUserId, $iVendorId, $iModuleId, $iItemId);
499  }
500  else if(isset($aData['pmt-checkout']) && !empty($aData['items'])) {
501  $sError = $this->initializeCheckout((int)$aData['vendor_id'], $aData['provider'], $aData['items']);
502  if(!empty($sError)){
503  $this->_oTemplate->getPageCodeError($sError, false);
504  return;
505  }
506  }
507 
508  header('Location: ' . CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'cart/');
509  exit;
510  }
511  function actionAddToCart($iVendorId, $iModuleId, $iItemId, $iItemCount)
512  {
513  $aResult = $this->_oCart->addToCart($this->_iUserId, $iVendorId, $iModuleId, $iItemId, $iItemCount);
514 
515  header('Content-Type:text/javascript; charset=utf-8');
516  return json_encode($aResult);
517  }
518  function serviceAddToCart($iVendorId, $iModuleId, $iItemId, $iItemCount)
519  {
520  return $this->_oCart->addToCart($this->_iUserId, $iVendorId, $iModuleId, $iItemId, $iItemCount);
521  }
525  function actionDeleteFromCart($iVendorId, $iModuleId, $iItemId)
526  {
527  $aResult = $this->_oCart->deleteFromCart($this->_iUserId, $iVendorId, $iModuleId, $iItemId);
528 
529  header('Content-Type:text/javascript; charset=utf-8');
530  return json_encode($aResult);
531  }
535  function actionEmptyCart($iVendorId)
536  {
537  $aResult = $this->_oCart->deleteFromCart($this->_iUserId, $iVendorId);
538 
539  header('Content-Type:text/javascript; charset=utf-8');
540  return json_encode($aResult);
541  }
542 
543 
544 
550  function serviceGetProviders($iVendorId, $sProvider = '')
551  {
552  $aResult = array();
553 
554  $aVendorProviders = $this->_oDb->getVendorInfoProviders($iVendorId, $sProvider);
555  foreach($aVendorProviders as $aProvider) {
556  $aProvider['caption_cart'] = _t($this->_sLangsPrefix . 'txt_cart_' . $aProvider['name']);
557 
558  $aResult[] = $aProvider;
559  }
560 
561  return $aResult;
562  }
563  function serviceInitializeCheckout($iVendorId, $sProvider, $aItems = array())
564  {
565  if(!is_array($aItems))
566  $aItems = array($aItems);
567 
568  return $this->initializeCheckout((int)$iVendorId, $sProvider, $aItems);
569  }
570  function initializeCheckout($iVendorId, $sProvider, $aItems = array())
571  {
572  if($iVendorId == CH_PMT_EMPTY_ID)
573  return MsgBox(_t($this->_sLangsPrefix . 'err_unknown_vendor'));
574 
575  $aProvider = $this->_oDb->getVendorInfoProviders($iVendorId, $sProvider);
576  $sClassPath = !empty($aProvider['class_file']) ? CH_DIRECTORY_PATH_ROOT . $aProvider['class_file'] : $this->_oConfig->getClassPath() . $aProvider['class_name'] . '.php';
577  if(empty($aProvider) || !file_exists($sClassPath))
578  return MsgBox(_t($this->_sLangsPrefix . 'err_incorrect_provider'));
579 
580  require_once($sClassPath);
581  $oProvider = new $aProvider['class_name']($this->_oDb, $this->_oConfig, $aProvider);
582 
583  $aInfo = $this->_oCart->getInfo($this->_iUserId, $iVendorId, $aItems);
584  if(empty($aInfo) || $aInfo['vendor_id'] == CH_PMT_EMPTY_ID || empty($aInfo['items']))
585  return MsgBox(_t($this->_sLangsPrefix . 'err_empty_order'));
586 
587  /*
588  * Process FREE (price = 0) items for LOGGED IN members
589  * WITHOUT processing via payment provider.
590  */
591  $bProcessedFree = false;
592  foreach($aInfo['items'] as $iIndex => $aItem)
593  if((int)$aInfo['client_id'] != 0 && (float)$aItem['price'] == 0) {
594  $aItemInfo = ChWsbService::call((int)$aItem['module_id'], 'register_cart_item', array($aInfo['client_id'], $aInfo['vendor_id'], $aItem['id'], $aItem['quantity'], $this->_oConfig->generateLicense()));
595  if(is_array($aItemInfo) && !empty($aItemInfo))
596  $bProcessedFree = true;
597 
598  $aInfo['items_count'] -= 1;
599  unset($aInfo['items'][$iIndex]);
600 
601  $sCartItems = $this->_oDb->getCartItems($aInfo['client_id']);
602  $sCartItems = trim(preg_replace("'" . implode(ChPmtCart::$DESCRIPTOR_DIVIDER, array($aInfo['vendor_id'], $aItem['module_id'], $aItem['id'], $aItem['quantity'])) . ":?'", "", $sCartItems), ":");
603  $this->_oDb->setCartItems($aInfo['client_id'], $sCartItems);
604  }
605 
606  if(empty($aInfo['items']))
607  return MsgBox(_t($this->_sLangsPrefix . ($bProcessedFree ? 'inf_successfully_processed_free' : 'err_empty_order')));
608 
609  $iPendingId = $this->_oDb->insertPending($this->_iUserId, $aProvider['name'], $aInfo);
610  if(empty($iPendingId))
611  return MsgBox(_t($this->_sLangsPrefix . 'err_access_db'));
612 
613  /*
614  * Perform Join WITHOUT processing via payment provider
615  * if a client ISN'T logged in and has only ONE FREE item in the card.
616  */
617  if((int)$aInfo['client_id'] == 0 && (int)$aInfo['items_count'] == 1) {
618  reset($aInfo['items']);
619  $aItem = current($aInfo['items']);
620 
621  if(!empty($aItem) && $aItem['price'] == 0) {
622  $this->_oDb->updatePending($iPendingId, array(
623  'order' => $this->_oConfig->generateLicense(),
624  'error_code' => '1',
625  'error_msg' => ''
626  ));
627 
628  $this->performJoin($iPendingId);
629  }
630  }
631 
632  $sError = $oProvider->initializeCheckout($iPendingId, $aInfo);
633  if(!empty($sError))
634  return MsgBox($sError);
635 
636  return '';
637  }
638  function actionFinalizeCheckout($sProvider, $mixedVendorId = "")
639  {
640  $aData = &$_REQUEST;
641 
642  $aProvider = is_numeric($mixedVendorId) && (int)$mixedVendorId != CH_PMT_EMPTY_ID ? $this->_oDb->getVendorInfoProviders((int)$mixedVendorId, $sProvider) : $this->_oDb->getProviders($sProvider);
643  $sClassPath = !empty($aProvider['class_file']) ? CH_DIRECTORY_PATH_ROOT . $aProvider['class_file'] : $this->_oConfig->getClassPath() . $aProvider['class_name'] . '.php';
644  if(empty($aProvider) || !file_exists($sClassPath)) {
645  $this->_onResultPage(array('message' => _t($this->_sLangsPrefix . 'err_incorrect_provider')));
646  exit;
647  }
648 
649  require_once($sClassPath);
650  $oProvider = new $aProvider['class_name']($this->_oDb, $this->_oConfig, $aProvider);
651 
652  $aResult = $oProvider->finalizeCheckout($aData);
653  if((int)$aResult['code'] == 1) {
654  $aPending = $this->_oDb->getPending(array('type' => 'id', 'id' => (int)$aResult['pending_id']));
655 
656  //--- Check "Pay Before Join" situation
657  if((int)$aPending['client_id'] == 0)
658  $this->performJoin((int)$aPending['id'], $aResult);
659 
660  //--- Register payment for purchased items in associated modules
661  $this->_oCart->updateInfo($aPending);
662 
663  if($oProvider->needRedirect()) {
664  header('Location: ' . $this->_oConfig->getReturnUrl());
665  exit;
666  }
667  }
668 
669  $this->_onResultPage($aResult);
670  exit;
671  }
672  function actionCheckoutFinished($sProvider, $mixedVendorId = "")
673  {
674  $aProvider = is_numeric($mixedVendorId) && (int)$mixedVendorId != CH_PMT_EMPTY_ID ? $this->_oDb->getVendorInfoProviders((int)$mixedVendorId, $sProvider) : $this->_oDb->getProviders($sProvider);
675  $sClassPath = !empty($aProvider['class_file']) ? CH_DIRECTORY_PATH_ROOT . $aProvider['class_file'] : $this->_oConfig->getClassPath() . $aProvider['class_name'] . '.php';
676  if(empty($aProvider) || !file_exists($sClassPath)) {
677  $this->_onResultPage(array('message' => _t($this->_sLangsPrefix . 'err_incorrect_provider')));
678  exit;
679  }
680 
681  require_once($sClassPath);
682  $oProvider = new $aProvider['class_name']($this->_oDb, $this->_oConfig, $aProvider);
683  $aResult = $oProvider->checkoutFinished();
684 
685  $this->_onResultPage($aResult);
686  exit;
687  }
688 
702  function serviceGetTransactionsInfo($aConditions)
703  {
704  return $this->_oDb->getProcessed(array('type' => 'mixed', 'conditions' => $aConditions));
705  }
706 
707  function serviceGetOption($sOption)
708  {
709  $sOptionPrefix = $this->_oConfig->getOptionsPrefix();
710  return $this->_oDb->getParam($sOptionPrefix . $sOption);
711  }
712 
714  {
715  if($oAlert->sUnit != 'profile' || !in_array($oAlert->sAction, array('join', 'delete')))
716  return;
717 
718  switch($oAlert->sAction) {
719  case 'join':
720  $this->_onProfileJoin($oAlert->iObject);
721  break;
722 
723  case 'delete':
724  $this->_oDb->onProfileDelete($oAlert->iObject);
725  break;
726  }
727  }
728 
734  function performJoin($iPendingId, $aPayment = array())
735  {
736  $oSession = ChWsbSession::getInstance();
737  $oSession->setValue($this->_sSessionKeyPending, (int)$iPendingId);
738 
739  if(!empty($aPayment['payer_name']) && !empty($aPayment['payer_email'])) {
740  ch_import('ChWsbEmailTemplates');
741  $oEmailTemplates = new ChWsbEmailTemplates();
742 
743  $aTemplate = $oEmailTemplates->parseTemplate($this->_sEmailTemplatesPrefix . 'paid_need_join', array(
744  'RealName' => $aPayment['payer_name'],
745  'JoinLink' => ch_append_url_params($this->_oConfig->getJoinUrl(), array($this->_sRequestKeyPending => (int)$iPendingId))
746  ));
747 
748  sendMail($aPayment['payer_email'], $aTemplate['Subject'], $aTemplate['Body'], 0, array(), 'html', false, true);
749  }
750 
751  header('Location: ' . $this->_oConfig->getJoinUrl());
752  exit;
753  }
754  function actionJoin()
755  {
756  $oSession = ChWsbSession::getInstance();
757  $iPendingId = (int)$oSession->getValue($this->_sSessionKeyPending);
758 
759  if(empty($iPendingId) && ch_get($this->_sRequestKeyPending) !== false) {
760  $iPendingId = (int)ch_get($this->_sRequestKeyPending);
761 
762  $oSession->setValue($this->_sSessionKeyPending, $iPendingId);
763  }
764 
765  if(empty($iPendingId)) {
766  $this->_oTemplate->getPageCodeError($this->_sLangsPrefix . 'err_not_allowed');
767  return;
768  }
769 
770  $aPending = $this->_oDb->getPending(array('type' => 'id', 'id' => $iPendingId));
771  if(empty($aPending['order']) || (int)$aPending['error_code'] != 1) {
772  $this->_oTemplate->getPageCodeError($this->_sLangsPrefix . 'err_not_processed');
773  return;
774  }
775 
776  if((int)$aPending['processed'] == 1) {
777  $this->_oTemplate->getPageCodeError($this->_sLangsPrefix . 'err_already_processed');
778  return;
779  }
780 
781  //--- 'System' -> 'Join after Payment' for Alerts Engine ---//
782  $bOverride = false;
783  $sOverrideError = '';
784 
785  ch_import('ChWsbAlerts');
786  $oAlert = new ChWsbAlerts('system', 'join_after_payment', 0, 0, array('override' => &$bOverride, 'override_error' => &$sOverrideError));
787  $oAlert->alert();
788 
789  if($bOverride)
790  return;
791  //--- 'System' -> 'Join after Payment' for Alerts Engine ---//
792 
793  ch_import('ProfileFields', $this->_aModule);
794  $oProfileFields = new ChPmtProfileFields(1, $this);
795 
796  ch_import('ChWsbJoinProcessor');
797  $oJoin = new ChWsbJoinProcessor(array('profile_fields' => $oProfileFields));
798 
799  $sBlockCaption = _t($this->_sLangsPrefix . 'bcpt_join');
800  $sBlockContent = (!empty($sOverrideError) ? MsgBox(_t($sOverrideError)) : '') . $oJoin->process();
801 
802  $aParams = array(
803  'index' => 1,
804  'css' => array('join.css'),
805  'js' => array('join.js', 'jquery.form.min.js'),
806  'title' => array(
807  'page' => _t($this->_sLangsPrefix . 'pcpt_join')
808  ),
809  'content' => array(
810  'page_main_code' => DesignBoxContent($sBlockCaption, $sBlockContent, 11)
811  )
812  );
813  $this->_oTemplate->getPageCode($aParams);
814  }
815 
816 
817 
824  {
825  $oSession = ChWsbSession::getInstance();
826  $iPendingId = (int)$oSession->getValue($this->_sSessionKeyPending);
827 
828  if(empty($iProfileId) || empty($iPendingId))
829  return;
830 
831  $aPending = $this->_oDb->getPending(array('type' => 'id', 'id' => $iPendingId));
832  if(empty($aPending) || (isset($aPending['client_id']) && (int)$aPending['client_id'] != 0))
833  return;
834 
835  if(!$this->_oDb->updatePending($iPendingId, array('client_id' => $iProfileId)))
836  return;
837 
838  $this->_oCart->updateInfo($iPendingId);
839 
840  $oSession->unsetValue($this->_sSessionKeyPending);
841  }
843  {
844  echo $this->_oTemplate->parseHtmlByTemplateName('on_result', array('message' => $aResult['message']));
845  }
847  {
848 
849  return $this->_oTemplate->parseHtmlByTemplateName('on_result_inline', array(
850  'js_object' => $aResult['js_object'],
851  'params' => json_encode(array(
852  'code' => $aResult['code'],
853  'message' => MsgBox(_t($aResult['message'])),
854  'parent_id' => $aResult['parent_id']
855  ))
856  ));
857  }
859  {
860  global $_page;
862 
863  $_page['name_index'] = isset($aResult['page_index']) ? (int)$aResult['page_index'] : 0;
864  $_page['header'] = !empty($aResult['page_caption']) ? $aResult['page_caption'] : _t($this->_sLangsPrefix . 'pcpt_payment_result');
865  $_page['header_text'] = !empty($aResult['block_caption']) ? $aResult['block_caption'] : _t($this->_sLangsPrefix . 'bcpt_payment_result');
866 
867  $sContent = $this->_oTemplate->parseHtmlByName('default_padding.html', array(
868  'content' => !empty($aResult['message']) ? MsgBox($aResult['message']) : ''
869  ));
870 
871  $_page_cont[$_page['name_index']]['page_main_code'] = $sContent;
872  PageCode($GLOBALS['oSysTemplate']);
873  }
874 }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
header
</code > Be careful enabling this directive if you have a redirector script that does not use the< code > Location</code > HTTP header
Definition: URI.MungeResources.txt:10
$oSettings
$oSettings
Definition: advanced_settings.php:20
CH_PMT_ADMINISTRATOR_ID
const CH_PMT_ADMINISTRATOR_ID
Definition: ChPmtModule.php:17
ChPmtModule\serviceGetOrdersUrl
serviceGetOrdersUrl()
Definition: ChPmtModule.php:166
ChPmtModule\serviceResponse
serviceResponse($oAlert)
Definition: ChPmtModule.php:713
ChPmtModule\$_sGeneralPrefix
$_sGeneralPrefix
Definition: ChPmtModule.php:85
CH_PMT_ORDERS_TYPE_PROCESSED
const CH_PMT_ORDERS_TYPE_PROCESSED
Definition: ChPmtModule.php:12
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
ChWsbModule\isLogged
isLogged()
Definition: ChWsbModule.php:113
ChPmtModule\_onResultInline
_onResultInline($aResult)
Definition: ChPmtModule.php:846
ChWsbRequest\serviceExists
static serviceExists($mixedModule, $sMethod, $sClass="Module")
Definition: ChWsbRequest.php:70
ChPmtModule\$_oOrders
$_oOrders
Definition: ChPmtModule.php:83
ChPmtModule\$_sSessionKeyPending
$_sSessionKeyPending
Definition: ChPmtModule.php:89
$sResult
$sResult
Definition: advanced_settings.php:26
ChWsbModule\getUserId
getUserId()
Definition: ChWsbModule.php:122
$aModule
$aModule
Definition: classifieds.php:21
$_page
$_page['name_index']
Definition: about_us.php:13
ChPmtModule\_onResultAlert
_onResultAlert($aResult)
Definition: ChPmtModule.php:842
ChWsbEmailTemplates
Definition: ChWsbEmailTemplates.php:11
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$aResult
$aResult
Definition: index.php:19
ChPmtModule\_onResultPage
_onResultPage($aResult)
Definition: ChPmtModule.php:858
ChPmtModule\$_sLangsPrefix
$_sLangsPrefix
Definition: ChPmtModule.php:86
$_page_cont
$_page_cont[$_ni]['page_main_code']
Definition: about_us.php:24
ch_get
ch_get($sName)
Definition: utils.inc.php:1664
$oAlert
$oAlert
Definition: embed.php:15
ChPmtModule\serviceUpdateDependentModules
serviceUpdateDependentModules($sModuleUri='all', $bInstall=true)
Definition: ChPmtModule.php:363
sendMail
sendMail( $sRecipientEmail, $sMailSubject, $sMailBody, $iRecipientID=0, $aPlus=array(), $sEmailFlag='html', $isDisableAlert=false, $bForceSend=false)
Definition: utils.inc.php:461
ChWsbModule\$_oConfig
$_oConfig
Definition: ChWsbModule.php:48
ChPmtModule\getOrdersBlock
getOrdersBlock($sType, $iUserId=CH_PMT_EMPTY_ID)
Definition: ChPmtModule.php:162
ChPmtModule\serviceInitializeCheckout
serviceInitializeCheckout($iVendorId, $sProvider, $aItems=array())
Definition: ChPmtModule.php:563
ChPmtModule\initializeCheckout
initializeCheckout($iVendorId, $sProvider, $aItems=array())
Definition: ChPmtModule.php:570
php
ChPmtModule
Definition: ChPmtModule.php:79
ChPmtModule\$_oDetails
$_oDetails
Definition: ChPmtModule.php:81
$iId
$iId
Definition: license.php:15
CH_PMT_ORDERS_TYPE_SUBSCRIPTION
const CH_PMT_ORDERS_TYPE_SUBSCRIPTION
Definition: ChPmtModule.php:13
ChPmtModule\serviceGetAddToCartLink
serviceGetAddToCartLink($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect=false)
Definition: ChPmtModule.php:435
ChPmtModule\$_sRequestKeyPending
$_sRequestKeyPending
Definition: ChPmtModule.php:90
$iPerPage
else $iPerPage
Definition: browse.php:61
ChPmtModule\serviceGetCartItemCount
serviceGetCartItemCount($iUserId, $iOldCount=0)
Definition: ChPmtModule.php:448
ChPmtModule\_onProfileJoin
_onProfileJoin($iProfileId)
Definition: ChPmtModule.php:823
ChPmtModule\getDetailsForm
getDetailsForm($iUserId=CH_PMT_EMPTY_ID)
Definition: ChPmtModule.php:302
$aInfo
$aInfo
Definition: constants.inc.php:21
ChPmtModule\actionManualOrderSubmit
actionManualOrderSubmit()
Definition: ChPmtModule.php:235
ChPmtModule\getManualOrderWindow
getManualOrderWindow()
Definition: ChPmtModule.php:158
ChPmtModule\getSettingsForm
getSettingsForm($mixedResult)
Definition: ChPmtModule.php:334
ChWsbAlerts
Definition: ChWsbAlerts.php:39
ChPmtModule\__construct
__construct($aModule)
Definition: ChPmtModule.php:95
exit
exit
Definition: cart.php:21
ChPmtModule\actionCheckoutFinished
actionCheckoutFinished($sProvider, $mixedVendorId="")
Definition: ChPmtModule.php:672
$sType
$sType
Definition: actions.inc.php:11
$iIndex
$iIndex
Definition: bottom_menu_compose.php:142
CH_PMT_ORDERS_TYPE_PENDING
const CH_PMT_ORDERS_TYPE_PENDING
Definition: ChPmtModule.php:11
ChPmtCart\$DESCRIPTOR_DIVIDER
static $DESCRIPTOR_DIVIDER
Definition: ChPmtCart.php:10
ChWsbJoinProcessor
Definition: ChWsbJoinProcessor.php:17
ch_append_url_params
ch_append_url_params($sUrl, $mixedParams)
Definition: utils.inc.php:1697
ChPmtModule\serviceGetOption
serviceGetOption($sOption)
Definition: ChPmtModule.php:707
getNickName
getNickName( $ID='')
Definition: profiles.inc.php:461
$_REQUEST
$_REQUEST['action']
Definition: cmd.php:11
ChPmtModule\actionDeleteFromCart
actionDeleteFromCart($iVendorId, $iModuleId, $iItemId)
Definition: ChPmtModule.php:525
ChPmtModule\serviceGetCartItemDescriptor
serviceGetCartItemDescriptor($iVendorId, $iModuleId, $iItemId, $iItemCount)
Definition: ChPmtModule.php:482
ChPmtModule\actionGetItems
actionGetItems($iModuleId)
Definition: ChPmtModule.php:173
ChPmtModule\getCartHistory
getCartHistory($iVendorId)
Definition: ChPmtModule.php:385
ChPmtModule\serviceAddToCart
serviceAddToCart($iVendorId, $iModuleId, $iItemId, $iItemCount)
Definition: ChPmtModule.php:518
CH_PMT_ORDERS_TYPE_HISTORY
const CH_PMT_ORDERS_TYPE_HISTORY
Definition: ChPmtModule.php:14
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
ChPmtModule\serviceGetTransactionsInfo
serviceGetTransactionsInfo($aConditions)
Definition: ChPmtModule.php:702
ChWsbModule
Definition: ChWsbModule.php:41
$sContent
$sContent
Definition: bottom_menu_compose.php:169
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
ChPmtModule\getCartContent
getCartContent($mixedVendor=null)
Definition: ChPmtModule.php:395
ChPmtModule\actionGetOrders
actionGetOrders()
Definition: ChPmtModule.php:202
ChPmtModule\actionAddToCart
actionAddToCart($iVendorId, $iModuleId, $iItemId, $iItemCount)
Definition: ChPmtModule.php:511
ChPmtModule\$_aOrderTypes
$_aOrderTypes
Definition: ChPmtModule.php:84
PageCode
PageCode($oTemplate=null)
Definition: design.inc.php:91
ChPmtModule\actionEmptyCart
actionEmptyCart($iVendorId)
Definition: ChPmtModule.php:535
ChPmtModule\$_iUserId
$_iUserId
Definition: ChPmtModule.php:80
ChPmtProfileFields
Definition: ChPmtProfileFields.php:10
CH_PMT_EMPTY_ID
const CH_PMT_EMPTY_ID
Definition: ChPmtModule.php:16
ChPmtModule\serviceGetAdmins
serviceGetAdmins()
Definition: ChPmtModule.php:313
ChWsbSession\getInstance
static getInstance()
Definition: ChWsbSession.php:28
ChWsbAdminSettings
Definition: ChWsbAdminSettings.php:35
ChPmtModule\serviceGetCurrencyInfo
serviceGetCurrencyInfo()
Definition: ChPmtModule.php:306
CH_TAGS_STRIP
const CH_TAGS_STRIP
Definition: utils.inc.php:22
ChPmtModule\serviceGetProviders
serviceGetProviders($iVendorId, $sProvider='')
Definition: ChPmtModule.php:550
ChWsbModule\$_oDb
$_oDb
Definition: ChWsbModule.php:44
ChPmtModule\serviceGetCartJs
serviceGetCartJs($bWrapped=true)
Definition: ChPmtModule.php:418
$aModules
$aModules
Definition: constants.inc.php:29
ChPmtModule\serviceGetCartUrl
serviceGetCartUrl()
Definition: ChPmtModule.php:475
ChPmtModule\setSettings
setSettings($aData)
Definition: ChPmtModule.php:351
ChPmtModule\performJoin
performJoin($iPendingId, $aPayment=array())
Definition: ChPmtModule.php:734
DesignBoxContent
DesignBoxContent($title, $content, $db_num=0, $caption_item='', $bottom_item='')
Definition: design.inc.php:78
$sError
$sError
Definition: index.php:425
ChPmtModule\actionJoin
actionJoin()
Definition: ChPmtModule.php:754
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChWsbService\call
static call($mixed, $sMethod, $aParams=array(), $sClass='Module')
Definition: ChWsbService.php:32
ChPmtModule\actionCartSubmit
actionCartSubmit()
Definition: ChPmtModule.php:486
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChPmtModule\serviceGetAddToCartJs
serviceGetAddToCartJs($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect=false, $bWrapped=true)
Definition: ChPmtModule.php:422
ChPmtModule\getExtraJs
getExtraJs($sType)
Definition: ChPmtModule.php:137
ChPmtModule\$_sEmailTemplatesPrefix
$_sEmailTemplatesPrefix
Definition: ChPmtModule.php:87
ChPmtModule\actionGetOrder
actionGetOrder()
Definition: ChPmtModule.php:186
ChPmtModule\actionOrdersSubmit
actionOrdersSubmit($sType)
Definition: ChPmtModule.php:252
$iProfileId
if( $sMembersList) $iProfileId
Definition: communicator.php:29
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
ChPmtModule\$_oCart
$_oCart
Definition: ChPmtModule.php:82
ChPmtModule\getMoreWindow
getMoreWindow()
Definition: ChPmtModule.php:154
ChPmtModule\serviceGetCartItems
serviceGetCartItems()
Definition: ChPmtModule.php:464
ChPmtModule\actionFinalizeCheckout
actionFinalizeCheckout($sProvider, $mixedVendorId="")
Definition: ChPmtModule.php:638