BxPaymentModule.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  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_credits_only is_credits_only
  143. *
  144. * @code bx_srv('bx_payment', 'is_credits_only'); @endcode
  145. *
  146. * Check whether the 'Credits Only' mode is enabled or not.
  147. *
  148. * @return boolean value determining the result of checking.
  149. *
  150. * @see BxPaymentModule::serviceIsCreditsOnly
  151. */
  152. /**
  153. * @ref bx_payment-is_credits_only "is_credits_only"
  154. */
  155. public function serviceIsCreditsOnly()
  156. {
  157. return $this->_oConfig->isCreditsOnly();
  158. }
  159. /**
  160. * @page service Service Calls
  161. * @section bx_payment Payment
  162. * @subsection bx_payment-purchase_processing Purchase Processing
  163. * @subsubsection bx_payment-is_accepting_payments is_accepting_payments
  164. *
  165. * @code bx_srv('bx_payment', 'is_accepting_payments', [...]); @endcode
  166. *
  167. * Check whether the specified vendor has a configured payment provider or not.
  168. *
  169. * @param $iVendorId integer value with vendor ID.
  170. * @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.
  171. * @return boolean value determining the result of checking.
  172. *
  173. * @see BxPaymentModule::serviceIsAcceptingPayments
  174. */
  175. /**
  176. * @ref bx_payment-is_accepting_payments "is_accepting_payments"
  177. */
  178. public function serviceIsAcceptingPayments($iVendorId, $sPaymentType = '')
  179. {
  180. $bResult = false;
  181. switch($sPaymentType) {
  182. case BX_PAYMENT_TYPE_SINGLE:
  183. $aProvidersCart = $this->_oDb->getVendorInfoProvidersSingle($iVendorId);
  184. $bResult = !empty($aProvidersCart);
  185. break;
  186. case BX_PAYMENT_TYPE_RECURRING:
  187. $aProvidersSubscription = $this->_oDb->getVendorInfoProvidersRecurring($iVendorId);
  188. $bResult = !empty($aProvidersSubscription);
  189. break;
  190. default:
  191. $aProviders = $this->_oDb->getVendorInfoProviders($iVendorId);
  192. $bResult = !empty($aProviders);
  193. }
  194. return $bResult;
  195. }
  196. /**
  197. * @deprecated since version 11.0.0
  198. *
  199. * @see BxPaymentModule::serviceIsProviderOptions
  200. */
  201. public function serviceIsPaymentProvider($iVendorId, $sVendorProvider, $sPaymentType = '')
  202. {
  203. return $this->serviceIsProviderOptions($iVendorId, $sVendorProvider, $sPaymentType);
  204. }
  205. /**
  206. * @deprecated since version 11.0.0
  207. *
  208. * @see BxPaymentModule::serviceGetProviderOptions
  209. */
  210. public function serviceGetPaymentProvider($iVendorId, $sVendorProvider, $sPaymentType = '')
  211. {
  212. return $this->serviceGetProviderOptions($iVendorId, $sVendorProvider, $sPaymentType);
  213. }
  214. /**
  215. * @page service Service Calls
  216. * @section bx_payment Payment
  217. * @subsection bx_payment-purchase_processing Purchase Processing
  218. * @subsubsection bx_payment-is_provider_options is_provider_options
  219. *
  220. * @code bx_srv('bx_payment', 'is_provider_options', [...]); @endcode
  221. *
  222. * Check whether the specified vendor has configured the specified payment provider or not.
  223. *
  224. * @param $iVendorId integer value with vendor ID.
  225. * @param $sVendorProvider string value with payment provider name.
  226. * @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.
  227. * @return boolean value determining the result of checking.
  228. *
  229. * @see BxPaymentModule::serviceIsProviderOptions
  230. */
  231. /**
  232. * @ref bx_payment-is_provider_options "is_provider_options"
  233. */
  234. public function serviceIsProviderOptions($iVendorId, $sVendorProvider, $sPaymentType = '')
  235. {
  236. $aProvider = $this->serviceGetProviderOptions($iVendorId, $sVendorProvider, $sPaymentType);
  237. return $aProvider !== false;
  238. }
  239. /**
  240. * @page service Service Calls
  241. * @section bx_payment Payment
  242. * @subsection bx_payment-purchase_processing Purchase Processing
  243. * @subsubsection bx_payment-get_provider_options get_provider_options
  244. *
  245. * @code bx_srv('bx_payment', 'get_provider_options', [...]); @endcode
  246. *
  247. * Get configuration settings for the payment provider entered by the specified vendor.
  248. *
  249. * @param $iVendorId integer value with vendor ID.
  250. * @param $sVendorProvider string value with payment provider name.
  251. * @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.
  252. * @return an array with special format describing the payment provider or false value if something is wrong.
  253. *
  254. * @see BxPaymentModule::serviceGetProviderOptions
  255. */
  256. /**
  257. * @ref bx_payment-get_provider_options "get_provider_options"
  258. */
  259. public function serviceGetProviderOptions($iVendorId, $sVendorProvider, $sPaymentType = '')
  260. {
  261. $aProviders = array();
  262. switch($sPaymentType) {
  263. case BX_PAYMENT_TYPE_SINGLE:
  264. $aProviders = $this->_oDb->getVendorInfoProvidersSingle($iVendorId);
  265. break;
  266. case BX_PAYMENT_TYPE_RECURRING:
  267. $aProviders = $this->_oDb->getVendorInfoProvidersRecurring($iVendorId);
  268. break;
  269. default:
  270. $aProviders = $this->_oDb->getVendorInfoProviders($iVendorId);
  271. }
  272. return !empty($aProviders) && !empty($aProviders[$sVendorProvider]) && is_array(($aProviders[$sVendorProvider])) ? $aProviders[$sVendorProvider] : false;
  273. }
  274. /**
  275. * @page service Service Calls
  276. * @section bx_payment Payment
  277. * @subsection bx_payment-other Other
  278. * @subsubsection bx_payment-get_options_default_currency_code get_options_default_currency_code
  279. *
  280. * @code bx_srv('bx_payment', 'get_options_default_currency_code', [...]); @endcode
  281. *
  282. * Get an array with available currencies. Is used in forms.
  283. *
  284. * @return an array with available currencies represented as key => value pairs.
  285. *
  286. * @see BxPaymentModule::serviceGetOptionsDefaultCurrencyCode
  287. */
  288. /**
  289. * @ref bx_payment-get_options_default_currency_code "get_options_default_currency_code"
  290. */
  291. public function serviceGetOptionsDefaultCurrencyCode()
  292. {
  293. $CNF = &$this->_oConfig->CNF;
  294. $aCurrencies = BxDolForm::getDataItems($CNF['OBJECT_FORM_PRELISTS_CURRENCIES']);
  295. $aResult = array();
  296. foreach($aCurrencies as $sKey => $sValue)
  297. $aResult[] = array(
  298. 'key' => $sKey,
  299. 'value' => $sValue
  300. );
  301. return $aResult;
  302. }
  303. /**
  304. * @page service Service Calls
  305. * @section bx_payment Payment
  306. * @subsection bx_payment-other Other
  307. * @subsubsection bx_payment-get_options_site_admin get_options_site_admin
  308. *
  309. * @code bx_srv('bx_payment', 'get_options_site_admin', [...]); @endcode
  310. *
  311. * 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.
  312. *
  313. * @return an array with profiles represented as key => value pairs.
  314. *
  315. * @see BxPaymentModule::serviceGetOptionsSiteAdmin
  316. */
  317. /**
  318. * @ref bx_payment-get_options_site_admin "get_options_site_admin"
  319. */
  320. public function serviceGetOptionsSiteAdmin()
  321. {
  322. $aResult = array(
  323. array('key' => '', 'value' => _t('_Select_one'))
  324. );
  325. $aIds = $this->_oDb->getAdminsIds();
  326. foreach($aIds as $iId) {
  327. $aUser = $this->getProfileInfo($iId);
  328. $aResult[] = array(
  329. 'key' => $iId,
  330. 'value' => $aUser['name']
  331. );
  332. }
  333. return $aResult;
  334. }
  335. /**
  336. * Cart Processing Methods
  337. */
  338. public function actionAddToCart($iSellerId, $iModuleId, $iItemId, $iItemCount, $sCustom = '')
  339. {
  340. if(empty($sCustom) && bx_get('custom') !== false)
  341. $sCustom = bx_process_input(bx_get('custom'));
  342. $aCustom = array();
  343. if(!empty($sCustom)) {
  344. $aCustom = unserialize(base64_decode($sCustom));
  345. if(empty($aCustom) || !is_array($aCustom))
  346. $aCustom = array();
  347. }
  348. $aResult = $this->getObjectCart()->serviceAddToCart($iSellerId, $iModuleId, $iItemId, $iItemCount, $aCustom);
  349. echoJson($aResult);
  350. }
  351. /**
  352. * Isn't used yet.
  353. */
  354. public function actionDeleteFromCart($iSellerId, $iModuleId, $iItemId)
  355. {
  356. $aResult = $this->getObjectCart()->serviceDeleteFromCart($iSellerId, $iModuleId, $iItemId);
  357. echoJson($aResult);
  358. }
  359. /**
  360. * Isn't used yet.
  361. */
  362. public function actionEmptyCart($iSellerId)
  363. {
  364. $aResult = $this->getObjectCart()->serviceDeleteFromCart($iSellerId);
  365. echoJson($aResult);
  366. }
  367. public function actionSubscribe()
  368. {
  369. $iSellerId = bx_process_input(bx_get('seller_id'), BX_DATA_INT);
  370. $sSellerProvider = bx_process_input(bx_get('seller_provider'));
  371. $iModuleId = bx_process_input(bx_get('module_id'), BX_DATA_INT);
  372. $iItemId = bx_process_input(bx_get('item_id'), BX_DATA_INT);
  373. $iItemCount = bx_process_input(bx_get('item_count'), BX_DATA_INT);
  374. if(empty($iItemCount))
  375. $iItemCount = 1;
  376. $sRedirect = bx_process_input(bx_get('redirect'));
  377. $sCustom = bx_process_input(bx_get('custom'));
  378. $aCustom = array();
  379. if(!empty($sCustom)) {
  380. $aCustom = unserialize(base64_decode($sCustom));
  381. if(empty($aCustom) || !is_array($aCustom))
  382. $aCustom = array();
  383. }
  384. $aResult = $this->getObjectSubscriptions()->serviceSubscribe($iSellerId, $sSellerProvider, $iModuleId, $iItemId, $iItemCount, $sRedirect, $aCustom);
  385. $bRedirect = !empty($aResult['redirect']);
  386. if(!empty($aResult['popup'])) {
  387. $sContent = '';
  388. $sContent .= $this->_oTemplate->displayCartJs(BX_PAYMENT_TYPE_RECURRING, $iSellerId);
  389. $sContent .= !empty($aResult['popup']['html']) ? $aResult['popup']['html'] : $aResult['popup'];
  390. return $this->_oTemplate->displayPageCodeResponse($sContent, false, true);
  391. }
  392. if(!empty($aResult['code']))
  393. return $this->_oTemplate->displayPageCodeError($aResult['message']);
  394. if(!empty($aResult['message']) && !$bRedirect)
  395. return $this->_oTemplate->displayPageCodeResponse($aResult['message']);
  396. if($bRedirect) {
  397. header('Location: ' . $aResult['redirect']);
  398. exit;
  399. }
  400. }
  401. public function actionSubscribeJson()
  402. {
  403. $iSellerId = bx_process_input(bx_get('seller_id'), BX_DATA_INT);
  404. $sSellerProvider = bx_process_input(bx_get('seller_provider'));
  405. $iModuleId = bx_process_input(bx_get('module_id'), BX_DATA_INT);
  406. $iItemId = bx_process_input(bx_get('item_id'), BX_DATA_INT);
  407. $iItemCount = bx_process_input(bx_get('item_count'), BX_DATA_INT);
  408. if(empty($iItemCount))
  409. $iItemCount = 1;
  410. $sItemAddons = '';
  411. if(bx_get('item_addons') !== false) {
  412. $sItemAddons = bx_process_input(bx_get('item_addons'));
  413. if(is_array($sItemAddons))
  414. $sItemAddons = $this->_oConfig->a2s($sItemAddons);
  415. }
  416. $sRedirect = bx_process_input(bx_get('redirect'));
  417. $sCustom = bx_process_input(bx_get('custom'));
  418. $aCustom = array();
  419. if(!empty($sCustom)) {
  420. $aCustom = unserialize(base64_decode($sCustom));
  421. if(empty($aCustom) || !is_array($aCustom))
  422. $aCustom = array();
  423. }
  424. $aResult = $this->getObjectSubscriptions()->serviceSubscribeWithAddons($iSellerId, $sSellerProvider, $iModuleId, $iItemId, $iItemCount, $sItemAddons, $sRedirect, $aCustom);
  425. echoJson($aResult);
  426. }
  427. public function actionSubscriptionGetDetails($iId)
  428. {
  429. $aResult = $this->_oTemplate->displaySubscriptionGetDetails($iId);
  430. echoJson($aResult);
  431. }
  432. public function actionSubscriptionChangeDetails($iId)
  433. {
  434. $aResult = $this->_oTemplate->displaySubscriptionChangeDetails($iId);
  435. echoJson($aResult);
  436. }
  437. public function actionSubscriptionGetBilling($iId)
  438. {
  439. $aResult = $this->_oTemplate->displaySubscriptionGetBilling($iId);
  440. echoJson($aResult);
  441. }
  442. public function actionSubscriptionChangeBilling($iId)
  443. {
  444. $aResult = $this->_oTemplate->displaySubscriptionChangeBilling($iId);
  445. echoJson($aResult);
  446. }
  447. public function actionSubscriptionCancelation($iId)
  448. {
  449. $aResult = array('code' => 1, 'message' => _t('_bx_payment_err_cannot_perform'));
  450. $aPending = $this->_oDb->getOrderPending(array('type' => 'id', 'id' => $iId));
  451. if(empty($aPending) || !is_array($aPending))
  452. return echoJson($aResult);
  453. $aSubscription = $this->_oDb->getSubscription(array('type' => 'pending_id', 'pending_id' => $iId));
  454. if(empty($aSubscription) || !is_array($aSubscription))
  455. return echoJson($aResult);
  456. $oRecipient = BxDolProfile::getInstance((int)$aPending['seller_id']);
  457. if(!$oRecipient)
  458. return echoJson($aResult);
  459. $mixedResult = $this->isAllowedManage($aPending);
  460. if($mixedResult !== true)
  461. return echoJson(array('code' => 2, 'message' => $mixedResult));
  462. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($this->_oConfig->getPrefix('general') . 'cancelation_request', array(
  463. 'sibscription_id' => $aSubscription['subscription_id'],
  464. 'sibscription_customer' => $aSubscription['customer_id'],
  465. 'sibscription_date' => bx_time_js($aSubscription['date'], BX_FORMAT_DATE, true)
  466. ), 0, (int)$aPending['client_id']);
  467. $sEmail = '';
  468. $oProvider = $this->getObjectProvider($aPending['provider'], $aPending['seller_id']);
  469. if($oProvider !== false && $oProvider->isActive())
  470. $sEmail = $oProvider->getOption('cancellation_email');
  471. if(empty($sEmail))
  472. $sEmail = $oRecipient->getAccountObject()->getEmail();
  473. if(!sendMail($sEmail, $aTemplate['Subject'], $aTemplate['Body'], 0, array(), BX_EMAIL_SYSTEM))
  474. return echoJson($aResult);
  475. echoJson(array('code' => 0, 'message' => _t('_bx_payment_msg_cancelation_request_sent')));
  476. }
  477. public function actionSubscriptionCancel($iId, $mixedGridObject = false)
  478. {
  479. $aResult = array('code' => 1, 'message' => _t('_bx_payment_err_cannot_perform'));
  480. $aPending = $this->_oDb->getOrderPending(array('type' => 'id', 'id' => $iId));
  481. if(empty($aPending) || !is_array($aPending))
  482. return echoJson($aResult);
  483. $mixedResult = $this->isAllowedManage($aPending);
  484. if($mixedResult !== true)
  485. return echoJson(array('code' => 2, 'message' => $mixedResult));
  486. if(!$this->getObjectSubscriptions()->cancel($iId))
  487. return echoJson($aResult);
  488. if(empty($mixedGridObject) && bx_get('grid') !== false)
  489. $mixedGridObject = bx_process_input(bx_get('grid'));
  490. if(!empty($mixedGridObject) && $aPending['client_id'] == $this->getProfileId()) {
  491. $oGrid = BxDolGrid::getObjectInstance($mixedGridObject, $this->_oTemplate);
  492. $oGrid->addQueryParam('client_id', $aPending['client_id']);
  493. return echoJson(array('object' => $mixedGridObject, 'grid' => $oGrid->getCode(false), 'blink' => array($iId)));
  494. }
  495. else
  496. return echoJson(array('code' => 0, 'message' => _t('_bx_payment_msg_successfully_performed')));
  497. }
  498. /**
  499. * Payment Processing Methods
  500. */
  501. public function actionInitializeCheckout($sType)
  502. {
  503. if(!$this->isLogged())
  504. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_required_login');
  505. if(bx_get('seller_id') !== false && bx_get('provider') !== false && bx_get('items') !== false) {
  506. $iSellerId = bx_process_input(bx_get('seller_id'), BX_DATA_INT);
  507. $sProvider = bx_process_input(bx_get('provider'));
  508. $aItems = bx_process_input(bx_get('items'));
  509. $mixedResult = $this->serviceInitializeCheckout(BX_PAYMENT_TYPE_SINGLE, $iSellerId, $sProvider, $aItems);
  510. if($mixedResult !== true)
  511. return $this->_oTemplate->displayPageCodeError($mixedResult);
  512. }
  513. header('Location: ' . $this->_oConfig->getUrl('URL_CART'));
  514. exit;
  515. }
  516. /**
  517. * @page service Service Calls
  518. * @section bx_payment Payment
  519. * @subsection bx_payment-purchase_processing Purchase Processing
  520. * @subsubsection bx_payment-initialize_checkout initialize_checkout
  521. *
  522. * @code bx_srv('bx_payment', 'initialize_checkout', [...]); @endcode
  523. *
  524. * Initialize the checkout process.
  525. *
  526. * @param $sType string value with payment type (single or recurring).
  527. * @param $iSellerId integer value with seller ID.
  528. * @param $sProvider string value with payment provider name.
  529. * @param $aItems (optional) an array with items to be purchased.
  530. * @param $sRedirect (optional) string value with redirect URL if it's needed.
  531. * @param $aCustom (optional) array with custom data to attach to a payment.
  532. * @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.
  533. *
  534. * @see BxPaymentModule::serviceInitializeCheckout
  535. */
  536. /**
  537. * @ref bx_payment-initialize_checkout "initialize_checkout"
  538. */
  539. public function serviceInitializeCheckout($sType, $iSellerId, $sProvider, $aItems = array(), $sRedirect = '', $aCustoms = array())
  540. {
  541. $bTypeSingle = $sType == BX_PAYMENT_TYPE_SINGLE;
  542. $bTypeRecurring = $sType == BX_PAYMENT_TYPE_RECURRING;
  543. if(!is_array($aItems))
  544. $aItems = array($aItems);
  545. $iSellerId = (int)$iSellerId;
  546. if($iSellerId == BX_PAYMENT_EMPTY_ID)
  547. return $this->_sLangsPrefix . 'err_unknown_vendor';
  548. $oProvider = $this->getObjectProvider($sProvider, $iSellerId);
  549. if($oProvider === false || !$oProvider->isActive())
  550. return $this->_sLangsPrefix . 'err_incorrect_provider';
  551. $aInfo = $this->getObjectCart()->getInfo($sType, $this->_iUserId, $iSellerId, $aItems);
  552. if(empty($aInfo) || $aInfo['vendor_id'] == BX_PAYMENT_EMPTY_ID || empty($aInfo['items']))
  553. return $this->_sLangsPrefix . 'err_empty_order';
  554. /*
  555. * Process FREE (price = 0) items for LOGGED IN members
  556. * WITHOUT processing via payment provider.
  557. * Note. This section isn't used for now!
  558. */
  559. $bProcessedFree = false;
  560. $sKeyPriceSingle = $this->_oConfig->getKey('KEY_ARRAY_PRICE_SINGLE');
  561. $sKeyPriceRecurring = $this->_oConfig->getKey('KEY_ARRAY_PRICE_RECURRING');
  562. foreach($aInfo['items'] as $iIndex => $aItem) {
  563. if((int)$aInfo['client_id'] == 0)
  564. continue;
  565. //--- For Single time payments.
  566. if($bTypeSingle && (float)$aItem[$sKeyPriceSingle] == 0) {
  567. $aCart = $this->_oDb->getCartContent($aInfo['client_id']);
  568. $aCartCustoms = !empty($aCart['customs']) ? unserialize($aCart['customs']) : array();
  569. $aCartItem = array($aInfo['vendor_id'], $aItem['module_id'], $aItem['id'], $aItem['quantity']);
  570. $aCartItemCustom = $this->_oConfig->pullCustom($aCartItem, $aCartCustoms);
  571. $aItemInfo = $this->callRegisterCartItem((int)$aItem['module_id'], array($aInfo['client_id'], $aInfo['vendor_id'], $aItem['id'], $aItem['quantity'], $this->_oConfig->getLicense(), $aCartItemCustom));
  572. if(!empty($aItemInfo) && is_array($aItemInfo)) {
  573. if(!empty($aItemInfo['addons']) && is_array($aItemInfo['addons']))
  574. foreach($aItemInfo['addons'] as $sAddon => $aAddon)
  575. $this->callRegisterCartItem((int)$aAddon['module_id'], array($aInfo['client_id'], $aInfo['vendor_id'], $aAddon['id'], $aAddon['quantity'], $this->_oConfig->getLicense(), $aCartItemCustom));
  576. $bProcessedFree = true;
  577. }
  578. $aInfo['items_count'] -= 1;
  579. unset($aInfo['items'][$iIndex]);
  580. $aCart['items'] = trim(preg_replace("'" . $this->_oConfig->descriptorA2S($aCartItem) . ":?'", "", $aCart['items']), ":");
  581. $this->_oDb->setCartItems($aInfo['client_id'], $aCart['items'], $aCartCustoms);
  582. }
  583. //--- For Recurring payments.
  584. if($bTypeRecurring && (float)$aItem[$sKeyPriceRecurring] == 0) {
  585. //TODO: Process FREE subscription here, if such situation will be possible.
  586. }
  587. }
  588. if(empty($aInfo['items']))
  589. return $this->_sLangsPrefix . ($bProcessedFree ? 'msg_successfully_processed_free' : 'err_empty_order');
  590. if($bTypeSingle && (empty($aCustoms) || !is_array($aCustoms))) {
  591. $aCart = $this->_oDb->getCartContent($aInfo['client_id']);
  592. $aCartCustoms = !empty($aCart['customs']) ? unserialize($aCart['customs']) : array();
  593. $aCustoms = array();
  594. foreach($aInfo['items'] as $aItem) {
  595. $sCartItem = $this->_oConfig->descriptorA2S(array($aInfo['vendor_id'], $aItem['module_id'], $aItem['id']));
  596. $aCartItemCustom = $this->_oConfig->getCustom($sCartItem, $aCartCustoms);
  597. $this->_oConfig->putCustom($sCartItem, $aCartItemCustom, $aCustoms);
  598. }
  599. }
  600. $iPendingId = $this->_oDb->insertOrderPending($this->_iUserId, $sType, $sProvider, $aInfo, $aCustoms);
  601. if(empty($iPendingId))
  602. return $this->_sLangsPrefix . 'err_access_db';
  603. /*
  604. * Perform Join WITHOUT processing via payment provider
  605. * if a client ISN'T logged in and has only ONE FREE item in the card.
  606. * Note. This section isn't used for now because only a member can purchase!
  607. */
  608. if((int)$aInfo['client_id'] == 0 && (int)$aInfo['items_count'] == 1) {
  609. reset($aInfo['items']);
  610. $aItem = current($aInfo['items']);
  611. if(!empty($aItem) && $this->_oConfig->getPrice($sType, $aItem)) {
  612. $this->_oDb->updateOrderPending($iPendingId, array(
  613. 'order' => $this->_oConfig->getLicense(),
  614. 'error_code' => '1',
  615. 'error_msg' => ''
  616. ));
  617. $this->getObjectJoin()->performJoin($iPendingId);
  618. }
  619. }
  620. return $oProvider->initializeCheckout($iPendingId, $aInfo, $sRedirect);
  621. }
  622. public function actionFinalizeCheckout($sProvider, $mixedVendorId = "")
  623. {
  624. $aData = &$_REQUEST;
  625. $oProvider = $this->getObjectProvider($sProvider, $mixedVendorId);
  626. if($oProvider === false || !$oProvider->isActive())
  627. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_incorrect_provider');
  628. $aResult = $oProvider->finalizeCheckout($aData);
  629. if((int)$aResult['code'] != BX_PAYMENT_RESULT_SUCCESS)
  630. return $this->_oTemplate->displayPageCodeError($aResult['message']);
  631. $aPending = $this->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$aResult['pending_id']));
  632. $bTypeRecurring = $aPending['type'] == BX_PAYMENT_TYPE_RECURRING;
  633. if($bTypeRecurring) {
  634. $aSubscription = array(
  635. 'customer_id' => $aResult['customer_id'],
  636. 'subscription_id' => $aResult['subscription_id']
  637. );
  638. if(!$this->registerSubscription($aPending, $aSubscription))
  639. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_already_registered');
  640. }
  641. $this->onPaymentRegisterBefore($aPending);
  642. //--- Check "Pay Before Join" situation
  643. if((int)$aPending['client_id'] == 0)
  644. $this->getObjectJoin()->performJoin((int)$aPending['id'], isset($aResult['client_name']) ? $aResult['client_name'] : '', isset($aResult['client_email']) ? $aResult['client_email'] : '');
  645. //--- Register payment for purchased items in associated modules
  646. if(!empty($aResult['paid']) || ($bTypeRecurring && !empty($aResult['trial'])))
  647. $this->registerPayment($aPending);
  648. bx_alert($this->getName(), 'finalize_checkout', 0, bx_get_logged_profile_id(), array(
  649. 'pending' => $aPending,
  650. 'transactions' => $this->_oDb->getOrderProcessed(array('type' => 'pending_id', 'pending_id' => (int)$aPending['id'])),
  651. 'provider' => $oProvider,
  652. 'message' => &$aResult['message'],
  653. 'result' => &$aResult,
  654. ));
  655. if($oProvider->needRedirect()) {
  656. header('Location: ' . $oProvider->getReturnUrl());
  657. exit;
  658. }
  659. if(!empty($aResult['redirect'])) {
  660. header('Location: ' . base64_decode(urldecode($aResult['redirect'])));
  661. exit;
  662. }
  663. $this->_oTemplate->displayPageCodeResponse($aResult['message']);
  664. }
  665. public function actionFinalizedCheckout($sProvider, $mixedVendorId = "")
  666. {
  667. $oProvider = $this->getObjectProvider($sProvider, $mixedVendorId);
  668. if($oProvider === false || !$oProvider->isActive())
  669. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_incorrect_provider');
  670. $aResult = $oProvider->finalizedCheckout();
  671. $this->_oTemplate->displayPageCodeResponse($aResult['message']);
  672. }
  673. public function actionNotify($sProvider, $mixedVendorId = "")
  674. {
  675. $oProvider = $this->getObjectProvider($sProvider, $mixedVendorId);
  676. if($oProvider === false || !$oProvider->isActive())
  677. return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_incorrect_provider');
  678. $oProvider->notify();
  679. }
  680. public function actionCall($sProvider, $sAction)
  681. {
  682. $oProvider = $this->getObjectProvider($sProvider);
  683. if($oProvider === false)
  684. BxDolRequest::methodNotFound($sAction, $this->getName());
  685. $sMethod = 'action' . bx_gen_method_name($sAction);
  686. if(!method_exists($oProvider, $sMethod))
  687. BxDolRequest::methodNotFound($sAction, $this->getName());
  688. return call_user_func_array(array($oProvider, $sMethod), array_slice(func_get_args(), 2));
  689. }
  690. public function onProfileJoin($iProfileId)
  691. {
  692. $this->getObjectJoin()->onProfileJoin($iProfileId);
  693. }
  694. public function onProfileDelete($iProfileId)
  695. {
  696. $this->_oDb->onProfileDelete($iProfileId);
  697. }
  698. public function isAllowedPurchase($aItem, $bPerform = false)
  699. {
  700. $iUserId = (int)$this->getProfileId();
  701. $aItemInfo = $this->callGetCartItem((int)$aItem['module_id'], array($aItem['item_id'], isset($aItem['custom']) ? $aItem['custom'] : array()));
  702. if(empty($aItemInfo))
  703. return false;
  704. if(isAdmin())
  705. return true;
  706. $aCheckResult = checkActionModule($iUserId, 'purchase', $this->getName(), $bPerform);
  707. if($aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED)
  708. return true;
  709. return $aCheckResult[CHECK_ACTION_MESSAGE];
  710. }
  711. public function isAllowedSell($aItem, $bPerform = false)
  712. {
  713. $iUserId = (int)$this->getProfileId();
  714. if(!$iUserId)
  715. return false;
  716. $aItemInfo = $this->callGetCartItem((int)$aItem['module_id'], array($aItem['item_id']));
  717. if(empty($aItemInfo))
  718. return false;
  719. if(isAdmin())
  720. return true;
  721. $aCheckResult = checkActionModule($iUserId, 'sell', $this->getName(), $bPerform);
  722. if((int)$aItemInfo['author_id'] == $iUserId && $aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED)
  723. return true;
  724. return $aCheckResult[CHECK_ACTION_MESSAGE];
  725. }
  726. public function isAllowedManage($aPending, $bPerform = false)
  727. {
  728. $iUserId = (int)$this->getProfileId();
  729. if($iUserId == $aPending['client_id'] || $iUserId == $aPending['seller_id'] || isAdmin())
  730. return true;
  731. $aCheckResult = checkActionModule($iUserId, 'manage any purchase', $this->getName(), $bPerform);
  732. if($aCheckResult[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED)
  733. return true;
  734. return $aCheckResult[CHECK_ACTION_MESSAGE];
  735. }
  736. public function checkData($iClientId, $iSellerId, $iModuleId, $iItemId, $iItemCount, $aCustom = array())
  737. {
  738. $CNF = &$this->_oConfig->CNF;
  739. if($iSellerId == BX_PAYMENT_EMPTY_ID || empty($iModuleId) || empty($iItemId) || empty($iItemCount))
  740. return array('code' => 1, 'message' => _t($CNF['T']['ERR_WRONG_DATA']));
  741. $iClientId = $this->getProfileId();
  742. if(empty($iClientId)) {
  743. $sLoginUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=login');
  744. return array('code' => 2, 'eval' => 'window.open("' . $sLoginUrl . '", "_self");');
  745. }
  746. $mixedResult = $this->isAllowedPurchase(array('module_id' => $iModuleId, 'item_id' => $iItemId, 'custom' => $aCustom));
  747. if($mixedResult !== true) {
  748. if(is_string($mixedResult) && !empty($mixedResult))
  749. return array('code' => 2, 'message' => $mixedResult);
  750. else
  751. return array('code' => 1, 'message' => _t($CNF['T']['ERR_WRONG_DATA']));
  752. }
  753. if($iClientId == $iSellerId)
  754. return array('code' => 3, 'message' => _t($CNF['T']['ERR_SELF_PURCHASE']));
  755. $aSeller = $this->getVendorInfo($iSellerId);
  756. if(!$aSeller['active'])
  757. return array('code' => 4, 'message' => _t($CNF['T']['ERR_INACTIVE_VENDOR']));
  758. return true;
  759. }
  760. public function registerPayment($mixedPending)
  761. {
  762. $aPending = is_array($mixedPending) ? $mixedPending : $this->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$mixedPending));
  763. if(empty($aPending) || !is_array($aPending))
  764. return false;
  765. $sType = $aPending['type'];
  766. $bTypeSingle = $sType == BX_PAYMENT_TYPE_SINGLE;
  767. if($bTypeSingle && (int)$aPending['processed'] == 1)
  768. return true;
  769. $iClientId = (int)$aPending['client_id'];
  770. $sLicense = $this->_oConfig->getLicense();
  771. $aCustoms = !empty($aPending['customs']) ? unserialize($aPending['customs']) : array();
  772. $aCart = array();
  773. if($bTypeSingle) {
  774. $aCart = $this->_oDb->getCartContent($iClientId);
  775. $aCart['customs'] = !empty($aCart['customs']) ? unserialize($aCart['customs']) : array();
  776. }
  777. $bResult = false;
  778. $aItems = $this->_oConfig->descriptorsM2A($aPending['items']);
  779. foreach($aItems as $aItem) {
  780. $sItem = $this->_oConfig->descriptorA2S(array($aItem['vendor_id'], $aItem['module_id'], $aItem['item_id']));
  781. $aItemCustom = $this->_oConfig->getCustom($sItem, $aCustoms);
  782. $sMethod = $bTypeSingle ? 'callRegisterCartItem' : 'callRegisterSubscriptionItem';
  783. $aItemInfo = $this->$sMethod((int)$aItem['module_id'], array($aPending['client_id'], $aPending['seller_id'], $aItem['item_id'], $aItem['item_count'], $aPending['order'], $sLicense, $aItemCustom));
  784. if(empty($aItemInfo) || !is_array($aItemInfo))
  785. continue;
  786. $this->_oDb->insertOrderProcessed(array(
  787. 'pending_id' => $aPending['id'],
  788. 'client_id' => $aPending['client_id'],
  789. 'seller_id' => $aPending['seller_id'],
  790. 'module_id' => (int)$aItem['module_id'],
  791. 'item_id' => (int)$aItem['item_id'],
  792. 'item_count' => (int)$aItem['item_count'],
  793. 'amount' => (int)$aItem['item_count'] * $this->_oConfig->getPrice($sType, $aItemInfo),
  794. 'license' => $sLicense,
  795. ));
  796. if($bTypeSingle) {
  797. $this->_oConfig->pullCustom($sItem, $aCart['customs']);
  798. $aCart['items'] = trim(preg_replace("'" . $this->_oConfig->descriptorA2S($aItem) . ":?'", "", $aCart['items']), ":");
  799. }
  800. $bResult = true;
  801. }
  802. if($bTypeSingle)
  803. $this->_oDb->setCartItems($iClientId, $aCart['items'], $aCart['customs']);
  804. if($bResult) {
  805. $this->_oDb->updateOrderPending($aPending['id'], array('processed' => 1));
  806. $this->onPaymentRegister($aPending);
  807. }
  808. return $bResult;
  809. }
  810. public function refundPayment($mixedPending)
  811. {
  812. $aPending = is_array($mixedPending) ? $mixedPending : $this->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$mixedPending));
  813. if(empty($aPending) || !is_array($aPending))
  814. return false;
  815. $bTypeSingle = $aPending['type'] == BX_PAYMENT_TYPE_SINGLE;
  816. $iCanceled = 0;
  817. $aOrders = $this->_oDb->getOrderProcessed(array('type' => 'pending_id', 'pending_id' => (int)$aPending['id']));
  818. foreach($aOrders as $aOrder) {
  819. $sMethod = $bTypeSingle ? 'callUnregisterCartItem' : 'callUnregisterSubscriptionItem';
  820. $bResult = $this->$sMethod((int)$aOrder['module_id'], array($aOrder['client_id'], $aOrder['seller_id'], $aOrder['item_id'], $aOrder['item_count'], $aPending['order'], $aOrder['license']));
  821. if(!$bResult)
  822. continue;
  823. if($this->_oDb->deleteOrderProcessed($aOrder['id']))
  824. $iCanceled++;
  825. }
  826. if($iCanceled != count($aOrders))
  827. return false;
  828. $bResult = $this->_oDb->deleteOrderPending($aPending['id']);
  829. if($bResult)
  830. $this->onPaymentRefund($aPending);
  831. return $bResult;
  832. }
  833. public function registerSubscription($aPending, $aParams = array())
  834. {
  835. if($this->_oDb->isSubscriptionByPending($aPending['id']))
  836. return false;
  837. $aSubscription = array(
  838. 'pending_id' => $aPending['id'],
  839. 'customer_id' => $aParams['customer_id'],
  840. 'subscription_id' => $aParams['subscription_id']
  841. );
  842. if(!$this->_oDb->insertSubscription($aSubscription))
  843. return false;
  844. $this->onSubscriptionCreate($aPending);
  845. return true;
  846. }
  847. public function updateSubscription($aPending, $aParams = array())
  848. {
  849. $this->_oDb->updateSubscription($aParams, array(
  850. 'pending_id' => $aPending['id']
  851. ));
  852. $this->onSubscriptionUpdate($aPending);
  853. return true;
  854. }
  855. public function cancelSubscription($mixedPending)
  856. {
  857. $aPending = is_array($mixedPending) ? $mixedPending : $this->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$mixedPending));
  858. if(empty($aPending) || !is_array($aPending) || $aPending['type'] != BX_PAYMENT_TYPE_RECURRING)
  859. return false;
  860. $aItems = $this->_oConfig->descriptorsM2A($aPending['items']);
  861. foreach($aItems as $aItem)
  862. $this->callCancelSubscriptionItem((int)$aItem['module_id'], array($aPending['client_id'], $aPending['seller_id'], $aItem['item_id'], $aItem['item_count'], $aPending['order']));
  863. $aSubscription = $this->_oDb->getSubscription(array('type' => 'pending_id', 'pending_id' => $aPending['id']));
  864. if(!empty($aSubscription) && is_array($aSubscription) && !$this->_oDb->deleteSubscription($aSubscription['id'], 'cancel'))
  865. return false;
  866. $this->onSubscriptionCancel($aPending);
  867. return true;
  868. }
  869. public function onPaymentRegisterBefore($aPending, $aResult = array())
  870. {
  871. //--- 'System' -> 'Before Register Payment' for Alerts Engine ---//
  872. bx_alert('system', 'before_register_payment', 0, $aPending['client_id'], array('pending' => $aPending));
  873. //--- 'System' -> 'Before Register Payment' for Alerts Engine ---//
  874. }
  875. public function onPaymentRegister($aPending, $aResult = array())
  876. {
  877. $bTypeSingle = $aPending['type'] == BX_PAYMENT_TYPE_SINGLE;
  878. if($bTypeSingle) {
  879. $aItems = $this->_oConfig->descriptorsM2A($aPending['items']);
  880. foreach($aItems as $aItem)
  881. $this->isAllowedPurchase(array('module_id' => $aItem['module_id'], 'item_id' => $aItem['item_id']), true);
  882. }
  883. //--- 'System' -> 'Register Payment' for Alerts Engine ---//
  884. bx_alert('system', 'register_payment', 0, $aPending['client_id'], array('pending' => $aPending));
  885. //--- 'System' -> 'Register Payment' for Alerts Engine ---//
  886. }
  887. public function onPaymentRefund($aPending, $aResult = array())
  888. {
  889. //--- 'System' -> 'Refund Payment' for Alerts Engine ---//
  890. bx_alert('system', 'refund_payment', 0, $aPending['client_id'], array('pending' => $aPending));
  891. //--- 'System' -> 'Refund Payment' for Alerts Engine ---//
  892. }
  893. public function onSubscriptionCreate($aPending, $aResult = array())
  894. {
  895. $aItems = $this->_oConfig->descriptorsM2A($aPending['items']);
  896. $this->isAllowedPurchase(array('module_id' => $aItems[0]['module_id'], 'item_id' => $aItems[0]['item_id']), true);
  897. //--- 'System' -> 'Create Subscription' for Alerts Engine ---//
  898. bx_alert('system', 'create_subscription', 0, $aPending['client_id'], array('pending' => $aPending));
  899. //--- 'System' -> 'Create Subscription' for Alerts Engine ---//
  900. }
  901. public function onSubscriptionUpdate($aPending, $aResult = array())
  902. {
  903. //--- 'System' -> 'Update Subscription' for Alerts Engine ---//
  904. bx_alert('system', 'update_subscription', 0, $aPending['client_id'], array('pending' => $aPending));
  905. //--- 'System' -> 'Update Subscription' for Alerts Engine ---//
  906. }
  907. public function onSubscriptionCancel($aPending, $aResult = array())
  908. {
  909. //--- 'System' -> 'Cancel Subscription' for Alerts Engine ---//
  910. bx_alert('system', 'cancel_subscription', 0, $aPending['client_id'], array('pending' => $aPending));
  911. //--- 'System' -> 'Cancel Subscription' for Alerts Engine ---//
  912. }
  913. public function setSiteSubmenu($sSubmenu, $sSelModule, $sSelName)
  914. {
  915. $oSiteSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  916. if(!$oSiteSubmenu)
  917. return;
  918. $sModuleSubmenu = $this->_oConfig->getObject($sSubmenu);
  919. $oModuleSubmenu = BxDolMenu::getObjectInstance($sModuleSubmenu);
  920. if(!$oModuleSubmenu)
  921. return;
  922. $oSiteSubmenu->setObjectSubmenu($sModuleSubmenu);
  923. $oModuleSubmenu->setSelected($sSelModule, $sSelName);
  924. }
  925. }
  926. /** @} */