BxBaseModPaymentConfig.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 BasePayment Base classes for Payment like modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModPaymentConfig extends BxBaseModGeneralConfig
  12. {
  13. protected $_oDb;
  14. protected $_sCurrencySign;
  15. protected $_sCurrencyCode;
  16. protected $_iSiteAdmin;
  17. protected $_bSingleSeller;
  18. protected $_aPerPage;
  19. protected $_aHtmlIds;
  20. protected $_sAnimationEffect;
  21. protected $_iAnimationSpeed;
  22. function __construct($aModule)
  23. {
  24. parent::__construct($aModule);
  25. $this->CNF = array_merge($this->CNF, [
  26. // some params
  27. 'PARAM_CURRENCY_CODE' => $this->_sName . '_default_currency_code',
  28. 'PARAM_CMSN_INVOICE_ISSUE_DAY' => 1, //the first day of month
  29. 'PARAM_CMSN_INVOICE_LIFETIME' => 4, //in days
  30. 'PARAM_CMSN_INVOICE_EXPIRATION_NOTIFY' => 1, //in days, before expiration date
  31. 'PARAM_CMSN_DATE_FORMAT' => 'd.m.Y',
  32. 'PARAM_CMSN_DATE_TIME_FORMAT' => 'd.m.Y H:i',
  33. // objects
  34. 'OBJECT_FORM_DETAILES' => $this->_sName . '_form_details',
  35. 'OBJECT_FORM_DETAILES_EDIT' => $this->_sName . '_form_details_edit',
  36. 'OBJECT_FORM_PRELISTS_CURRENCIES' => '',
  37. 'PROVIDER_GENERIC' => 'generic',
  38. 'KEY_SESSION_PENDING' => $this->_sName . '_pending_id',
  39. 'KEY_REQUEST_PENDING' => $this->_sName . '_pending_id',
  40. 'DIVIDER_DESCRIPTOR' => '_',
  41. 'DIVIDER_DESCRIPTORS' => ':',
  42. 'DIVIDER_GRID_FILTERS' => '#-#',
  43. ]);
  44. $this->_aPrefixes = [
  45. 'general' => $this->_sName . '_',
  46. 'langs' => '_' . $this->_sName . '_',
  47. 'options' => $this->_sName . '_'
  48. ];
  49. $this->_aObjects = array_merge($this->_aObjects, [
  50. 'form_details' => $this->CNF['OBJECT_FORM_DETAILES'],
  51. 'form_display_details_edit' => $this->CNF['OBJECT_FORM_DETAILES_EDIT'],
  52. 'form_pendings' => $this->_sName . '_form_pendings',
  53. 'form_processed' => $this->_sName . '_form_processed',
  54. 'form_display_pendings_process' => $this->_sName . '_form_pendings_process',
  55. 'form_display_processed_add' => $this->_sName . '_form_processed_add',
  56. 'form_commissions' => $this->_sName . '_form_commissions',
  57. 'form_display_commissions_add' => $this->_sName . '_form_commissions_add',
  58. 'form_display_commissions_edit' => $this->_sName . '_form_commissions_edit',
  59. 'form_invoices' => $this->_sName . '_form_invoices',
  60. 'form_display_invoices_edit' => $this->_sName . '_form_invoices_edit',
  61. 'menu_dashboard' => 'sys_account_dashboard',
  62. 'menu_cart_submenu' => $this->_sName . '_menu_cart_submenu',
  63. 'menu_orders_submenu' => $this->_sName . '_menu_orders_submenu',
  64. 'menu_sbs_submenu' => $this->_sName . '_menu_sbs_submenu',
  65. 'menu_sbs_actions' => $this->_sName . '_menu_sbs_actions',
  66. 'grid_providers' => $this->_sName . '_grid_providers',
  67. 'grid_history' => $this->_sName . '_grid_orders_history',
  68. 'grid_processed' => $this->_sName . '_grid_orders_processed',
  69. 'grid_pending' => $this->_sName . '_grid_orders_pending',
  70. 'grid_commissions' => $this->_sName . '_grid_commissions',
  71. 'grid_invoices' => $this->_sName . '_grid_invoices',
  72. 'grid_carts' => $this->_sName . '_grid_carts',
  73. 'grid_cart' => $this->_sName . '_grid_cart',
  74. 'grid_sbs_list_my' => $this->_sName . '_grid_sbs_list_my',
  75. 'grid_sbs_list_all' => $this->_sName . '_grid_sbs_list_all',
  76. 'grid_sbs_history' => $this->_sName . '_grid_sbs_history',
  77. ]);
  78. $this->_aPerPage = [];
  79. $this->_aHtmlIds = [];
  80. $this->_sAnimationEffect = 'fade';
  81. $this->_iAnimationSpeed = 'slow';
  82. }
  83. public function init(&$oDb)
  84. {
  85. $this->_oDb = $oDb;
  86. $sPrefix = $this->getPrefix('options');
  87. $this->_sCurrencyCode = (string)$this->_oDb->getParam($this->CNF['PARAM_CURRENCY_CODE']);
  88. $this->_sCurrencySign = $this->retrieveCurrencySign($this->_sCurrencyCode);
  89. $this->_iSiteAdmin = (int)$this->_oDb->getParam($sPrefix . 'site_admin');
  90. $this->_bSingleSeller = $this->_oDb->getParam($sPrefix . 'single_seller') == 'on';
  91. }
  92. public function getDefaultCurrencySign()
  93. {
  94. return $this->_sCurrencySign;
  95. }
  96. public function getDefaultCurrencyCode()
  97. {
  98. return $this->_sCurrencyCode;
  99. }
  100. public function getSiteAdmin()
  101. {
  102. return $this->_iSiteAdmin;
  103. }
  104. public function isSiteAdmin($iProfileId = 0)
  105. {
  106. if(empty($iProfileId))
  107. $iProfileId = bx_get_logged_profile_id();
  108. return $iProfileId == $this->_iSiteAdmin;
  109. }
  110. public function isSingleSeller()
  111. {
  112. return $this->_bSingleSeller;
  113. }
  114. public function getInvoiceIssueDay()
  115. {
  116. $sKey = 'PARAM_CMSN_INVOICE_ISSUE_DAY';
  117. return is_numeric($this->CNF[$sKey]) ? $this->CNF[$sKey] : $this->_oDb->getParam($this->CNF[$sKey]);
  118. }
  119. public function getInvoiceLifetime()
  120. {
  121. $sKey = 'PARAM_CMSN_INVOICE_LIFETIME';
  122. return is_numeric($this->CNF[$sKey]) ? $this->CNF[$sKey] : $this->_oDb->getParam($this->CNF[$sKey]);
  123. }
  124. public function getInvoiceExpirationNotify()
  125. {
  126. $sKey = 'PARAM_CMSN_INVOICE_EXPIRATION_NOTIFY';
  127. return is_numeric($this->CNF[$sKey]) ? $this->CNF[$sKey] : $this->_oDb->getParam($this->CNF[$sKey]);
  128. }
  129. public function getKey($sType)
  130. {
  131. $sResult = '';
  132. if(empty($sType) || !isset($this->CNF[$sType]))
  133. return $sResult;
  134. return $this->CNF[$sType];
  135. }
  136. public function getUrl($sType, $aParams = array(), $bSsl = false)
  137. {
  138. $sResult = '';
  139. if(empty($sType) || !isset($this->CNF[$sType]))
  140. return $sResult;
  141. if(strncmp($this->CNF[$sType], BX_DOL_URL_ROOT, strlen(BX_DOL_URL_ROOT)) === 0)
  142. $sResult = bx_append_url_params($this->CNF[$sType], $aParams);
  143. else
  144. $sResult = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($this->CNF[$sType], $aParams));
  145. return $bSsl ? $this->http2https($sResult) : $sResult;
  146. }
  147. public function getDivider($sType)
  148. {
  149. $sResult = '';
  150. if(empty($sType) || !isset($this->CNF[$sType]))
  151. return $sResult;
  152. return $this->CNF[$sType];
  153. }
  154. public function getPerPage($sType = 'default')
  155. {
  156. if(empty($sType))
  157. return $this->_aPerPage;
  158. return isset($this->_aPerPage[$sType]) ? $this->_aPerPage[$sType] : '';
  159. }
  160. public function getHtmlIds($sType, $sKey = '')
  161. {
  162. if(empty($sKey))
  163. return isset($this->_aHtmlIds[$sType]) ? $this->_aHtmlIds[$sType] : array();
  164. return isset($this->_aHtmlIds[$sType][$sKey]) ? $this->_aHtmlIds[$sType][$sKey] : '';
  165. }
  166. public function getAnimationEffect()
  167. {
  168. return $this->_sAnimationEffect;
  169. }
  170. public function getAnimationSpeed()
  171. {
  172. return $this->_iAnimationSpeed;
  173. }
  174. public function getLicense()
  175. {
  176. list($fMilliSec, $iSec) = explode(' ', microtime());
  177. $fSeed = (float)$iSec + ((float)$fMilliSec * 100000);
  178. srand((int)$fSeed);
  179. $sResult = '';
  180. for($i=0; $i < 16; ++$i) {
  181. switch(rand(1,2)) {
  182. case 1:
  183. $c = chr(rand(ord('A'),ord('Z')));
  184. break;
  185. case 2:
  186. $c = chr(rand(ord('0'),ord('9')));
  187. break;
  188. }
  189. $sResult .= $c;
  190. }
  191. return $sResult;
  192. }
  193. public function formatDate($iTs)
  194. {
  195. return gmdate($this->CNF['PARAM_CMSN_DATE_FORMAT'], $iTs);
  196. }
  197. public function formatDateTime($iTs)
  198. {
  199. return gmdate($this->CNF['PARAM_CMSN_DATE_TIME_FORMAT'], $iTs);
  200. }
  201. public function retrieveCurrencySign($sCode)
  202. {
  203. if(empty($sCode))
  204. return '';
  205. $aCurrencies = BxDolForm::getDataItems($this->CNF['OBJECT_FORM_PRELISTS_CURRENCIES'], false, BX_DATA_VALUES_ADDITIONAL);
  206. if(!isset($aCurrencies[$sCode]))
  207. return '';
  208. return $aCurrencies[$sCode];
  209. }
  210. }
  211. /** @} */