BxPaymentGridPending.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Payment Payment
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxPaymentGridPending extends BxBaseModPaymentGridOrders
  12. {
  13. public function __construct ($aOptions, $oTemplate = false)
  14. {
  15. $this->MODULE = 'bx_payment';
  16. parent::__construct ($aOptions, $oTemplate);
  17. $this->_sOrdersType = 'pending';
  18. }
  19. public function getFormBlockTitleAPI($sAction, $iId = 0)
  20. {
  21. $sResult = '';
  22. switch($sAction) {
  23. case 'process':
  24. $sResult = _t($this->_sLangsPrefix . 'popup_title_ods_order_' . $this->_sOrdersType . '_process');
  25. break;
  26. }
  27. return $sResult;
  28. }
  29. public function getFormCallBackUrlAPI($sAction, $iId = 0)
  30. {
  31. return '/api.php?r=system/perfom_action_api/TemplServiceGrid/&params[]=&o=' . $this->_sObject . '&a=' . $sAction . '&id=' . $iId;
  32. }
  33. public function performActionProcess()
  34. {
  35. $aIds = bx_get('ids');
  36. if(!$aIds || !is_array($aIds)) {
  37. $iId = (int)bx_get('id');
  38. if(!$iId)
  39. return $this->_bIsApi ? [] : echoJson([]);
  40. $aIds = array($iId);
  41. }
  42. $iId = (int)$aIds[0];
  43. $sAction = 'process';
  44. $sFormObject = $this->_oModule->_oConfig->getObject('form_pendings');
  45. $sFormDisplay = $this->_oModule->_oConfig->getObject('form_display_pendings_process');
  46. $oForm = BxDolForm::getObjectInstance($sFormObject, $sFormDisplay, $this->_oModule->_oTemplate);
  47. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction;
  48. $oForm->aInputs['id']['value'] = $iId;
  49. $oForm->aInputs['seller_id']['value'] = $this->_aQueryAppend['seller_id'];
  50. $oForm->initChecker();
  51. if($oForm->isSubmittedAndValid()) {
  52. $iId = $oForm->getCleanValue('id');
  53. $this->_oModule->_oDb->updateOrderPending($iId, [
  54. 'order' => $oForm->getCleanValue('order'),
  55. 'error_code' => 0,
  56. 'error_msg' => 'Manually processed'
  57. ]);
  58. if($this->_oModule->registerPayment($iId))
  59. $aRes = $this->_bIsApi ? [] : ['grid' => $this->getCode(false), 'blink' => $iId];
  60. else
  61. $aRes = ($sMsg = _t($this->_sLangsPrefix . 'err_cannot_perform')) && $this->_bIsApi ? [bx_api_get_msg($sMsg)] : ['msg' => $sMsg];
  62. return $this->_bIsApi ? $aRes : echoJson($aRes);
  63. }
  64. if($this->_bIsApi)
  65. return $this->getFormBlockAPI($oForm, $sAction, $iId);
  66. $sKey = 'order_' . $this->_sOrdersType . '_process';
  67. $sId = $this->_oModule->_oConfig->getHtmlIds('pending', $sKey);
  68. $sTitle = _t($this->_sLangsPrefix . 'popup_title_ods_' . $sKey);
  69. $sContent = BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $this->_oModule->_oTemplate->parseHtmlByName('order_pending_process.html', [
  70. 'form_id' => $oForm->aFormAttrs['id'],
  71. 'form' => $oForm->getCode(true),
  72. 'object' => $this->_sObject,
  73. 'action' => $sAction
  74. ]));
  75. echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]]);
  76. }
  77. protected function _getActionCancel ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
  78. {
  79. if($this->_bIsApi)
  80. return array_merge($a, ['name' => $sKey, 'type' => 'callback', 'on_callback' => 'hide_row']);
  81. return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  82. }
  83. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  84. {
  85. if(empty($this->_aQueryAppend['seller_id']))
  86. return array();
  87. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `tt`.`seller_id`=?", $this->_aQueryAppend['seller_id']);
  88. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  89. }
  90. }
  91. /** @} */