BxCreditsModule.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  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 Credits Credits
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_CREDITS_TRANSFER_TYPE_PURCHASE', 'purchase');
  12. define('BX_CREDITS_TRANSFER_TYPE_CHECKOUT', 'checkout');
  13. define('BX_CREDITS_TRANSFER_TYPE_CANCELLATION', 'cancellation');
  14. define('BX_CREDITS_TRANSFER_TYPE_GRANT', 'grant');
  15. define('BX_CREDITS_TRANSFER_TYPE_SEND', 'send');
  16. define('BX_CREDITS_TRANSFER_TYPE_WITHDRAW', 'withdraw');
  17. define('BX_CREDITS_TRANSFER_TYPE_SERVICE', 'service');
  18. define('BX_CREDITS_DIRECTION_IN', 'in');
  19. define('BX_CREDITS_DIRECTION_OUT', 'out');
  20. define('BX_CREDITS_ORDER_TYPE_SINGLE', 'single'); //--- one-time payment
  21. define('BX_CREDITS_ORDER_TYPE_RECURRING', 'recurring'); //--- recurring payment (subscription)
  22. class BxCreditsModule extends BxBaseModGeneralModule
  23. {
  24. function __construct(&$aModule)
  25. {
  26. parent::__construct($aModule);
  27. }
  28. public function actionGetProfiles()
  29. {
  30. $sTerm = bx_get('term');
  31. $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  32. echoJson($a);
  33. }
  34. public function actionCheckBundleName()
  35. {
  36. $CNF = &$this->_oConfig->CNF;
  37. $sName = bx_process_input(bx_get('name'));
  38. if(empty($sName))
  39. return echoJson(array());
  40. $sResult = '';
  41. $iId = (int)bx_get('id');
  42. if(!empty($iId)) {
  43. $aBundle = $this->_oDb->getBundle(array('type' => 'id', 'id' => $iId));
  44. if(strcmp($sName, $aBundle[$CNF['FIELD_NAME']]) == 0)
  45. $sResult = $sName;
  46. }
  47. echoJson(array(
  48. 'name' => !empty($sResult) ? $sResult : $this->_oConfig->getBundleName($sName)
  49. ));
  50. }
  51. public function actionCheckout()
  52. {
  53. $iBuyerId = bx_get_logged_profile_id();
  54. if(!$iBuyerId)
  55. return echoJson(array('code' => 1, 'msg' => _t('_bx_credits_err_unknown_buyer')));
  56. $aData = $this->_oConfig->getCheckoutData();
  57. if(empty($aData) || !is_array($aData))
  58. return echoJson(array('code' => 2, 'msg' => _t('_bx_credits_err_incorrect_data')));
  59. $iSellerId = (int)$aData['seller'];
  60. $fAmount = (float)$aData['amount'];
  61. $fBalance = (float)$this->_oDb->getProfile(array('type' => 'balance', 'id' => $iBuyerId));
  62. if($fAmount > $fBalance)
  63. return echoJson(array('code' => 3, 'msg' => _t('_bx_credits_err_low_balance')));
  64. $sOrder = $this->_oConfig->getOrder();
  65. $sInfo = '_bx_credits_txt_history_info_checkout';
  66. $sData = serialize(array(
  67. 'conversion' => $this->_oConfig->getConversionRateUse(),
  68. 'precision' => $this->_oConfig->getPrecision()
  69. ));
  70. $this->updateProfileBalance($iBuyerId, $iSellerId, -$fAmount, BX_CREDITS_TRANSFER_TYPE_CHECKOUT, $sOrder, $sInfo, $sData);
  71. $this->updateProfileBalance($iSellerId, $iBuyerId, $fAmount, BX_CREDITS_TRANSFER_TYPE_CHECKOUT, $sOrder, $sInfo, $sData);
  72. bx_alert($this->getName(), 'checkout', 0, false, array(
  73. 'seller' => $iSellerId,
  74. 'buyer' => $iBuyerId,
  75. 'amount' => $fAmount,
  76. 'order' => $sOrder
  77. ));
  78. return echoJson(array(
  79. 'code' => 0,
  80. 'redirect' => bx_append_url_params($aData['return_data_url'], array('o' => $sOrder, 'c' => $aData['custom']))
  81. ));
  82. }
  83. public function actionSubscribe()
  84. {
  85. $iBuyerId = bx_get_logged_profile_id();
  86. if(!$iBuyerId)
  87. return echoJson(array('code' => 1, 'msg' => _t('_bx_credits_err_unknown_buyer')));
  88. $aData = $this->_oConfig->getCheckoutData();
  89. if(empty($aData) || !is_array($aData))
  90. return echoJson(array('code' => 2, 'msg' => _t('_bx_credits_err_incorrect_data')));
  91. $iSellerId = (int)$aData['seller'];
  92. $fAmount = (float)$aData['amount'];
  93. $fBalance = (float)$this->_oDb->getProfile(array('type' => 'balance', 'id' => $iBuyerId));
  94. if($fAmount > $fBalance)
  95. return echoJson(array('code' => 3, 'msg' => _t('_bx_credits_err_low_balance')));
  96. $sUnique = $this->_oConfig->getOrder(9);
  97. $sCustomer = 'bx_cus_' . $sUnique;
  98. $sSubscription = 'bx_sub_' . $sUnique;
  99. bx_alert($this->getName(), 'subscribe', 0, false, array(
  100. 'seller' => $iSellerId,
  101. 'buyer' => $iBuyerId,
  102. 'amount' => $fAmount,
  103. 'trial' => $aData['trial'],
  104. 'customer' => $sCustomer,
  105. 'subscription' => $sSubscription
  106. ));
  107. return echoJson(array(
  108. 'code' => 0,
  109. 'redirect' => bx_append_url_params($aData['return_data_url'], array(
  110. 'cs' => $sCustomer,
  111. 'sb' => $sSubscription,
  112. 'tr' => $aData['trial'],
  113. 'c' => $aData['custom']
  114. ))
  115. ));
  116. }
  117. public function serviceGetSafeServices()
  118. {
  119. return array (
  120. 'GetBlockBundles' => '',
  121. 'GetBlockOrders' => '',
  122. 'GetBlockHistory' => '',
  123. );
  124. }
  125. public function serviceGetCheckoutUrl()
  126. {
  127. return $this->_oConfig->getCheckoutUrl();
  128. }
  129. public function serviceValidateCheckout($iSeller, $iBuyer, $fAmount, $sOrder)
  130. {
  131. $fAmount = (float)$fAmount;
  132. $aOut = $this->_oDb->getHistory(array('type' => 'row_by', 'by' => array('first_pid' => $iBuyer, 'direction' => BX_CREDITS_DIRECTION_OUT, 'order' => $sOrder)));
  133. if(empty($aOut) || !is_array($aOut) || (int)$aOut['second_pid'] != (int)$iSeller)
  134. return false;
  135. $aDataOut = unserialize($aOut['data']);
  136. if($this->_oConfig->convertM2C($fAmount, $aDataOut['conversion'], $aDataOut['precision']) != (float)$aOut['amount'])
  137. return false;
  138. $aIn = $this->_oDb->getHistory(array('type' => 'row_by', 'by' => array('first_pid' => $iSeller, 'direction' => BX_CREDITS_DIRECTION_IN, 'order' => $sOrder)));
  139. if(empty($aIn) || !is_array($aIn) || (int)$aIn['second_pid'] != (int)$iBuyer)
  140. return false;
  141. $aDataIn = unserialize($aIn['data']);
  142. if($this->_oConfig->convertM2C($fAmount, $aDataIn['conversion'], $aDataIn['precision']) != (float)$aIn['amount'])
  143. return false;
  144. return true;
  145. }
  146. public function serviceGetBlockCheckout()
  147. {
  148. $oBuyer = BxDolProfile::getInstance();
  149. if(!$oBuyer)
  150. return MsgBox(_t('_bx_credits_err_unknown_buyer'));
  151. $iSeller = (int)bx_get('seller');
  152. $oSeller = BxDolProfile::getInstance($iSeller);
  153. if(!$oSeller)
  154. return MsgBox(_t('_bx_credits_err_unknown_seller'));
  155. $fAmountM = (float)bx_get('amount');
  156. $fAmountC = $this->_oConfig->convertM2C($fAmountM);
  157. $aData = array(
  158. 'seller' => $iSeller,
  159. 'currency' => array(
  160. 'code' => bx_process_input(bx_get('currency_code')),
  161. 'sign' => bx_process_input(bx_get('currency_sign')),
  162. ),
  163. 'amountm' => $fAmountM,
  164. 'amountc' => $fAmountC
  165. );
  166. $iItemsCount = (int)bx_get('items_count');
  167. for($i = 0; $i < $iItemsCount; $i++) {
  168. $aData['items'][] = array(
  169. 'title' => bx_process_input(bx_get('item_title_' . $i)),
  170. 'quantity' => (int)bx_get('item_quantity_' . $i)
  171. );
  172. }
  173. $this->_oConfig->setCheckoutData(array(
  174. 'seller' => $iSeller,
  175. 'amount' => $fAmountC,
  176. 'custom' => bx_process_input(bx_get('custom')),
  177. 'return_data_url' => bx_process_input(bx_get('return_data_url')),
  178. ));
  179. return $this->_oTemplate->getBlockCheckout($oBuyer, $oSeller, $aData);
  180. }
  181. public function serviceGetPopupSubscribe($aData)
  182. {
  183. $oBuyer = BxDolProfile::getInstance();
  184. if(!$oBuyer)
  185. return array('msg' => _t('_bx_credits_err_unknown_buyer'));
  186. $iSeller = (int)$aData['seller'];
  187. $oSeller = BxDolProfile::getInstance($iSeller);
  188. if(!$oSeller)
  189. return array('msg' => _t('_bx_credits_err_unknown_seller'));
  190. $fAmountM = (float)$aData['amount'];
  191. $fAmountC = $this->_oConfig->convertM2C($fAmountM);
  192. $aData = array_merge($aData, array(
  193. 'amountm' => $fAmountM,
  194. 'amountc' => $fAmountC
  195. ));
  196. $this->_oConfig->setCheckoutData(array(
  197. 'seller' => $iSeller,
  198. 'amount' => $fAmountC,
  199. 'trial' => (int)$aData['trial'] > 0,
  200. 'custom' => bx_process_input($aData['custom']),
  201. 'return_data_url' => bx_process_input($aData['return_data_url']),
  202. ));
  203. return $this->_oTemplate->getPopupSubscribe($oBuyer, $oSeller, $aData);
  204. }
  205. public function serviceGetMenuItemAddonAmount()
  206. {
  207. $iProfileId = bx_get_logged_profile_id();
  208. if(!$iProfileId)
  209. return '';
  210. return array(
  211. 'unit' => $this->_oTemplate->getUnit(),
  212. 'value' => $this->convertC2S($this->_oDb->getProfile(array('type' => 'balance', 'id' => $iProfileId)), false)
  213. );
  214. }
  215. /**
  216. * @page service Service Calls
  217. * @section bx_credits Credits
  218. * @subsection bx_credits-page_blocks Page Blocks
  219. * @subsubsection bx_credits-get_block_bundles get_block_bundles
  220. *
  221. * @code bx_srv('bx_credits', 'get_block_bundles'); @endcode
  222. *
  223. * Get page block with bundles
  224. *
  225. * @see BxCreditsModule::serviceGetBlockBundles
  226. */
  227. /**
  228. * @ref bx_credits-get_block_bundles "get_block_bundles"
  229. */
  230. public function serviceGetBlockBundles()
  231. {
  232. return $this->_oTemplate->getBlockBundles();
  233. }
  234. /**
  235. * @page service Service Calls
  236. * @section bx_credits Credits
  237. * @subsection bx_credits-page_blocks Page Blocks
  238. * @subsubsection bx_credits-get_block_orders_note get_block_orders_note
  239. *
  240. * @code bx_srv('bx_credits', 'get_block_orders_note', [...]); @endcode
  241. *
  242. * Get page block with a notice for orders usage.
  243. *
  244. * @return HTML string with block content to display on the site.
  245. *
  246. * @see BxCreditsModule::serviceBlockLicensesNote
  247. */
  248. /**
  249. * @ref bx_credits-get_block_orders_note "get_block_orders_note"
  250. */
  251. public function serviceGetBlockOrdersNote()
  252. {
  253. return MsgBox(_t('_bx_credits_page_block_content_orders_common_note'));
  254. }
  255. /**
  256. * @page service Service Calls
  257. * @section bx_credits Credits
  258. * @subsection bx_credits-page_blocks Page Blocks
  259. * @subsubsection bx_credits-block_orders get_block_orders
  260. *
  261. * @code bx_srv('bx_credits', 'get_block_orders', [...]); @endcode
  262. *
  263. * Get page block with a list of orders purchased by currently logged member.
  264. *
  265. * @return an array describing a block to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  266. *
  267. * @see BxCreditsModule::serviceBlockLicenses
  268. */
  269. /**
  270. * @ref bx_credits-get_block_orders "get_block_orders"
  271. */
  272. public function serviceGetBlockOrders($sType = 'common')
  273. {
  274. return $this->_getBlockOrders($sType);
  275. }
  276. /**
  277. * @page service Service Calls
  278. * @section bx_credits Credits
  279. * @subsection bx_credits-page_blocks Page Blocks
  280. * @subsubsection bx_credits-get_block_history get_block_history
  281. *
  282. * @code bx_srv('bx_credits', 'get_block_history', [...]); @endcode
  283. *
  284. * Get page block with a list of all changes with credits.
  285. *
  286. * @return an array describing a block to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  287. *
  288. * @see BxCreditsModule::serviceGetBlockHistory
  289. */
  290. /**
  291. * @ref bx_credits-get_block_history "get_block_history"
  292. */
  293. public function serviceGetBlockHistory($sType = 'common')
  294. {
  295. return $this->_getBlockHistory($sType);
  296. }
  297. /**
  298. * @page service Service Calls
  299. * @section bx_credits Credits
  300. * @subsection bx_credits-payments Payments
  301. * @subsubsection bx_credits-get_payment_data get_payment_data
  302. *
  303. * @code bx_srv('bx_credits', 'get_payment_data', [...]); @endcode
  304. *
  305. * Get an array with module's description. Is needed for payments processing module.
  306. *
  307. * @return an array with module's description.
  308. *
  309. * @see BxCreditsModule::serviceGetPaymentData
  310. */
  311. /**
  312. * @ref bx_credits-get_payment_data "get_payment_data"
  313. */
  314. public function serviceGetPaymentData()
  315. {
  316. $CNF = &$this->_oConfig->CNF;
  317. $oPermalink = BxDolPermalinks::getInstance();
  318. $aResult = $this->_aModule;
  319. $aResult['url_browse_order_common'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_ORDERS_COMMON'], array('filter' => '{order}'));
  320. $aResult['url_browse_order_administration'] = BX_DOL_URL_ROOT . $oPermalink->permalink($CNF['URL_ORDERS_ADMINISTRATION'], array('filter' => '{order}'));
  321. return $aResult;
  322. }
  323. /**
  324. * @page service Service Calls
  325. * @section bx_credits Credits
  326. * @subsection bx_credits-payments Payments
  327. * @subsubsection bx_credits-get_cart_item get_cart_item
  328. *
  329. * @code bx_srv('bx_credits', 'get_cart_item', [...]); @endcode
  330. *
  331. * Get an array with prodict's description. Is used in Shopping Cart in payments processing module.
  332. *
  333. * @param $iItemId product's ID.
  334. * @return an array with prodict's description. Empty array is returned if something is wrong.
  335. *
  336. * @see BxCreditsModule::serviceGetCartItem
  337. */
  338. /**
  339. * @ref bx_credits-get_cart_item "get_cart_item"
  340. */
  341. public function serviceGetCartItem($iItemId)
  342. {
  343. $CNF = &$this->_oConfig->CNF;
  344. if(!$iItemId)
  345. return array();
  346. $aItem = $this->_oDb->getBundle(array('type' => 'id', 'id' => $iItemId));
  347. if(empty($aItem) || !is_array($aItem))
  348. return array();
  349. return array (
  350. 'id' => $aItem[$CNF['FIELD_ID']],
  351. 'author_id' => $this->_oConfig->getAuthor(),
  352. 'name' => $aItem[$CNF['FIELD_NAME']],
  353. 'title' => _t($aItem[$CNF['FIELD_TITLE']]),
  354. 'description' => $this->_oConfig->getBundleDescription($aItem),
  355. 'url' => $this->_oConfig->getBundleUrl($aItem),
  356. 'price_single' => $aItem[$CNF['FIELD_PRICE']],
  357. 'price_recurring' => '',
  358. 'period_recurring' => 1,
  359. 'period_unit_recurring' => '',
  360. 'trial_recurring' => ''
  361. );
  362. }
  363. /**
  364. * @page service Service Calls
  365. * @section bx_credits Credits
  366. * @subsection bx_credits-payments Payments
  367. * @subsubsection bx_credits-get_cart_items get_cart_items
  368. *
  369. * @code bx_srv('bx_credits', 'get_cart_items', [...]); @endcode
  370. *
  371. * Get an array with prodicts' descriptions by seller. Is used in Manual Order Processing in payments processing module.
  372. *
  373. * @param $iSellerId seller ID.
  374. * @return an array with prodicts' descriptions. Empty array is returned if something is wrong or seller doesn't have any products.
  375. *
  376. * @see BxCreditsModule::serviceGetCartItems
  377. */
  378. /**
  379. * @ref bx_credits-get_cart_items "get_cart_items"
  380. */
  381. public function serviceGetCartItems($iSellerId)
  382. {
  383. $CNF = &$this->_oConfig->CNF;
  384. $iAuthorId = $this->_oConfig->getAuthor();
  385. if($iSellerId != $iAuthorId && !BxDolAcl::getInstance()->isMemberLevelInSet([MEMBERSHIP_ID_ADMINISTRATOR], $iSellerId))
  386. return array();
  387. $aItems = $this->_oDb->getBundle(array('type' => 'all', 'active' => 1));
  388. $aResult = array();
  389. foreach($aItems as $aItem)
  390. $aResult[] = array(
  391. 'id' => $aItem[$CNF['FIELD_ID']],
  392. 'author_id' => $iAuthorId,
  393. 'name' => $aItem[$CNF['FIELD_NAME']],
  394. 'title' => _t($aItem[$CNF['FIELD_TITLE']]),
  395. 'description' => $this->_oConfig->getBundleDescription($aItem),
  396. 'url' => $this->_oConfig->getBundleUrl($aItem),
  397. 'price_single' => $aItem[$CNF['FIELD_PRICE']],
  398. 'price_recurring' => '',
  399. 'period_recurring' => 1,
  400. 'period_unit_recurring' => '',
  401. 'trial_recurring' => ''
  402. );
  403. return $aResult;
  404. }
  405. /**
  406. * @page service Service Calls
  407. * @section bx_credits Credits
  408. * @subsection bx_credits-payments Payments
  409. * @subsubsection bx_credits-register_cart_item register_cart_item
  410. *
  411. * @code bx_srv('bx_credits', 'register_cart_item', [...]); @endcode
  412. *
  413. * Register a processed single time payment inside the Credits module. Is called with payment processing module after the payment was registered there.
  414. *
  415. * @param $iClientId client ID.
  416. * @param $iSellerId seller ID
  417. * @param $iItemId item ID.
  418. * @param $iItemCount the number of purchased items.
  419. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  420. * @param $sLicense license number genereted with payment processing module for internal usage
  421. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  422. *
  423. * @see BxCreditsModule::serviceRegisterCartItem
  424. */
  425. /**
  426. * @ref bx_credits-register_cart_item "register_cart_item"
  427. */
  428. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  429. {
  430. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_CREDITS_ORDER_TYPE_SINGLE);
  431. }
  432. /**
  433. * @page service Service Calls
  434. * @section bx_credits Credits
  435. * @subsection bx_credits-payments Payments
  436. * @subsubsection bx_credits-register_subscription_item register_subscription_item
  437. *
  438. * @code bx_srv('bx_credits', 'register_subscription_item', [...]); @endcode
  439. *
  440. * Register a processed subscription (recurring payment) inside the Credits module. Is called with payment processing module after the subscription was registered there.
  441. *
  442. * @param $iClientId client ID.
  443. * @param $iSellerId seller ID
  444. * @param $iItemId item ID.
  445. * @param $iItemCount the number of purchased items.
  446. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  447. * @param $sLicense license number genereted with payment processing module for internal usage
  448. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  449. *
  450. * @see BxCreditsModule::serviceRegisterSubscriptionItem
  451. */
  452. /**
  453. * @ref bx_credits-register_subscription_item "register_subscription_item"
  454. */
  455. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  456. {
  457. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_CREDITS_ORDER_TYPE_RECURRING);
  458. }
  459. /**
  460. * @page service Service Calls
  461. * @section bx_credits Credits
  462. * @subsection bx_credits-payments Payments
  463. * @subsubsection bx_credits-reregister_cart_item reregister_cart_item
  464. *
  465. * @code bx_srv('bx_credits', 'reregister_cart_item', [...]); @endcode
  466. *
  467. * Reregister a single time payment inside the Credits module. Is called with payment processing module after the payment was reregistered there.
  468. *
  469. * @param $iClientId client ID.
  470. * @param $iSellerId seller ID
  471. * @param $iItemIdOld old item ID.
  472. * @param $iItemIdNew new item ID.
  473. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  474. * @return an array with purchased prodict's description. Empty array is returned if something is wrong.
  475. *
  476. * @see BxCreditsModule::serviceReregisterCartItem
  477. */
  478. /**
  479. * @ref bx_credits-reregister_cart_item "reregister_cart_item"
  480. */
  481. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  482. {
  483. return array();
  484. }
  485. /**
  486. * @page service Service Calls
  487. * @section bx_credits Credits
  488. * @subsection bx_credits-payments Payments
  489. * @subsubsection bx_credits-reregister_subscription_item reregister_subscription_item
  490. *
  491. * @code bx_srv('bx_credits', 'reregister_subscription_item', [...]); @endcode
  492. *
  493. * Reregister a subscription (recurring payment) inside the Credits module. Is called with payment processing module after the subscription was reregistered there.
  494. *
  495. * @param $iClientId client ID.
  496. * @param $iSellerId seller ID
  497. * @param $iItemIdOld old item ID.
  498. * @param $iItemIdNew new item ID.
  499. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  500. * @return an array with subscribed prodict's description. Empty array is returned if something is wrong.
  501. *
  502. * @see BxCreditsModule::serviceReregisterSubscriptionItem
  503. */
  504. /**
  505. * @ref bx_credits-reregister_subscription_item "reregister_subscription_item"
  506. */
  507. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  508. {
  509. return array();
  510. }
  511. /**
  512. * @page service Service Calls
  513. * @section bx_credits Credits
  514. * @subsection bx_credits-payments Payments
  515. * @subsubsection bx_credits-unregister_cart_item unregister_cart_item
  516. *
  517. * @code bx_srv('bx_credits', 'unregister_cart_item', [...]); @endcode
  518. *
  519. * Unregister an earlier processed single time payment inside the Credits module. Is called with payment processing module after the payment was unregistered there.
  520. *
  521. * @param $iClientId client ID.
  522. * @param $iSellerId seller ID
  523. * @param $iItemId item ID.
  524. * @param $iItemCount the number of purchased items.
  525. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  526. * @param $sLicense license number genereted with payment processing module for internal usage
  527. * @return boolean value determining where the payment was unregistered or not.
  528. *
  529. * @see BxCreditsModule::serviceUnregisterCartItem
  530. */
  531. /**
  532. * @ref bx_credits-unregister_cart_item "unregister_cart_item"
  533. */
  534. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  535. {
  536. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_CREDITS_ORDER_TYPE_SINGLE);
  537. }
  538. /**
  539. * @page service Service Calls
  540. * @section bx_credits Credits
  541. * @subsection bx_credits-payments Payments
  542. * @subsubsection bx_credits-unregister_subscription_item unregister_subscription_item
  543. *
  544. * @code bx_srv('bx_credits', 'unregister_subscription_item', [...]); @endcode
  545. *
  546. * Unregister an earlier processed subscription (recurring payment) inside the Credits module. Is called with payment processing module after the subscription was unregistered there.
  547. *
  548. * @param $iClientId client ID.
  549. * @param $iSellerId seller ID
  550. * @param $iItemId item ID.
  551. * @param $iItemCount the number of purchased items.
  552. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  553. * @param $sLicense license number genereted with payment processing module for internal usage
  554. * @return boolean value determining where the subscription was unregistered or not.
  555. *
  556. * @see BxCreditsModule::serviceUnregisterSubscriptionItem
  557. */
  558. /**
  559. * @ref bx_credits-unregister_subscription_item "unregister_subscription_item"
  560. */
  561. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  562. {
  563. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, BX_CREDITS_ORDER_TYPE_RECURRING);
  564. }
  565. /**
  566. * @page service Service Calls
  567. * @section bx_credits Credits
  568. * @subsection bx_credits-payments Payments
  569. * @subsubsection bx_credits-cancel_subscription_item cancel_subscription_item
  570. *
  571. * @code bx_srv('bx_credits', 'cancel_subscription_item', [...]); @endcode
  572. *
  573. * Cancel an earlier processed subscription (recurring payment) inside the Credits module. Is called with payment processing module after the subscription was canceled there.
  574. *
  575. * @param $iClientId client ID.
  576. * @param $iSellerId seller ID
  577. * @param $iItemId item ID.
  578. * @param $iItemCount the number of purchased items.
  579. * @param $sOrder order number received from payment provider (PayPal, Stripe, etc)
  580. * @return boolean value determining where the subscription was canceled or not.
  581. *
  582. * @see BxCreditsModule::serviceCancelSubscriptionItem
  583. */
  584. /**
  585. * @ref bx_credits-cancel_subscription_item "cancel_subscription_item"
  586. */
  587. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  588. {
  589. return true;
  590. }
  591. public function serviceGetProfileBalance($iProfileId = 0)
  592. {
  593. return $this->getProfileBalance($iProfileId);
  594. }
  595. public function serviceUpdateProfileBalance($iFirstPid, $fAmount, $iSecondPid = 0, $sOrder = '', $sInfo = '')
  596. {
  597. if(empty($sInfo))
  598. $sInfo = '_bx_credits_txt_history_info_service';
  599. return $this->updateProfileBalance($iFirstPid, $iSecondPid, $fAmount, BX_CREDITS_TRANSFER_TYPE_SERVICE, $sOrder, $sInfo);
  600. }
  601. public function serviceMakePayment($iBuyerPid, $fAmount, $iSellerPid, $sOrder = '')
  602. {
  603. $sInfo = '_bx_credits_txt_history_info_checkout';
  604. if(!$this->updateProfileBalance($iBuyerPid, $iSellerPid, -$fAmount, BX_CREDITS_TRANSFER_TYPE_CHECKOUT, $sOrder, $sInfo))
  605. return false;
  606. if(!$this->updateProfileBalance($iSellerPid, $iBuyerPid, $fAmount, $sOrder, BX_CREDITS_TRANSFER_TYPE_CHECKOUT, $sInfo)) {
  607. $this->updateProfileBalance($iBuyerPid, 0, $fAmount, BX_CREDITS_TRANSFER_TYPE_CANCELLATION, $sOrder, '_bx_credits_txt_history_info_cancellation');
  608. return false;
  609. }
  610. return true;
  611. }
  612. /**
  613. * Delete all content by profile
  614. * @param $iProfileId profile id
  615. * @return number of deleted items
  616. */
  617. public function serviceDeleteEntitiesByAuthor ($iProfileId)
  618. {
  619. $this->_oDb->deleteProfile(array('id' => $iProfileId));
  620. $this->_oDb->deleteHistory(array('first_pid' => $iProfileId));
  621. }
  622. /*
  623. * Common methods
  624. */
  625. public function convertC2S($fCredits, $bWithUnit = true)
  626. {
  627. $sResult = '';
  628. if($bWithUnit)
  629. $sResult .= $this->_oTemplate->getUnit();
  630. $iPrecision = $this->_oConfig->getPrecision();
  631. $sResult .= sprintf("%01." . $iPrecision . "f", round((float)$fCredits, $iPrecision));
  632. return $sResult;
  633. }
  634. public function getProfileBalance($iProfileId = 0)
  635. {
  636. if(empty($iProfileId))
  637. $iProfileId = bx_get_logged_profile_id();
  638. if(empty($iProfileId))
  639. return 0;
  640. return (float)$this->_oDb->getProfile(array('type' => 'balance', 'id' => $iProfileId));
  641. }
  642. public function getProfileBalanceCleared($iProfileId = 0)
  643. {
  644. if(empty($iProfileId))
  645. $iProfileId = bx_get_logged_profile_id();
  646. if(empty($iProfileId))
  647. return 0;
  648. $fCleared = (float)$this->_oDb->getHistory(['type' => 'cleared', 'profile' => $iProfileId]);
  649. $fSpent = (float)$this->_oDb->getHistory(['type' => 'spent', 'profile' => $iProfileId]);
  650. return $fCleared > $fSpent ? $fCleared - $fSpent : 0;
  651. }
  652. public function updateProfileBalance($iFirstPid, $iSecondPid, $fAmount, $sType, $sOrder = '', $sInfo = '', $sData = '')
  653. {
  654. $CNF = &$this->_oConfig->CNF;
  655. if(empty($sOrder))
  656. $sOrder = $this->_oConfig->getOrder();
  657. if(empty($sData))
  658. $sData = serialize(array(
  659. 'conversion' => $this->_oConfig->getConversionRateUse(),
  660. 'precision' => $this->_oConfig->getPrecision()
  661. ));
  662. if(!$this->_oDb->updateProfileBalance($iFirstPid, $fAmount))
  663. return false;
  664. $fAmountAbs = abs($fAmount);
  665. $sDirection = $fAmount > 0 ? BX_CREDITS_DIRECTION_IN : BX_CREDITS_DIRECTION_OUT;
  666. $iHistoryId = $this->_oDb->insertHistory([
  667. 'first_pid' => $iFirstPid,
  668. 'second_pid' => $iSecondPid,
  669. 'amount' => $fAmountAbs,
  670. 'type' => $sType,
  671. 'direction' => $sDirection,
  672. 'order' => $sOrder,
  673. 'data' => $sData,
  674. 'info' => $sInfo,
  675. 'date' => time()
  676. ]);
  677. if(!$iHistoryId)
  678. return false;
  679. bx_alert($this->getName(), 'update_balance', 0, false, array(
  680. 'first_pid' => $iFirstPid,
  681. 'second_pid' => $iSecondPid,
  682. 'amount' => $fAmountAbs,
  683. 'type' => $sType,
  684. 'direction' => $sDirection,
  685. 'order' => $sOrder,
  686. ));
  687. $oSecondProfile = BxDolProfile::getInstanceMagic($iSecondPid);
  688. sendMailTemplate($CNF['ETEMPLATE_' . strtoupper($sDirection)], 0, $iFirstPid, array(
  689. 'second_profile_name' => $oSecondProfile->getDisplayName(),
  690. 'amount' => $fAmountAbs,
  691. ));
  692. return $iHistoryId;
  693. }
  694. public function processGrant($iUserId, $iProfileId, $fAmount, $sMessage = '')
  695. {
  696. $CNF = &$this->_oConfig->CNF;
  697. $oProfile = BxDolProfile::getInstance($iProfileId);
  698. if(!$oProfile)
  699. return ['code' => 2, 'msg' => '_bx_credits_err_profile_not_found'];
  700. $sInfo = '_bx_credits_txt_history_info_grant';
  701. $iHistoryId = $this->updateProfileBalance($iProfileId, 0, $fAmount, BX_CREDITS_TRANSFER_TYPE_GRANT, '', $sInfo);
  702. if(!$iHistoryId)
  703. return ['code' => 3, 'msg' => '_bx_credits_err_cannot_update_balance'];
  704. sendMailTemplate($CNF['ETEMPLATE_GRANTED'], 0, $iProfileId, [
  705. 'amount' => $fAmount,
  706. 'message' => $sMessage
  707. ]);
  708. bx_alert($this->getName(), 'granted', 0, false, [
  709. 'profile' => $iProfileId,
  710. 'amount' => $fAmount,
  711. ]);
  712. return ['code' => 0, 'id' => $iHistoryId];
  713. }
  714. public function processSend($iUserId, $iProfileId, $fAmount, $sMessage = '')
  715. {
  716. $CNF = &$this->_oConfig->CNF;
  717. $fAmountAvail = $this->getProfileBalance($iUserId);
  718. if($fAmount > $fAmountAvail)
  719. return ['code' => 1, 'msg' => '_bx_credits_err_low_balance'];
  720. $oProfile = BxDolProfile::getInstance($iProfileId);
  721. if(!$oProfile)
  722. return ['code' => 2, 'msg' => '_bx_credits_err_profile_not_found'];
  723. $sOrder = $this->_oConfig->getOrder();
  724. $sInfo = !empty($sMessage) ? $sMessage : '_bx_credits_txt_history_info_send';
  725. $iHistoryId = $this->updateProfileBalance($iUserId, $iProfileId, -$fAmount, BX_CREDITS_TRANSFER_TYPE_SEND, $sOrder, $sInfo);
  726. if(!$iHistoryId)
  727. return ['code' => 3, 'msg' => '_bx_credits_err_cannot_update_balance'];
  728. if(!$this->updateProfileBalance($iProfileId, $iUserId, $fAmount, BX_CREDITS_TRANSFER_TYPE_SEND, $sOrder, $sInfo)) {
  729. $sInfo = '_bx_credits_txt_history_info_cancellation';
  730. $iHistoryId = $this->updateProfileBalance($iUserId, 0, $fAmount, BX_CREDITS_TRANSFER_TYPE_CANCELLATION, $sOrder, $sInfo);
  731. return ['code' => 3, 'id' => $iHistoryId, 'msg' => '_bx_credits_err_cannot_update_balance'];
  732. }
  733. $oUser = BxDolProfile::getInstance($iUserId);
  734. sendMailTemplate($CNF['ETEMPLATE_RECEIVED'], 0, $iProfileId, [
  735. 'performer_id' => $iUserId,
  736. 'performer_name' => $oUser->getDisplayName(),
  737. 'performer_link' => $oUser->getUrl(),
  738. 'amount' => $fAmount,
  739. 'order' => $sOrder,
  740. 'message' => $sMessage
  741. ]);
  742. bx_alert($this->getName(), 'sent', 0, $iUserId, [
  743. 'performer' => $iUserId,
  744. 'profile' => $iProfileId,
  745. 'amount' => $fAmount,
  746. 'order' => $sOrder,
  747. ]);
  748. return ['code' => 0, 'id' => $iHistoryId];
  749. }
  750. public function processWithdrawRequest($iUserId, $iProfileId, $fAmount, $sMessage = '')
  751. {
  752. $CNF = &$this->_oConfig->CNF;
  753. if(empty($iProfileId))
  754. $iProfileId = bx_get_logged_profile_id ();
  755. if(empty($iProfileId))
  756. return ['code' => 1, 'msg' => '_bx_credits_err_login_required'];
  757. $oProfile = BxDolProfile::getInstance($iProfileId);
  758. if(!$oProfile)
  759. return ['code' => 1, 'msg' => '_bx_credits_err_login_required'];
  760. $fBalanceCleared = $this->getProfileBalanceCleared($iProfileId);
  761. if($fAmount > $fBalanceCleared)
  762. return ['code' => 2, 'msg' => '_bx_credits_err_low_balance'];
  763. if($fAmount < ($iWithdrawMinimum = (int)getParam($CNF['PARAM_WITHDRAW_MINIMUM'])))
  764. return ['code' => 3, 'msg' => _t('_bx_credits_err_withdraw_minimum', $iWithdrawMinimum)];
  765. $fBalance = $this->getProfileBalance($iProfileId);
  766. if(($fBalance - $fAmount) < ($iWithdrawRemaining = (int)getParam($CNF['PARAM_WITHDRAW_REMAINING'])))
  767. return ['code' => 4, 'msg' => _t('_bx_credits_err_withdraw_remaining', $iWithdrawRemaining)];
  768. $aResult = ['code' => 5, 'msg' => '_bx_credits_err_cannot_send'];
  769. $fRate = $this->_oConfig->getConversionRateWithdraw();
  770. $aTemplateVars = [
  771. 'profile_link' => $oProfile->getUrl(),
  772. 'profile_name' => $oProfile->getDisplayName(),
  773. 'amount' => $fAmount,
  774. 'rate' => $fRate,
  775. 'message' => $sMessage,
  776. 'confirm_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_HISTORY_ADMINISTRATION'])
  777. ];
  778. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($CNF['ETEMPLATE_WITHDRAW_REQUESTED'], $aTemplateVars);
  779. if(!$aTemplate)
  780. return $aResult;
  781. $sEmail = $this->_oConfig->getWithdrawEmail();
  782. if(!sendMail($sEmail, $aTemplate['Subject'], $aTemplate['Body'], 0, [], BX_EMAIL_SYSTEM, 'html', false, [], true))
  783. return $aResult;
  784. bx_alert($this->getName(), 'withdraw_requested', 0, $iProfileId, [
  785. 'profile' => $iProfileId,
  786. 'amount' => $fAmount,
  787. 'rate' => $fRate
  788. ]);
  789. return ['code' => 0];
  790. }
  791. public function processWithdrawConfirm($iUserId, $iProfileId, $fAmount, $sMessage = '')
  792. {
  793. $CNF = &$this->_oConfig->CNF;
  794. $oProfile = BxDolProfile::getInstance($iProfileId);
  795. if(!$oProfile)
  796. return ['code' => 1, 'msg' => '_bx_credits_err_profile_not_found'];
  797. $fBalance = $this->getProfileBalance($iProfileId);
  798. if($fAmount > $fBalance)
  799. return ['code' => 2, 'msg' => '_bx_credits_err_low_balance'];
  800. $sInfo = '_bx_credits_txt_history_info_withdraw';
  801. $iHistoryId = $this->updateProfileBalance($iProfileId, 0, -$fAmount, BX_CREDITS_TRANSFER_TYPE_WITHDRAW, '', $sInfo);
  802. if(!$iHistoryId)
  803. return ['code' => 3, 'msg' => '_bx_credits_err_cannot_update_balance'];
  804. sendMailTemplate($CNF['ETEMPLATE_WITHDRAW_SENT'], 0, $iProfileId, [
  805. 'amount' => $fAmount,
  806. 'message' => $sMessage
  807. ]);
  808. bx_alert($this->getName(), 'withdraw_sent', 0, $iUserId, [
  809. 'performer' => $iUserId,
  810. 'profile' => $iProfileId,
  811. 'amount' => $fAmount,
  812. ]);
  813. return ['code' => 0, 'id' => $iHistoryId];
  814. }
  815. public function processClearing()
  816. {
  817. $CNF = &$this->_oConfig->CNF;
  818. $aItems = $this->_oDb->getHistory(['type' => 'clearing', 'clearing' => $this->_oConfig->getWithdrawClearing()]);
  819. if(empty($aItems) || !is_array($aItems))
  820. return;
  821. $iNow = time();
  822. foreach($aItems as $aItem) {
  823. $this->_oDb->updateHistory([$CNF['FIELD_H_CLEARED'] => $iNow], [$CNF['FIELD_H_ID'] => $aItem['id']]);
  824. //TODO: Some action(s) related to clearing can be performed here.
  825. }
  826. }
  827. /*
  828. * Internal methods
  829. */
  830. protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType)
  831. {
  832. $CNF = &$this->_oConfig->CNF;
  833. $aItem = $this->serviceGetCartItem($iItemId);
  834. if(empty($aItem) || !is_array($aItem))
  835. return array();
  836. $aBundle = $this->_oDb->getBundle(array('type' => 'id', 'id' => $iItemId));
  837. if(empty($aBundle) || !is_array($aBundle))
  838. return array();
  839. $iTrial = 0;
  840. $sDuration = '';
  841. $sAction = 'register';
  842. if($sType == BX_CREDITS_ORDER_TYPE_RECURRING && isset($CNF['FIELD_DURATION_RECURRING'], $CNF['FIELD_TRIAL_RECURRING'])) {
  843. $iTrial = $aBundle[$CNF['FIELD_TRIAL_RECURRING']];
  844. $sDuration = $aBundle[$CNF['FIELD_DURATION_RECURRING']];
  845. if($this->_oDb->isOrderByPbo($iClientId, $iItemId, $sOrder))
  846. $sAction = 'prolong';
  847. }
  848. if(!$this->_oDb->{$sAction . 'Order'}($iClientId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType, $sDuration, $iTrial))
  849. return array();
  850. $sInfo = '_bx_credits_txt_history_info_purchase';
  851. $fAmount = ((float)$aBundle[$CNF['FIELD_AMOUNT']] + (float)$aBundle[$CNF['FIELD_BONUS']]) * $iItemCount;
  852. if(!$this->updateProfileBalance($iClientId, 0, $fAmount, BX_CREDITS_TRANSFER_TYPE_PURCHASE, '', $sInfo))
  853. return array();
  854. bx_alert($this->getName(), 'order_' . $sAction, 0, false, array(
  855. 'profile_id' => $iClientId,
  856. 'bundle_id' => $iItemId,
  857. 'product_id' => $iItemId, //--- Alias for 'bundle_id'
  858. 'count' => $iItemCount,
  859. 'order' => $sOrder,
  860. 'license' => $sLicense,
  861. 'type' => $sType,
  862. 'duration' => $sDuration,
  863. 'trial' => $iTrial
  864. ));
  865. $oClient = BxDolProfile::getInstanceMagic($iClientId);
  866. $oSeller = BxDolProfile::getInstanceMagic($iSellerId);
  867. $sSellerUrl = $oSeller->getUrl();
  868. $sSellerName = $oSeller->getDisplayName();
  869. sendMailTemplate($CNF['ETEMPLATE_PURCHASED'], 0, $iClientId, array(
  870. 'client_name' => $oClient->getDisplayName(),
  871. 'bundle_name' => $aBundle[$CNF['FIELD_NAME']],
  872. 'bundle_title' => _t($aBundle[$CNF['FIELD_TITLE']]),
  873. 'bundle_url' => $this->_oConfig->getBundleUrl($aBundle),
  874. 'vendor_url' => $sSellerUrl,
  875. 'vendor_name' => $sSellerName,
  876. 'order' => $sOrder,
  877. 'license' => $sLicense,
  878. 'notes' => _t('_bx_credits_txt_purchased_note', $sSellerUrl, $sSellerName),
  879. ));
  880. return $aItem;
  881. }
  882. protected function _serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense, $sType)
  883. {
  884. $CNF = &$this->_oConfig->CNF;
  885. $aBundle = $this->_oDb->getBundle(array('type' => 'id', 'id' => $iItemId));
  886. if(empty($aBundle) || !is_array($aBundle))
  887. return false;
  888. if(!$this->_oDb->unregisterOrder($iClientId, $iItemId, $sOrder, $sLicense, $sType))
  889. return false;
  890. $fAmount = (float)$aBundle[$CNF['FIELD_AMOUNT']] + (float)$aBundle[$CNF['FIELD_BONUS']];
  891. $aProfile = $this->_oDb->getProfile(array('type' => 'id', 'id' => $iClientId));
  892. if(!empty($aProfile) && is_array($aProfile))
  893. $this->_oDb->updateProfile(array('balance' => (float)$aProfile['balance'] - $fAmount), array('id' => $aProfile['id']));
  894. bx_alert($this->getName(), 'order_unregister', 0, false, array(
  895. 'profile_id' => $iClientId,
  896. 'bundle_id' => $iItemId,
  897. 'product_id' => $iItemId, //--- Alias for 'bundle_id'
  898. 'count' => $iItemCount,
  899. 'order' => $sOrder,
  900. 'license' => $sLicense,
  901. 'type' => $sType,
  902. ));
  903. return true;
  904. }
  905. protected function _getBlockOrders($sType)
  906. {
  907. $CNF = &$this->_oConfig->CNF;
  908. $sGrid = $CNF['OBJECT_GRID_ORDERS_' . strtoupper($sType)];
  909. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  910. if(!$oGrid)
  911. return '';
  912. return array(
  913. 'content' => $oGrid->getCode(),
  914. 'menu' => $CNF['OBJECT_MENU_MANAGE_SUBMENU']
  915. );
  916. }
  917. protected function _getBlockHistory($sType)
  918. {
  919. $CNF = &$this->_oConfig->CNF;
  920. $sGrid = $CNF['OBJECT_GRID_HISTORY_' . strtoupper($sType)];
  921. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  922. if(!$oGrid)
  923. return '';
  924. return array(
  925. 'content' => $oGrid->getCode(),
  926. 'menu' => $CNF['OBJECT_MENU_MANAGE_SUBMENU']
  927. );
  928. }
  929. }
  930. /** @} */