BxPaymentModule.php 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  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. define('BX_PAYMENT_ORDERS_TYPE_PENDING', 'pending');
  12. define('BX_PAYMENT_ORDERS_TYPE_PROCESSED', 'processed');
  13. define('BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION', 'subscription');
  14. define('BX_PAYMENT_ORDERS_TYPE_HISTORY', 'history');
  15. define('BX_PAYMENT_RESULT_SUCCESS', 0);
  16. define('BX_PAYMENT_SBS_STATUS_SCHEDULED', 'scheduled');
  17. define('BX_PAYMENT_SBS_STATUS_TRIAL', 'trial');
  18. define('BX_PAYMENT_SBS_STATUS_ACTIVE', 'active');
  19. define('BX_PAYMENT_SBS_STATUS_UNPAID', 'unpaid');
  20. define('BX_PAYMENT_SBS_STATUS_PAUSED', 'paused');
  21. define('BX_PAYMENT_SBS_STATUS_CANCELED', 'canceled');
  22. define('BX_PAYMENT_SBS_STATUS_UNKNOWN', 'unknown');
  23. /**
  24. * Payment module by BoonEx
  25. *
  26. * This module is needed to work with payment providers and organize the process
  27. * of some item purchasing. Shopping Cart and Orders Manager are included.
  28. *
  29. * Integration notes:
  30. * To integrate your module with this one, you need:
  31. * 1. Get 'Add To Cart' button using serviceGetAddToCartLink service.
  32. * 2. Add info about your module in the 'bx_pmt_modules' table.
  33. * 3. Realize the following service methods in your Module class.
  34. * a. serviceGetItems($iSellerId) - Is used in Orders Administration to get all products of the requested seller(vendor).
  35. * b. serviceGetCartItem($iClientId, $iItemId) - Is used in Shopping Cart to get one product by specified id.
  36. * c. serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrderId) - Register purchased product.
  37. * d. serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrderId) - Unregister the product purchased earlier.
  38. * @see You may see an example of integration in Membership module.
  39. *
  40. *
  41. * Profile's Wall:
  42. * no spy events
  43. *
  44. *
  45. *
  46. * Spy:
  47. * no spy events
  48. *
  49. *
  50. *
  51. * Memberships/ACL:
  52. * Doesn't depend on user's membership.
  53. *
  54. *
  55. *
  56. * Service methods:
  57. *
  58. * Is used to get "Add to cart" link for some item(s) in your module.
  59. * @see BxPmtModule::serviceGetAddToCartLink
  60. * BxDolService::call('payment', 'get_add_to_cart_link', array($iSellerId, $mixedModuleId, $iItemId, $iItemCount));
  61. *
  62. * Check transaction(s) in database which satisty all conditions.
  63. * @see BxPmtModule::serviceGetOrdersInfo
  64. * BxDolService::call('payment', 'get_orders_info', array($aConditions), 'Orders');
  65. *
  66. * Get total count of items in Shopping Cart.
  67. * @see BxPmtModule::serviceGetCartItemsCount
  68. * BxDolService::call('payment', 'get_cart_items_count', array($iUserId, $iOldCount));
  69. * @note is needed for internal usage(integration with member tool bar).
  70. *
  71. * Get Shopping cart content.
  72. * @see BxPmtModule::serviceGetCartItems
  73. * BxDolService::call('payment', 'get_cart_items');
  74. * @note is needed for internal usage(integration with member tool bar).
  75. *
  76. *
  77. * Alerts:
  78. * no alerts available
  79. *
  80. */
  81. class BxPaymentModule extends BxBaseModPaymentModule
  82. {
  83. protected $_iUserId;
  84. protected $_aOrderTypes;
  85. function __construct($aModule)
  86. {
  87. parent::__construct($aModule);
  88. $this->_iUserId = $this->getProfileId();
  89. $this->_aOrderTypes = array(
  90. BX_PAYMENT_ORDERS_TYPE_PENDING,
  91. BX_PAYMENT_ORDERS_TYPE_PROCESSED,
  92. BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION,
  93. BX_PAYMENT_ORDERS_TYPE_HISTORY
  94. );
  95. }
  96. /**
  97. * Manage Orders Methods
  98. */
  99. public function actionGetClients()
  100. {
  101. $sTerm = bx_get('term');
  102. $aResult = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  103. echoJson($aResult);
  104. }
  105. public function actionGetItems($sType, $iModuleId)
  106. {
  107. $iSellerId = $this->getProfileId();
  108. $aItems = $this->callGetCartItems((int)$iModuleId, array($iSellerId));
  109. echoJson(array(
  110. 'code' => 0,
  111. 'eval' => $this->_oConfig->getJsObject('processed') . '.onSelectModule(oData);',
  112. 'data' => $this->_oTemplate->displayItems($sType, $aItems)
  113. ));
  114. }
  115. public function actionGetFilterValuesItem($iSellerId, $iModuleId)
  116. {
  117. $sItems = '<option value="">' . _t('_bx_payment_txt_all_items') . '</option>';
  118. if(empty($iSellerId) || empty($iModuleId))
  119. return echoJson(array('code' => 1, 'content' => $sItems));
  120. $aItems = $this->callGetCartItems((int)$iModuleId, array($iSellerId));
  121. $this->_oConfig->sortByColumn('title', $aItems);
  122. foreach($aItems as $aItem)
  123. $sItems .= '<option value="' . $aItem['id'] . '">' . $aItem['title'] . '</option>';
  124. echoJson(array('code' => 0, 'content' => $sItems));
  125. }
  126. public function serviceGetSafeServices()
  127. {
  128. $a = parent::serviceGetSafeServices();
  129. return array_merge($a, array (
  130. 'GetBlockJoin' => 'BxPaymentJoin',
  131. 'GetBlockCarts' => 'BxPaymentCart',
  132. 'GetBlockCart' => 'BxPaymentCart',
  133. 'GetBlockCartHistory' => 'BxPaymentCart',
  134. 'GetBlockListMy' => 'BxPaymentSubscriptions',
  135. 'GetBlockHistory' => 'BxPaymentSubscriptions',
  136. ));
  137. }
  138. /**
  139. * @page service Service Calls
  140. * @section bx_payment Payment
  141. * @subsection bx_payment-purchase_processing Purchase Processing
  142. * @subsubsection bx_payment-is_accepting_payments is_accepting_payments
  143. *
  144. * @code bx_srv('bx_payment', 'is_accepting_payments', [...]); @endcode
  145. *
  146. * Check whether the specified vendor has a configured payment provider or not.
  147. *
  148. * @param $iVendorId integer value with vendor ID.
  149. * @param $sPaymentType (optional) string value with payment type. If specified then the vendor will be checked for having the payment provider of the requested type.
  150. * @return boolean value determining the result of checking.
  151. *
  152. * @see BxPaymentModule::serviceIsAcceptingPayments
  153. */
  154. /**
  155. * @ref bx_payment-is_accepting_payments "is_accepting_payments"
  156. */
  157. public function serviceIsAcceptingPayments($iVendorId, $sPaymentType = '')
  158. {
  159. $bResult = false;
  160. switch($sPaymentType) {
  161. case BX_PAYMENT_TYPE_SINGLE:
  162. $aProvidersCart = $this->_oDb->getVendorInfoProvidersSingle($iVendorId);
  163. $bResult = !empty($aProvidersCart);
  164. break;
  165. case BX_PAYMENT_TYPE_RECURRING:
  166. $aProvidersSubscription = $this->_oDb->getVendorInfoProvidersRecurring($iVendorId);
  167. $bResult = !empty($aProvidersSubscription);
  168. break;
  169. default:
  170. $aProviders = $this->_oDb->getVendorInfoProviders($iVendorId);
  171. $bResult = !empty($aProviders);
  172. }
  173. return $bResult;
  174. }
  175. /**
  176. * @deprecated since version 11.0.0
  177. *
  178. * @see BxPaymentModule::serviceIsProviderOptions
  179. */
  180. public function serviceIsPaymentProvider($iVendorId, $sVendorProvider, $sPaymentType = '')
  181. {
  182. return $this->serviceIsProviderOptions($iVendorId, $sVendorProvider, $sPaymentType);
  183. }
  184. /**
  185. * @deprecated since version 11.0.0
  186. *
  187. * @see BxPaymentModule::serviceGetProviderOptions
  188. */
  189. public function serviceGetPaymentProvider($iVendorId, $sVendorProvider, $sPaymentType = '')
  190. {
  191. return $this->serviceGetProviderOptions($iVendorId, $sVendorProvider, $sPaymentType);
  192. }
  193. /**
  194. * @page service Service Calls
  195. * @section bx_payment Payment
  196. * @subsection bx_payment-purchase_processing Purchase Processing
  197. * @subsubsection bx_payment-is_provider_options is_provider_options
  198. *
  199. * @code bx_srv('bx_payment', 'is_provider_options', [...]); @endcode
  200. *
  201. * Check whether the specified vendor has configured the specified payment provider or not.
  202. *
  203. * @param $iVendorId integer value with vendor ID.
  204. * @param $sVendorProvider string value with payment provider name.
  205. * @param $sPaymentType (optional) string value with payment type. If specified then the vendor will be checked for having the payment provider of the requested type.
  206. * @return boolean value determining the result of checking.
  207. *
  208. * @see BxPaymentModule::serviceIsProviderOptions
  209. */
  210. /**
  211. * @ref bx_payment-is_provider_options "is_provider_options"
  212. */
  213. public function serviceIsProviderOptions($iVendorId, $sVendorProvider, $sPaymentType = '')
  214. {
  215. $aProvider = $this->serviceGetProviderOptions($iVendorId, $sVendorProvider, $sPaymentType);
  216. return $aProvider !== false;
  217. }
  218. /**
  219. * @page service Service Calls
  220. * @section bx_payment Payment
  221. * @subsection bx_payment-purchase_processing Purchase Processing
  222. * @subsubsection bx_payment-get_provider_options get_provider_options
  223. *
  224. * @code bx_srv('bx_payment', 'get_provider_options', [...]); @endcode
  225. *
  226. * Get configuration settings for the payment provider entered by the specified vendor.
  227. *
  228. * @param $iVendorId integer value with vendor ID.
  229. * @param $sVendorProvider string value with payment provider name.
  230. * @param $sPaymentType (optional) string value with payment type. If specified then the vendor will be checked for having the payment provider of the requested type.
  231. * @return an array with special format describing the payment provider or false value if something is wrong.
  232. *
  233. * @see BxPaymentModule::serviceGetProviderOptions
  234. */
  235. /**
  236. * @ref bx_payment-get_provider_options "get_provider_options"
  237. */
  238. public function serviceGetProviderOptions($iVendorId, $sVendorProvider, $sPaymentType = '')
  239. {
  240. $aProviders = array();
  241. switch($sPaymentType) {
  242. case BX_PAYMENT_TYPE_SINGLE:
  243. $aProviders = $this->_oDb->getVendorInfoProvidersSingle($iVendorId);
  244. break;
  245. case BX_PAYMENT_TYPE_RECURRING:
  246. $aProviders = $this->_oDb->getVendorInfoProvidersRecurring($iVendorId);
  247. break;
  248. default:
  249. $aProviders = $this->_oDb->getVendorInfoProviders($iVendorId);
  250. }
  251. return !empty($aProviders) && !empty($aProviders[$sVendorProvider]) && is_array(($aProviders[$sVendorProvider])) ? $aProviders[$sVendorProvider] : false;
  252. }
  253. /**
  254. * @page service Service Calls
  255. * @section bx_payment Payment
  256. * @subsection bx_payment-other Other
  257. * @subsubsection bx_payment-get_options_default_currency_code get_options_default_currency_code
  258. *
  259. * @code bx_srv('bx_payment', 'get_options_default_currency_code', [...]); @endcode
  260. *
  261. * Get an array with available currencies. Is used in forms.
  262. *
  263. * @return an array with available currencies represented as key => value pairs.
  264. *
  265. * @see BxPaymentModule::serviceGetOptionsDefaultCurrencyCode
  266. */
  267. /**
  268. * @ref bx_payment-get_options_default_currency_code "get_options_default_currency_code"
  269. */
  270. public function serviceGetOptionsDefaultCurrencyCode()
  271. {
  272. $CNF = &$this->_oConfig->CNF;
  273. $aCurrencies = BxDolForm::getDataItems($CNF['OBJECT_FORM_PRELISTS_CURRENCIES']);
  274. $aResult = array();
  275. foreach($aCurrencies as $sKey => $sValue)
  276. $aResult[] = array(
  277. 'key' => $sKey,
  278. 'value' => $sValue
  279. );
  280. return $aResult;
  281. }
  282. /**
  283. * @page service Service Calls
  284. * @section bx_payment Payment
  285. * @subsection bx_payment-other Other
  286. * @subsubsection bx_payment-get_options_site_admin get_options_site_admin
  287. *
  288. * @code bx_srv('bx_payment', 'get_options_site_admin', [...]); @endcode
  289. *
  290. * Get an array with profiles which can be used as 'Site Admin (Owner)'. 'Site Admin' is a person who will be displayed to buyers when something is selling on behalf of the site.
  291. *
  292. * @return an array with profiles represented as key => value pairs.
  293. *
  294. * @see BxPaymentModule::serviceGetOptionsSiteAdmin
  295. */
  296. /**
  297. * @ref bx_payment-get_options_site_admin "get_options_site_admin"
  298. */
  299. public function serviceGetOptionsSiteAdmin()
  300. {
  301. $aResult = array(
  302. array('key' => '', 'value' => _t('_Select_one'))
  303. );
  304. $aIds = $this->_oDb->getAdminsIds();
  305. foreach($aIds as $iId) {
  306. $aUser = $this->getProfileInfo($iId);
  307. $aResult[] = array(
  308. 'key' => $iId,
  309. 'value' => $aUser['name']
  310. );
  311. }
  312. return $aResult;
  313. }
  314. /**
  315. * Cart Processing Methods
  316. */
  317. public function actionAddToCart($iSellerId, $iModuleId, $iItemId, $iItemCount, $sCustom = '')
  318. {
  319. if(empty($sCustom) && bx_get('custom') !== false)
  320. $sCustom = bx_process_input(bx_get('custom'));
  321. $aCustom = array();
  322. if(!empty($sCustom)) {
  323. $aCustom = unserialize(base64_decode($sCustom));
  324. if(empty($aCustom) || !is_array($aCustom))
  325. $aCustom = array();
  326. }
  327. $aResult = $this->getObjectCart()->serviceAddToCart($iSellerId, $iModuleId, $iItemId, $iItemCount, $aCustom);
  328. echoJson($aResult);
  329. }
  330. /**
  331. * Isn't used yet.
  332. */
  333. public function actionDeleteFromCart($iSellerId, $iModuleId, $iItemId)
  334. {
  335. $aResult = $this->getObjectCart()->serviceDeleteFromCart($iSellerId, $iModuleId, $iItemId);
  336. echoJson($aResult);
  337. }
  338. /**
  339. * Isn't used yet.
  340. */
  341. public function actionEmptyCart($iSellerId)
  342. {
  343. $aResult = $this->getObjectCart()->serviceDeleteFromCart($iSellerId);
  344. echoJson($aResult);
  345. }
  346. public function actionSubscribe()
  347. {
  348. $iSellerId = bx_process_input(bx_get('seller_id'), BX_DATA_INT);
  349. $sSellerProvider = bx_process_input(bx_get('seller_provider'));
  350. $iModuleId = bx_process_input(bx_get('module_id'), BX_DATA_INT);
  351. $iItemId = bx_process_input(bx_get('item_id'), BX_DATA_INT);
  352. $iItemCount = bx_process_input(bx_get('item_count'), BX_DATA_INT);
  353. if(empty($iItemCount))
  354. $iItemCount = 1;
  355. $sRedirect = bx_process_input(bx_get('redirect'));
  356. $sCustom = bx_process_input(bx_get('custom'));
  357. $aCustom = array();
  358. if(!empty($sCustom)) {
  359. $aCustom = unserialize(base64_decode($sCustom));
  360. if(empty($aCustom) || !is_array($aCustom))
  361. $aCustom = array();
  362. }
  363. $aResult = $this->getObjectSubscriptions()->serviceSubscribe($iSellerId, $sSellerProvider, $iModuleId, $iItemId, $iItemCount, $sRedirect, $aCustom);
  364. $bRedirect = !empty($aResult['redirect']);
  365. if(!empty($aResult['popup'])) {
  366. $sContent = '';
  367. $sContent .= $this->_oTemplate->displayCartJs(BX_PAYMENT_TYPE_RECURRING, $iSellerId);
  368. $sContent .= !empty($aResult['popup']['html']) ? $aResult['popup']['html'] : $aResult['popup'];
  369. return $this->_oTemplate->displayPageCodeResponse($sContent, false, true);
  370. }
  371. if(!empty($aResult['code']))
  372. return $this->_oTemplate->displayPageCodeError($aResult['message']);
  373. if(!empty($aResult['message']) && !$bRedirect)
  374. return $this->_oTemplate->displayPageCodeResponse($aResult['message']);
  375. if($bRedirect) {
  376. header('Location: ' . $aResult['redirect']);
  377. exit;
  378. }
  379. }
  380. public function actionSubscribeJson()
  381. {
  382. $iSellerId = bx_process_input(bx_get('seller_id'), BX_DATA_INT);
  383. $sSellerProvider = bx_process_input(bx_get('seller_provider'));
  384. $iModuleId = bx_process_input(bx_get('module_id'), BX_DATA_INT);
  385. $iItemId = bx_process_input(bx_get('item_id'), BX_DATA_INT);
  386. $iItemCount = bx_process_input(bx_get('item_count'), BX_DATA_INT);
  387. if(empty($iItemCount))
  388. $iItemCount = 1;
  389. $sItemAddons = '';
  390. if(bx_get('item_addons') !== false) {
  391. $sItemAddons = bx_process_input(bx_get('item_addons'));
  392. if(is_array($sItemAddons))
  393. $sItemAddons = $this->_oConfig->a2s($sItemAddons);
  394. }
  395. $sRedirect = bx_process_input(bx_get('redirect'));
  396. $sCustom = bx_process_input(bx_get('custom'));
  397. $aCustom = array();
  398. if(!empty($sCustom)) {
  399. $aCustom = unserialize(base64_decode($sCustom));
  400. if(empty($aCustom) || !is_array($aCustom))
  401. $aCustom = array();
  402. }
  403. $aResult = $this->getObjectSubscriptions()->serviceSubscribeWithAddons($iSellerId, $sSellerProvider, $iModuleId, $iItemId, $iItemCount, $sItemAddons, $sRedirect, $aCustom);
  404. echoJson($aResult);
  405. }
  406. public function actionSubscriptionGetDetails($iId)
  407. {
  408. $aResult = $this->_oTemplate->displaySubscriptionGetDetails($iId);
  409. echoJson($aResult);
  410. }
  411. public function actionSubscriptionChangeDetails($iId)
  412. {
  413. $aResult = $this->_oTemplate->displaySubscriptionChangeDetails($iId);
  414. echoJson($aResult);
  415. }
  416. public function actionSubscriptionGetBilling($iId)
  417. {
  418. $aResult = $this->_oTemplate->displaySubscriptionGetBilling($iId);
  419. echoJson($aResult);
  420. }
  421. public function actionSubscriptionChangeBilling($iId)
  422. {
  423. $aResult = $this->_oTemplate->displaySubscriptionChangeBilling($iId);
  424. echoJson($aResult);
  425. }
  426. public function actionSubscriptionCancelation($iId)
  427. {
  428. $aResult = array('code' => 1, 'message' => _t('_bx_payment_err_cannot_perform'));
  429. $aPending = $this->_oDb->getOrderPending(array('type' => 'id', 'id' => $iId));
  430. if(empty($aPending) || !is_array($aPending))
  431. return echoJson($aResult);
  432. $aSubscription = $this->_oDb->getSubscription(array('type' => 'pending_id', 'pending_id' => $iId));
  433. if(empty($aSubscription) || !is_array($aSubscription))
  434. return echoJson($aResult);
  435. $oRecipient = BxDolProfile::getInstance((int)$aPending['seller_id']);
  436. if(!$oRecipient)
  437. return echoJson($aResult);
  438. $mixedResult = $this->isAllowedManage($aPending);
  439. if($mixedResult !== true)
  440. return echoJson(array('code' => 2, 'message' => $mixedResult));
  441. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($this->_oConfig->getPrefix('general') . 'cancelation_request', array(
  442. 'sibscription_id' => $aSubscription['subscription_id'],
  443. 'sibscription_customer' => $aSubscription['customer_id'],
  444. 'sibscription_date' => bx_time_js($aSubscription['date'], BX_FORMAT_DATE, true)
  445. ), 0, (int)$aPending['client_id']);
  446. $sEmail = '';
  447. $oProvider = $this->getObjectProvider($aPending['provider'], $aPending['seller_id']);
  448. if($oProvider !== false && $oProvider->isActive())
  449. $sEmail = $oProvider->getOption('cancellation_email');
  450. if(empty($sEmail))
  451. $sEmail = $oRecipient->getAccountObject()->getEmail();
  452. if(!sendMail($sEmail, $aTemplate['Subject'], $aTemplate['Body'], 0, array(), BX_EMAIL_SYSTEM))
  453. return echoJson($aResult);
  454. echoJson(array('code' => 0, 'message' => _t('_bx_payment_msg_cancelation_request_sent')));
  455. }
  456. public function actionSubscriptionCancel($iId, $mixedGridObject = false)
  457. {
  458. $aResult = array('code' => 1, 'message' => _t('_bx_payment_err_cannot_perform'));
  459. $aPending = $this->_oDb->getOrderPending(array('type' => 'id', 'id' => $iId));
  460. if(empty($aPending) || !is_array($aPending))
  461. return echoJson($aResult);
  462. $mixedResult = $this->isAllowedManage($aPending);
  463. if($mixedResult !== true)
  464. return echoJson(array('code' => 2, 'message' => $mixedResult));
  465. if(!$this->getObjectSubscriptions()->cancel($iId))
  466. return echoJson($aResult);
  467. if(empty($mixedGridObject) && bx_get('grid') !== false)
  468. $mixedGridObject = bx_process_input(bx_get('grid'));
  469. if(!empty($mixedGridObject) && $aPending['client_id'] == $this->getProfileId()) {
  470. $oGrid = BxDolGrid::getObjectInstance($mixedGridObject, $this->_oTemplate);
  471. $oGrid->addQueryParam('client_id', $aPending['client_id']);
  472. return echoJson(array('object' => $mixedGridObject, 'grid' => $oGrid->getCode(false), 'blink' => array($iId)));
  473. }
  474. else
  475. return echoJson(array('code' => 0, 'message' => _t('_bx_payment_msg_successfully_performed')));
  476. }
  477. /**
  478. * Payment Processing Methods
  479. */
  480. public function actionInitializeCheckout($sType)
  481. {
  482. if(!$this->isLogged())
  483. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_required_login');
  484. if(bx_get('seller_id') !== false && bx_get('provider') !== false && bx_get('items') !== false) {
  485. $iSellerId = bx_process_input(bx_get('seller_id'), BX_DATA_INT);
  486. $sProvider = bx_process_input(bx_get('provider'));
  487. $aItems = bx_process_input(bx_get('items'));
  488. $mixedResult = $this->serviceInitializeCheckout(BX_PAYMENT_TYPE_SINGLE, $iSellerId, $sProvider, $aItems);
  489. if($mixedResult !== true)
  490. return $this->_oTemplate->displayPageCodeError($mixedResult);
  491. }
  492. header('Location: ' . $this->_oConfig->getUrl('URL_CART'));
  493. exit;
  494. }
  495. /**
  496. * @page service Service Calls
  497. * @section bx_payment Payment
  498. * @subsection bx_payment-purchase_processing Purchase Processing
  499. * @subsubsection bx_payment-initialize_checkout initialize_checkout
  500. *
  501. * @code bx_srv('bx_payment', 'initialize_checkout', [...]); @endcode
  502. *
  503. * Initialize the checkout process.
  504. *
  505. * @param $sType string value with payment type (single or recurring).
  506. * @param $iSellerId integer value with seller ID.
  507. * @param $sProvider string value with payment provider name.
  508. * @param $aItems (optional) an array with items to be purchased.
  509. * @param $sRedirect (optional) string value with redirect URL if it's needed.
  510. * @param $aCustom (optional) array with custom data to attach to a payment.
  511. * @return the result depends on the payment provider which is used for processing or represented as string value with error message if something is wrong.
  512. *
  513. * @see BxPaymentModule::serviceInitializeCheckout
  514. */
  515. /**
  516. * @ref bx_payment-initialize_checkout "initialize_checkout"
  517. */
  518. public function serviceInitializeCheckout($sType, $iSellerId, $sProvider, $aItems = array(), $sRedirect = '', $aCustoms = array())
  519. {
  520. $bTypeSingle = $sType == BX_PAYMENT_TYPE_SINGLE;
  521. $bTypeRecurring = $sType == BX_PAYMENT_TYPE_RECURRING;
  522. if(!is_array($aItems))
  523. $aItems = array($aItems);
  524. $iSellerId = (int)$iSellerId;
  525. if($iSellerId == BX_PAYMENT_EMPTY_ID)
  526. return $this->_sLangsPrefix . 'err_unknown_vendor';
  527. $oProvider = $this->getObjectProvider($sProvider, $iSellerId);
  528. if($oProvider === false || !$oProvider->isActive())
  529. return $this->_sLangsPrefix . 'err_incorrect_provider';
  530. $aInfo = $this->getObjectCart()->getInfo($sType, $this->_iUserId, $iSellerId, $aItems);
  531. if(empty($aInfo) || $aInfo['vendor_id'] == BX_PAYMENT_EMPTY_ID || empty($aInfo['items']))
  532. return $this->_sLangsPrefix . 'err_empty_order';
  533. /*
  534. * Process FREE (price = 0) items for LOGGED IN members
  535. * WITHOUT processing via payment provider.
  536. * Note. This section isn't used for now!
  537. */
  538. $bProcessedFree = false;
  539. $sKeyPriceSingle = $this->_oConfig->getKey('KEY_ARRAY_PRICE_SINGLE');
  540. $sKeyPriceRecurring = $this->_oConfig->getKey('KEY_ARRAY_PRICE_RECURRING');
  541. foreach($aInfo['items'] as $iIndex => $aItem) {
  542. if((int)$aInfo['client_id'] == 0)
  543. continue;
  544. //--- For Single time payments.
  545. if($bTypeSingle && (float)$aItem[$sKeyPriceSingle] == 0) {
  546. $aCart = $this->_oDb->getCartContent($aInfo['client_id']);
  547. $aCartCustoms = !empty($aCart['customs']) ? unserialize($aCart['customs']) : array();
  548. $aCartItem = array($aInfo['vendor_id'], $aItem['module_id'], $aItem['id'], $aItem['quantity']);
  549. $aCartItemCustom = $this->_oConfig->pullCustom($aCartItem, $aCartCustoms);
  550. $aItemInfo = $this->callRegisterCartItem((int)$aItem['module_id'], array($aInfo['client_id'], $aInfo['vendor_id'], $aItem['id'], $aItem['quantity'], $this->_oConfig->getLicense(), $aCartItemCustom));
  551. if(!empty($aItemInfo) && is_array($aItemInfo)) {
  552. if(!empty($aItemInfo['addons']) && is_array($aItemInfo['addons']))
  553. foreach($aItemInfo['addons'] as $sAddon => $aAddon)
  554. $this->callRegisterCartItem((int)$aAddon['module_id'], array($aInfo['client_id'], $aInfo['vendor_id'], $aAddon['id'], $aAddon['quantity'], $this->_oConfig->getLicense(), $aCartItemCustom));
  555. $bProcessedFree = true;
  556. }
  557. $aInfo['items_count'] -= 1;
  558. unset($aInfo['items'][$iIndex]);
  559. $aCart['items'] = trim(preg_replace("'" . $this->_oConfig->descriptorA2S($aCartItem) . ":?'", "", $aCart['items']), ":");
  560. $this->_oDb->setCartItems($aInfo['client_id'], $aCart['items'], $aCartCustoms);
  561. }
  562. //--- For Recurring payments.
  563. if($bTypeRecurring && (float)$aItem[$sKeyPriceRecurring] == 0) {
  564. //TODO: Process FREE subscription here, if such situation will be possible.
  565. }
  566. }
  567. if(empty($aInfo['items']))
  568. return $this->_sLangsPrefix . ($bProcessedFree ? 'msg_successfully_processed_free' : 'err_empty_order');
  569. if($bTypeSingle && (empty($aCustoms) || !is_array($aCustoms))) {
  570. $aCart = $this->_oDb->getCartContent($aInfo['client_id']);
  571. $aCartCustoms = !empty($aCart['customs']) ? unserialize($aCart['customs']) : array();
  572. $aCustoms = array();
  573. foreach($aInfo['items'] as $aItem) {
  574. $sCartItem = $this->_oConfig->descriptorA2S(array($aInfo['vendor_id'], $aItem['module_id'], $aItem['id']));
  575. $aCartItemCustom = $this->_oConfig->getCustom($sCartItem, $aCartCustoms);
  576. $this->_oConfig->putCustom($sCartItem, $aCartItemCustom, $aCustoms);
  577. }
  578. }
  579. $iPendingId = $this->_oDb->insertOrderPending($this->_iUserId, $sType, $sProvider, $aInfo, $aCustoms);
  580. if(empty($iPendingId))
  581. return $this->_sLangsPrefix . 'err_access_db';
  582. /*
  583. * Perform Join WITHOUT processing via payment provider
  584. * if a client ISN'T logged in and has only ONE FREE item in the card.
  585. * Note. This section isn't used for now because only a member can purchase!
  586. */
  587. if((int)$aInfo['client_id'] == 0 && (int)$aInfo['items_count'] == 1) {
  588. reset($aInfo['items']);
  589. $aItem = current($aInfo['items']);
  590. if(!empty($aItem) && $this->_oConfig->getPrice($sType, $aItem)) {
  591. $this->_oDb->updateOrderPending($iPendingId, array(
  592. 'order' => $this->_oConfig->getLicense(),
  593. 'error_code' => '1',
  594. 'error_msg' => ''
  595. ));
  596. $this->getObjectJoin()->performJoin($iPendingId);
  597. }
  598. }
  599. return $oProvider->initializeCheckout($iPendingId, $aInfo, $sRedirect);
  600. }
  601. public function actionFinalizeCheckout($sProvider, $mixedVendorId = "")
  602. {
  603. $aData = &$_REQUEST;
  604. $oProvider = $this->getObjectProvider($sProvider, $mixedVendorId);
  605. if($oProvider === false || !$oProvider->isActive())
  606. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_incorrect_provider');
  607. $aResult = $oProvider->finalizeCheckout($aData);
  608. if((int)$aResult['code'] != BX_PAYMENT_RESULT_SUCCESS)
  609. return $this->_oTemplate->displayPageCodeError($aResult['message']);
  610. $aPending = $this->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$aResult['pending_id']));
  611. $bTypeRecurring = $aPending['type'] == BX_PAYMENT_TYPE_RECURRING;
  612. if($bTypeRecurring) {
  613. $aSubscription = array(
  614. 'customer_id' => $aResult['customer_id'],
  615. 'subscription_id' => $aResult['subscription_id']
  616. );
  617. if(!$this->registerSubscription($aPending, $aSubscription))
  618. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_already_registered');
  619. }
  620. $this->onPaymentRegisterBefore($aPending);
  621. //--- Check "Pay Before Join" situation
  622. if((int)$aPending['client_id'] == 0)
  623. $this->getObjectJoin()->performJoin((int)$aPending['id'], isset($aResult['client_name']) ? $aResult['client_name'] : '', isset($aResult['client_email']) ? $aResult['client_email'] : '');
  624. //--- Register payment for purchased items in associated modules
  625. if(!empty($aResult['paid']) || ($bTypeRecurring && !empty($aResult['trial'])))
  626. $this->registerPayment($aPending);
  627. bx_alert($this->getName(), 'finalize_checkout', 0, bx_get_logged_profile_id(), array(
  628. 'pending' => $aPending,
  629. 'transactions' => $this->_oDb->getOrderProcessed(array('type' => 'pending_id', 'pending_id' => (int)$aPending['id'])),
  630. 'provider' => $oProvider,
  631. 'message' => &$aResult['message'],
  632. 'result' => &$aResult,
  633. ));
  634. if($oProvider->needRedirect()) {
  635. header('Location: ' . $oProvider->getReturnUrl());
  636. exit;
  637. }
  638. if(!empty($aResult['redirect'])) {
  639. header('Location: ' . base64_decode(urldecode($aResult['redirect'])));
  640. exit;
  641. }
  642. $this->_oTemplate->displayPageCodeResponse($aResult['message']);
  643. }
  644. public function actionFinalizedCheckout($sProvider, $mixedVendorId = "")
  645. {
  646. $oProvider = $this->getObjectProvider($sProvider, $mixedVendorId);
  647. if($oProvider === false || !$oProvider->isActive())
  648. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_incorrect_provider');
  649. $aResult = $oProvider->finalizedCheckout();
  650. $this->_oTemplate->displayPageCodeResponse($aResult['message']);
  651. }
  652. public function actionNotify($sProvider, $mixedVendorId = "")
  653. {
  654. $oProvider = $this->getObjectProvider($sProvider, $mixedVendorId);
  655. if($oProvider === false || !$oProvider->isActive())
  656. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_incorrect_provider');
  657. $oProvider->notify();
  658. }
  659. public function actionCall($sProvider, $sAction)
  660. {
  661. $oProvider = $this->getObjectProvider($sProvider);
  662. if($oProvider === false)
  663. BxDolRequest::methodNotFound($sAction, $this->getName());
  664. $sMethod = 'action' . bx_gen_method_name($sAction);
  665. if(!method_exists($oProvider, $sMethod))
  666. BxDolRequest::methodNotFound($sAction, $this->getName());
  667. return call_user_func_array(array($oProvider, $sMethod), array_slice(func_get_args(), 2));
  668. }
  669. public function onProfileJoin($iProfileId)
  670. {
  671. $this->getObjectJoin()->onProfileJoin($iProfileId);
  672. }
  673. public function onProfileDelete($iProfileId)
  674. {
  675. $this->_oDb->onProfileDelete($iProfileId);
  676. }
  677. public function isAllowedPurchase($aItem, $bPerform = false)
  678. {
  679. $iUserId = (int)$this->getProfileId();
  680. $aItemInfo = $this->callGetCartItem((int)$aItem['module_id'], array($aItem['item_id'], isset($aItem['custom']) ? $aItem['custom'] : array()));
  681. if(empty($aItemInfo))
  682. return false;
  683. if(isAdmin())
  684. return true;
  685. $aCheckResult = checkActionModule($iUserId, 'purchase', $this->getName(), $bPerform);
  686. if($aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED)
  687. return true;
  688. return $aCheckResult[CHECK_ACTION_MESSAGE];
  689. }
  690. public function isAllowedSell($aItem, $bPerform = false)
  691. {
  692. $iUserId = (int)$this->getProfileId();
  693. if(!$iUserId)
  694. return false;
  695. $aItemInfo = $this->callGetCartItem((int)$aItem['module_id'], array($aItem['item_id']));
  696. if(empty($aItemInfo))
  697. return false;
  698. if(isAdmin())
  699. return true;
  700. $aCheckResult = checkActionModule($iUserId, 'sell', $this->getName(), $bPerform);
  701. if((int)$aItemInfo['author_id'] == $iUserId && $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED)
  702. return true;
  703. return $aCheckResult[CHECK_ACTION_MESSAGE];
  704. }
  705. public function isAllowedManage($aPending, $bPerform = false)
  706. {
  707. $iUserId = (int)$this->getProfileId();
  708. if($iUserId == $aPending['client_id'] || $iUserId == $aPending['seller_id'] || isAdmin())
  709. return true;
  710. $aCheckResult = checkActionModule($iUserId, 'manage any purchase', $this->getName(), $bPerform);
  711. if($aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED)
  712. return true;
  713. return $aCheckResult[CHECK_ACTION_MESSAGE];
  714. }
  715. public function checkData($iClientId, $iSellerId, $iModuleId, $iItemId, $iItemCount, $aCustom = array())
  716. {
  717. $CNF = &$this->_oConfig->CNF;
  718. if($iSellerId == BX_PAYMENT_EMPTY_ID || empty($iModuleId) || empty($iItemId) || empty($iItemCount))
  719. return array('code' => 1, 'message' => _t($CNF['T']['ERR_WRONG_DATA']));
  720. $iClientId = $this->getProfileId();
  721. if(empty($iClientId)) {
  722. $sLoginUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=login');
  723. return array('code' => 2, 'eval' => 'window.open("' . $sLoginUrl . '", "_self");');
  724. }
  725. $mixedResult = $this->isAllowedPurchase(array('module_id' => $iModuleId, 'item_id' => $iItemId, 'custom' => $aCustom));
  726. if($mixedResult !== true) {
  727. if(is_string($mixedResult) && !empty($mixedResult))
  728. return array('code' => 2, 'message' => $mixedResult);
  729. else
  730. return array('code' => 1, 'message' => _t($CNF['T']['ERR_WRONG_DATA']));
  731. }
  732. if($iClientId == $iSellerId)
  733. return array('code' => 3, 'message' => _t($CNF['T']['ERR_SELF_PURCHASE']));
  734. $aSeller = $this->getVendorInfo($iSellerId);
  735. if(!$aSeller['active'])
  736. return array('code' => 4, 'message' => _t($CNF['T']['ERR_INACTIVE_VENDOR']));
  737. return true;
  738. }
  739. public function registerPayment($mixedPending)
  740. {
  741. $aPending = is_array($mixedPending) ? $mixedPending : $this->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$mixedPending));
  742. if(empty($aPending) || !is_array($aPending))
  743. return false;
  744. $sType = $aPending['type'];
  745. $bTypeSingle = $sType == BX_PAYMENT_TYPE_SINGLE;
  746. if($bTypeSingle && (int)$aPending['processed'] == 1)
  747. return true;
  748. $iClientId = (int)$aPending['client_id'];
  749. $sLicense = $this->_oConfig->getLicense();
  750. $aCustoms = !empty($aPending['customs']) ? unserialize($aPending['customs']) : array();
  751. $aCart = array();
  752. if($bTypeSingle) {
  753. $aCart = $this->_oDb->getCartContent($iClientId);
  754. $aCart['customs'] = !empty($aCart['customs']) ? unserialize($aCart['customs']) : array();
  755. }
  756. $bResult = false;
  757. $aItems = $this->_oConfig->descriptorsM2A($aPending['items']);
  758. foreach($aItems as $aItem) {
  759. $sItem = $this->_oConfig->descriptorA2S(array($aItem['vendor_id'], $aItem['module_id'], $aItem['item_id']));
  760. $aItemCustom = $this->_oConfig->getCustom($sItem, $aCustoms);
  761. $sMethod = $bTypeSingle ? 'callRegisterCartItem' : 'callRegisterSubscriptionItem';
  762. $aItemInfo = $this->$sMethod((int)$aItem['module_id'], array($aPending['client_id'], $aPending['seller_id'], $aItem['item_id'], $aItem['item_count'], $aPending['order'], $sLicense, $aItemCustom));
  763. if(empty($aItemInfo) || !is_array($aItemInfo))
  764. continue;
  765. $this->_oDb->insertOrderProcessed(array(
  766. 'pending_id' => $aPending['id'],
  767. 'client_id' => $aPending['client_id'],
  768. 'seller_id' => $aPending['seller_id'],
  769. 'module_id' => (int)$aItem['module_id'],
  770. 'item_id' => (int)$aItem['item_id'],
  771. 'item_count' => (int)$aItem['item_count'],
  772. 'amount' => (int)$aItem['item_count'] * $this->_oConfig->getPrice($sType, $aItemInfo),
  773. 'license' => $sLicense,
  774. ));
  775. if($bTypeSingle) {
  776. $this->_oConfig->pullCustom($sItem, $aCart['customs']);
  777. $aCart['items'] = trim(preg_replace("'" . $this->_oConfig->descriptorA2S($aItem) . ":?'", "", $aCart['items']), ":");
  778. }
  779. $bResult = true;
  780. }
  781. if($bTypeSingle)
  782. $this->_oDb->setCartItems($iClientId, $aCart['items'], $aCart['customs']);
  783. if($bResult) {
  784. $this->_oDb->updateOrderPending($aPending['id'], array('processed' => 1));
  785. $this->onPaymentRegister($aPending);
  786. }
  787. return $bResult;
  788. }
  789. public function refundPayment($mixedPending)
  790. {
  791. $aPending = is_array($mixedPending) ? $mixedPending : $this->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$mixedPending));
  792. if(empty($aPending) || !is_array($aPending))
  793. return false;
  794. $bTypeSingle = $aPending['type'] == BX_PAYMENT_TYPE_SINGLE;
  795. $iCanceled = 0;
  796. $aOrders = $this->_oDb->getOrderProcessed(array('type' => 'pending_id', 'pending_id' => (int)$aPending['id']));
  797. foreach($aOrders as $aOrder) {
  798. $sMethod = $bTypeSingle ? 'callUnregisterCartItem' : 'callUnregisterSubscriptionItem';
  799. $bResult = $this->$sMethod((int)$aOrder['module_id'], array($aOrder['client_id'], $aOrder['seller_id'], $aOrder['item_id'], $aOrder['item_count'], $aPending['order'], $aOrder['license']));
  800. if(!$bResult)
  801. continue;
  802. if($this->_oDb->deleteOrderProcessed($aOrder['id']))
  803. $iCanceled++;
  804. }
  805. if($iCanceled != count($aOrders))
  806. return false;
  807. $bResult = $this->_oDb->deleteOrderPending($aPending['id']);
  808. if($bResult)
  809. $this->onPaymentRefund($aPending);
  810. return $bResult;
  811. }
  812. public function registerSubscription($aPending, $aParams = array())
  813. {
  814. if($this->_oDb->isSubscriptionByPending($aPending['id']))
  815. return false;
  816. $aSubscription = array(
  817. 'pending_id' => $aPending['id'],
  818. 'customer_id' => $aParams['customer_id'],
  819. 'subscription_id' => $aParams['subscription_id']
  820. );
  821. if(!$this->_oDb->insertSubscription($aSubscription))
  822. return false;
  823. $this->onSubscriptionCreate($aPending);
  824. return true;
  825. }
  826. public function updateSubscription($aPending, $aParams = array())
  827. {
  828. $this->_oDb->updateSubscription($aParams, array(
  829. 'pending_id' => $aPending['id']
  830. ));
  831. $this->onSubscriptionUpdate($aPending);
  832. return true;
  833. }
  834. public function cancelSubscription($mixedPending)
  835. {
  836. $aPending = is_array($mixedPending) ? $mixedPending : $this->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$mixedPending));
  837. if(empty($aPending) || !is_array($aPending) || $aPending['type'] != BX_PAYMENT_TYPE_RECURRING)
  838. return false;
  839. $aItems = $this->_oConfig->descriptorsM2A($aPending['items']);
  840. foreach($aItems as $aItem)
  841. $this->callCancelSubscriptionItem((int)$aItem['module_id'], array($aPending['client_id'], $aPending['seller_id'], $aItem['item_id'], $aItem['item_count'], $aPending['order']));
  842. $aSubscription = $this->_oDb->getSubscription(array('type' => 'pending_id', 'pending_id' => $aPending['id']));
  843. if(!empty($aSubscription) && is_array($aSubscription) && !$this->_oDb->deleteSubscription($aSubscription['id'], 'cancel'))
  844. return false;
  845. $this->onSubscriptionCancel($aPending);
  846. return true;
  847. }
  848. public function onPaymentRegisterBefore($aPending, $aResult = array())
  849. {
  850. //--- 'System' -> 'Before Register Payment' for Alerts Engine ---//
  851. bx_alert('system', 'before_register_payment', 0, $aPending['client_id'], array('pending' => $aPending));
  852. //--- 'System' -> 'Before Register Payment' for Alerts Engine ---//
  853. }
  854. public function onPaymentRegister($aPending, $aResult = array())
  855. {
  856. $bTypeSingle = $aPending['type'] == BX_PAYMENT_TYPE_SINGLE;
  857. if($bTypeSingle) {
  858. $aItems = $this->_oConfig->descriptorsM2A($aPending['items']);
  859. foreach($aItems as $aItem)
  860. $this->isAllowedPurchase(array('module_id' => $aItem['module_id'], 'item_id' => $aItem['item_id']), true);
  861. }
  862. //--- 'System' -> 'Register Payment' for Alerts Engine ---//
  863. bx_alert('system', 'register_payment', 0, $aPending['client_id'], array('pending' => $aPending));
  864. //--- 'System' -> 'Register Payment' for Alerts Engine ---//
  865. }
  866. public function onPaymentRefund($aPending, $aResult = array())
  867. {
  868. //--- 'System' -> 'Refund Payment' for Alerts Engine ---//
  869. bx_alert('system', 'refund_payment', 0, $aPending['client_id'], array('pending' => $aPending));
  870. //--- 'System' -> 'Refund Payment' for Alerts Engine ---//
  871. }
  872. public function onSubscriptionCreate($aPending, $aResult = array())
  873. {
  874. $aItems = $this->_oConfig->descriptorsM2A($aPending['items']);
  875. $this->isAllowedPurchase(array('module_id' => $aItems[0]['module_id'], 'item_id' => $aItems[0]['item_id']), true);
  876. //--- 'System' -> 'Create Subscription' for Alerts Engine ---//
  877. bx_alert('system', 'create_subscription', 0, $aPending['client_id'], array('pending' => $aPending));
  878. //--- 'System' -> 'Create Subscription' for Alerts Engine ---//
  879. }
  880. public function onSubscriptionUpdate($aPending, $aResult = array())
  881. {
  882. //--- 'System' -> 'Update Subscription' for Alerts Engine ---//
  883. bx_alert('system', 'update_subscription', 0, $aPending['client_id'], array('pending' => $aPending));
  884. //--- 'System' -> 'Update Subscription' for Alerts Engine ---//
  885. }
  886. public function onSubscriptionCancel($aPending, $aResult = array())
  887. {
  888. //--- 'System' -> 'Cancel Subscription' for Alerts Engine ---//
  889. bx_alert('system', 'cancel_subscription', 0, $aPending['client_id'], array('pending' => $aPending));
  890. //--- 'System' -> 'Cancel Subscription' for Alerts Engine ---//
  891. }
  892. public function setSiteSubmenu($sSubmenu, $sSelModule, $sSelName)
  893. {
  894. $oSiteSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  895. if(!$oSiteSubmenu)
  896. return;
  897. $sModuleSubmenu = $this->_oConfig->getObject($sSubmenu);
  898. $oModuleSubmenu = BxDolMenu::getObjectInstance($sModuleSubmenu);
  899. if(!$oModuleSubmenu)
  900. return;
  901. $oSiteSubmenu->setObjectSubmenu($sModuleSubmenu);
  902. $oModuleSubmenu->setSelected($sSelModule, $sSelName);
  903. }
  904. }
  905. /** @} */