1
0

BxPaymentSubscriptions.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Payment Payment
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxPaymentSubscriptions extends BxBaseModPaymentSubscriptions
  12. {
  13. function __construct()
  14. {
  15. $this->MODULE = 'bx_payment';
  16. parent::__construct();
  17. }
  18. /*
  19. * Service methods
  20. */
  21. /**
  22. * @page service Service Calls
  23. * @section bx_payment Payment
  24. * @subsection bx_payment-page_blocks Page Blocks
  25. * @subsubsection bx_payment-get_block_list_my get_block_list_my
  26. *
  27. * @code bx_srv('bx_payment', 'get_block_list_my', [...], 'Subscriptions'); @endcode
  28. *
  29. * Get page block with a list of currently logged in member's subscriptions.
  30. *
  31. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  32. *
  33. * @see BxPaymentSubscriptions::serviceGetBlockListMy
  34. */
  35. /**
  36. * @ref bx_payment-get_block_list_my "get_block_list_my"
  37. */
  38. public function serviceGetBlockListMy()
  39. {
  40. return $this->_getBlock('list_my');
  41. }
  42. /**
  43. * @page service Service Calls
  44. * @section bx_payment Payment
  45. * @subsection bx_payment-page_blocks Page Blocks
  46. * @subsubsection bx_payment-get_block_list_all get_block_list_all
  47. *
  48. * @code bx_srv('bx_payment', 'get_block_list_all', [...], 'Subscriptions'); @endcode
  49. *
  50. * Get page block with a list of all subscriptions. It's available for authorized members only.
  51. *
  52. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  53. *
  54. * @see BxPaymentSubscriptions::serviceGetBlockListAll
  55. */
  56. /**
  57. * @ref bx_payment-get_block_list_all "get_block_list_all"
  58. */
  59. public function serviceGetBlockListAll()
  60. {
  61. return $this->_getBlock('list_all');
  62. }
  63. /**
  64. * @page service Service Calls
  65. * @section bx_payment Payment
  66. * @subsection bx_payment-page_blocks Page Blocks
  67. * @subsubsection bx_payment-get_block_history get_block_history
  68. *
  69. * @code bx_srv('bx_payment', 'get_block_history', [...], 'Subscriptions'); @endcode
  70. *
  71. * Get page block with a list of payments related to subscriptions of currently logged in member.
  72. *
  73. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  74. *
  75. * @see BxPaymentSubscriptions::serviceGetBlockHistory
  76. */
  77. /**
  78. * @ref bx_payment-get_block_history "get_block_history"
  79. */
  80. public function serviceGetBlockHistory()
  81. {
  82. return $this->_getBlock('history');
  83. }
  84. /**
  85. * @page service Service Calls
  86. * @section bx_payment Payment
  87. * @subsection bx_payment-other Other
  88. * @subsubsection bx_payment-get_subscription_orders_info get_subscription_orders_info
  89. *
  90. * @code bx_srv('bx_payment', 'get_subscription_orders_info', [...], 'Subscriptions'); @endcode
  91. *
  92. * Get subscription transaction(s) which meets all requirements.
  93. *
  94. * @param $aConditions an array of pears('key' => 'value'). The most useful keys are the following:
  95. * a. client_id - client's ID (integer)
  96. * b. seller_id - seller's ID (integer)
  97. * c. type - transaction type: single or recurring (string)
  98. * d. amount - transaction amount (float)
  99. * e. order - order ID received from payment provider (string)
  100. * f. provider - payment provider name (string)
  101. * g. date - the date when the payment was established(UNIXTIME STAMP)
  102. * h. processed - whether the payment was processed or not (integer, 0 or 1)
  103. * @return an array of transactions. Each transaction has full info(client ID, seller ID, external transaction ID, date and so on)
  104. *
  105. * @see BxPaymentSubscriptions::serviceGetSubscriptionOrdersInfo
  106. */
  107. /**
  108. * @ref bx_payment-get_subscription_orders_info "get_subscription_orders_info"
  109. */
  110. public function serviceGetSubscriptionOrdersInfo($aConditions)
  111. {
  112. if(empty($aConditions) || !is_array($aConditions))
  113. return array();
  114. return $this->_oModule->_oDb->getOrderSubscription(array('type' => 'mixed', 'conditions' => $aConditions));
  115. }
  116. /**
  117. * @page service Service Calls
  118. * @section bx_payment Payment
  119. * @subsection bx_payment-other Other
  120. * @subsubsection bx_payment-get_subscriptions_info get_subscriptions_info
  121. *
  122. * @code bx_srv('bx_payment', 'get_subscriptions_info', [...], 'Subscriptions'); @endcode
  123. *
  124. * Get subscription(s) which meets all requirements.
  125. *
  126. * @param $aConditions an array of pears('key' => 'value'). The most useful keys are the following:
  127. * a. pending_id - pending transaction ID (integer)
  128. * b. customer_id - customer ID from payment provider (string)
  129. * c. subscription_id - subscription ID from payment provider (string)
  130. * d. paid - flag determining whether the subscription paid or not (integer)
  131. * e. date - the date when the subscription was established(UNIXTIME STAMP)
  132. * @param $bCheckInProvider boolean value determining whether the subscription should be checked in associated payment provider.
  133. * @return an array of subscriptions. Each subscription has full info(pending ID, customer ID, subscription ID and so on)
  134. *
  135. * @see BxPaymentSubscriptions::serviceGetSubscriptionsInfo
  136. */
  137. /**
  138. * @ref bx_payment-get_subscriptions_info "get_subscriptions_info"
  139. */
  140. public function serviceGetSubscriptionsInfo($aConditions, $bCheckInProvider = false)
  141. {
  142. if(empty($aConditions) || !is_array($aConditions))
  143. return array();
  144. $aSubscriptions = $this->_oModule->_oDb->getSubscription(array('type' => 'mixed_ext', 'conditions' => $aConditions));
  145. if(empty($aSubscriptions) || !is_array($aSubscriptions) || !$bCheckInProvider)
  146. return $aSubscriptions;
  147. foreach($aSubscriptions as $iKey => $aSubscription) {
  148. if(empty($aSubscription['provider']) || $aSubscription['provider'] == 'manual')
  149. continue;
  150. $oProvider = $this->_oModule->getObjectProvider($aSubscription['provider'], $aSubscription['seller_id']);
  151. if(!$oProvider)
  152. continue;
  153. $aSubscriptions[$iKey]['data'] = $oProvider->getSubscription($aSubscription['pending_id'], $aSubscription['customer_id'], $aSubscription['subscription_id']);
  154. }
  155. return $aSubscriptions;
  156. }
  157. /**
  158. * @page service Service Calls
  159. * @section bx_payment Payment
  160. * @subsection bx_payment-purchase_processing Purchase Processing
  161. * @subsubsection bx_payment-subscribe subscribe
  162. *
  163. * @code bx_srv('bx_payment', 'subscribe', [...], 'Subscriptions'); @endcode
  164. *
  165. * Initialize subscription for specified item.
  166. *
  167. * @param $iSellerId integer value with seller ID.
  168. * @param $sSellerProvider string value with a name of payment provider to be used for processing. Empty value means that payment provider selector should be shown.
  169. * @param $iModuleId integer value with module ID.
  170. * @param $iItemId integer value with item ID.
  171. * @param $iItemCount integer value with a number of items for purchasing. It's equal to 1 in case of subscription.
  172. * @param $sRedirect (optional) string value with redirect URL, if it's needed.
  173. * @return an array with special format which describes the result of operation.
  174. *
  175. * @see BxPaymentSubscriptions::serviceSubscribe
  176. */
  177. /**
  178. * @ref bx_payment-subscribe "subscribe"
  179. */
  180. public function serviceSubscribe($iSellerId, $sSellerProvider, $iModuleId, $iItemId, $iItemCount, $sRedirect = '', $aCustom = array())
  181. {
  182. return $this->serviceSubscribeWithAddons($iSellerId, $sSellerProvider, $iModuleId, $iItemId, $iItemCount, '', $sRedirect, $aCustom);
  183. }
  184. /**
  185. * @page service Service Calls
  186. * @section bx_payment Payment
  187. * @subsection bx_payment-purchase_processing Purchase Processing
  188. * @subsubsection bx_payment-subscribe_with_addons subscribe_with_addons
  189. *
  190. * @code bx_srv('bx_payment', 'subscribe_with_addons', [...], 'Subscriptions'); @endcode
  191. *
  192. * Initialize subscription for specified item.
  193. *
  194. * @param $iSellerId integer value with seller ID.
  195. * @param $sSellerProvider string value with a name of payment provider to be used for processing. Empty value means that payment provider selector should be shown.
  196. * @param $iModuleId integer value with module ID.
  197. * @param $iItemId integer value with item ID.
  198. * @param $iItemCount integer value with a number of items for purchasing. It's equal to 1 in case of subscription.
  199. * @param $sItemAddons (optional) string with attached addons.
  200. * @param $sRedirect (optional) string value with redirect URL, if it's needed.
  201. * @return an array with special format which describes the result of operation.
  202. *
  203. * @see BxPaymentSubscriptions::serviceSubscribeWithAddons
  204. */
  205. /**
  206. * @ref bx_payment-subscribe_with_addons "subscribe_with_addons"
  207. */
  208. public function serviceSubscribeWithAddons($iSellerId, $sSellerProvider, $mixedModuleId, $iItemId, $iItemCount, $sItemAddons = '', $sRedirect = '', $aCustom = array())
  209. {
  210. $CNF = &$this->_oModule->_oConfig->CNF;
  211. $iModuleId = $this->_oModule->_oConfig->getModuleId($mixedModuleId);
  212. $iClientId = $this->_oModule->getProfileId();
  213. $mixedResult = $this->_oModule->checkData($iClientId, $iSellerId, $iModuleId, $iItemId, $iItemCount);
  214. if($mixedResult !== true)
  215. return $mixedResult;
  216. $aSellerProviders = $this->_oModule->_oDb->getVendorInfoProvidersRecurring($iSellerId, true);
  217. if(empty($aSellerProviders))
  218. return array('code' => 5, 'message' => _t($CNF['T']['ERR_NOT_ACCEPT_PAYMENTS']));
  219. $aCartItem = array($iSellerId, $iModuleId, $iItemId, $iItemCount, $sItemAddons);
  220. if(empty($sSellerProvider)) {
  221. $sId = $this->_oModule->_oConfig->getHtmlIds('cart', 'providers_select') . BX_PAYMENT_TYPE_RECURRING;
  222. $sTitle = _t($CNF['T']['POPUP_PROVIDERS_SELECT']);
  223. return array('popup' => array(
  224. 'html' => BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $this->_oModule->_oTemplate->displayProvidersSelector($aCartItem, $aSellerProviders, $sRedirect, $aCustom)),
  225. 'options' => array('closeOnOuterClick' => true)
  226. ));
  227. }
  228. $aCustoms = array();
  229. $this->_oModule->_oConfig->putCustom($aCartItem, $aCustom, $aCustoms);
  230. $sCartItem = $this->_oModule->_oConfig->descriptorA2S($aCartItem);
  231. $mixedResult = $this->_oModule->serviceInitializeCheckout(BX_PAYMENT_TYPE_RECURRING, $iSellerId, $aSellerProviders[$sSellerProvider]['name'], array($sCartItem), $sRedirect, $aCustoms);
  232. if(is_string($mixedResult))
  233. return array('code' => 6, 'message' => _t($mixedResult));
  234. return $mixedResult;
  235. }
  236. public function serviceCancel($sOrder)
  237. {
  238. $aPending = $this->_oModule->_oDb->getOrderPending(['type' => 'order', 'order' => $sOrder]);
  239. if(empty($aPending) || !is_array($aPending))
  240. return ['code' => 1, 'message' => _t('_bx_payment_err_not_found_pending')];
  241. if(!$this->cancel((int)$aPending['id']))
  242. return ['code' => 2, 'message' => _t('_bx_payment_err_cannot_perform')];
  243. return ['code' => 0, 'message' => _t('_bx_payment_msg_successfully_performed')];
  244. }
  245. /**
  246. * @page service Service Calls
  247. * @section bx_payment Payment
  248. * @subsection bx_payment-purchase_processing Purchase Processing
  249. * @subsubsection bx_payment-send_subscription_expiration_letters send_subscription_expiration_letters
  250. *
  251. * @code bx_srv('bx_payment', 'send_subscription_expiration_letters', [...], 'Subscriptions'); @endcode
  252. *
  253. * Send subscription expiration letters.
  254. *
  255. * @param $iPendingId integer value with pending transaction ID.
  256. * @param $sOrderId string value with order ID.
  257. *
  258. * @see BxPaymentSubscriptions::serviceSendSubscriptionExpirationLetters
  259. */
  260. /**
  261. * @ref bx_payment-send_subscription_expiration_letters "send_subscription_expiration_letters"
  262. */
  263. public function serviceSendSubscriptionExpirationLetters($iPendingId, $sOrderId)
  264. {
  265. $CNF = &$this->_oModule->_oConfig->CNF;
  266. $sPrefix = $this->_oModule->_oConfig->getPrefix('general');
  267. $aSubscription = $this->serviceGetSubscriptionsInfo(array('subscription_id' => $sOrderId));
  268. if(empty($aSubscription) || !is_array($aSubscription))
  269. return;
  270. $aSubscription = array_shift($aSubscription);
  271. $oSeller = BxDolProfile::getInstance((int)$aSubscription['seller_id']);
  272. $oClient = BxDolProfile::getInstance((int)$aSubscription['client_id']);
  273. $aEtParams = array(
  274. 'subscription_id' => $aSubscription['subscription_id'],
  275. 'subscription_customer' => $aSubscription['customer_id'],
  276. 'subscription_date' => bx_time_js($aSubscription['date_add'], BX_FORMAT_DATE, true)
  277. );
  278. /**
  279. * Notify seller.
  280. */
  281. if($oSeller !== false) {
  282. $sEmail = '';
  283. $oProvider = $this->_oModule->getObjectProvider($aSubscription['provider'], $aSubscription['seller_id']);
  284. if($oProvider !== false && $oProvider->isActive())
  285. $sEmail = $oProvider->getOption('expiration_email');
  286. if(empty($sEmail))
  287. $sEmail = $oSeller->getAccountObject()->getEmail();
  288. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($sPrefix . 'expiration_notification_seller', $aEtParams, 0, (int)$aSubscription['client_id']);
  289. sendMail($sEmail, $aTemplate['Subject'], $aTemplate['Body'], 0, array(), BX_EMAIL_SYSTEM);
  290. }
  291. /**
  292. * Notify client.
  293. */
  294. if($oClient !== false) {
  295. $sEmail = $oClient->getAccountObject()->getEmail();
  296. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($sPrefix . 'expiration_notification_client', $aEtParams, 0, (int)$aSubscription['seller_id']);
  297. sendMail($sEmail, $aTemplate['Subject'], $aTemplate['Body'], 0, array(), BX_EMAIL_SYSTEM);
  298. }
  299. }
  300. public function register($aPending, $aParams = array())
  301. {
  302. if($this->_oModule->_oDb->isSubscriptionByPending($aPending['id']) || empty($aPending['items']))
  303. return false;
  304. $aInfo = $this->_oModule->getObjectCart()->getInfo(BX_PAYMENT_TYPE_RECURRING, $aPending['client_id'], $aPending['seller_id'], $aPending['items']);
  305. if(empty($aInfo['items']) || !is_array($aInfo['items']))
  306. return false;
  307. $aItem = array_shift($aInfo['items']);
  308. $iPeriod = (int)$aItem['period_recurring'];
  309. $iTrial = (int)$aItem['trial_recurring'];
  310. $oDate = date_create();
  311. $iNow = $iNext = date_format($oDate, 'U');
  312. if((!empty($aParams['status']) && $aParams['status'] == BX_PAYMENT_SBS_STATUS_ACTIVE) || $iTrial > 0) {
  313. $sInterval = $this->_getInterval($iPeriod, $aItem['period_unit_recurring'], $iTrial);
  314. date_add($oDate, new DateInterval($sInterval));
  315. $iNext = date_format($oDate, 'U');
  316. }
  317. $sUnique = genRndPwd(9, false);
  318. $aSubscription = array(
  319. 'pending_id' => $aPending['id'],
  320. 'customer_id' => !empty($aParams['customer_id']) ? $aParams['customer_id'] : 'bx_cus_' . $sUnique,
  321. 'subscription_id' => !empty($aParams['subscription_id']) ? $aParams['subscription_id'] : 'bx_sub_' . $sUnique,
  322. 'period' => $iPeriod,
  323. 'period_unit' => $aItem['period_unit_recurring'],
  324. 'trial' => $iTrial,
  325. 'date_add' => $iNow,
  326. 'date_next' => $iNext,
  327. 'status' => !empty($aParams['status']) ? $aParams['status'] : ($iTrial > 0 ? BX_PAYMENT_SBS_STATUS_TRIAL : BX_PAYMENT_SBS_STATUS_UNPAID)
  328. );
  329. if(!$this->_oModule->_oDb->insertSubscription($aSubscription))
  330. return false;
  331. $this->_oModule->onSubscriptionCreate($aPending, $aSubscription);
  332. return true;
  333. }
  334. public function prolong($aPending, $aParams = array())
  335. {
  336. if(empty($aPending['items']))
  337. return false;
  338. $aSubscription = $this->_oModule->_oDb->getSubscription(array('type' => 'pending_id', 'pending_id' => $aPending['id']));
  339. if(empty($aSubscription) || !is_array($aSubscription))
  340. return false;
  341. $aInfo = $this->_oModule->getObjectCart()->getInfo(BX_PAYMENT_TYPE_RECURRING, $aPending['client_id'], $aPending['seller_id'], $aPending['items']);
  342. if(empty($aInfo['items']) || !is_array($aInfo['items']))
  343. return false;
  344. $aItem = array_shift($aInfo['items']);
  345. $iItemPeriod = (int)$aItem['period_recurring'];
  346. $sItemPeriodUnit = $aItem['period_unit_recurring'];
  347. $iDateNext = 0;
  348. if(!empty($iItemPeriod) && !empty($sItemPeriodUnit)) {
  349. $sInterval = $this->_getInterval($iItemPeriod, $sItemPeriodUnit);
  350. if(empty($sInterval))
  351. return false;
  352. $oDate = date_create('@' . $aSubscription['date_next']);
  353. date_add($oDate, new DateInterval($sInterval));
  354. $iDateNext = date_format($oDate, 'U');
  355. }
  356. $this->_oModule->_oDb->updateSubscription(array_merge(array(
  357. 'date_next' => $iDateNext,
  358. 'pay_attempts' => 0,
  359. 'status' => BX_PAYMENT_SBS_STATUS_ACTIVE
  360. ), $aParams), array(
  361. 'id' => $aSubscription['id']
  362. ));
  363. $this->_oModule->onSubscriptionProlong($aPending, $aSubscription);
  364. return true;
  365. }
  366. public function overdue($aPending, $aParams = array())
  367. {
  368. $aSubscription = $this->_oModule->_oDb->getSubscription(array('type' => 'pending_id', 'pending_id' => $aPending['id']));
  369. if(empty($aSubscription) || !is_array($aSubscription))
  370. return false;
  371. $this->_oModule->_oDb->updateSubscription(array_merge(array(
  372. 'status' => BX_PAYMENT_SBS_STATUS_UNPAID
  373. ), $aParams), array(
  374. 'id' => $aSubscription['id']
  375. ));
  376. $this->_oModule->onSubscriptionOverdue($aPending, $aSubscription);
  377. return true;
  378. }
  379. public function cancel($iPendingId)
  380. {
  381. if(!$this->cancelRemote($iPendingId))
  382. return false;
  383. if(!$this->cancelLocal($iPendingId))
  384. return false;
  385. return true;
  386. }
  387. public function cancelRemote($mixedPending)
  388. {
  389. $aPending = is_array($mixedPending) ? $mixedPending : $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$mixedPending));
  390. if(empty($aPending) || !is_array($aPending) || $aPending['type'] != BX_PAYMENT_TYPE_RECURRING)
  391. return false;
  392. $aSubscription = $this->_oModule->_oDb->getSubscription(array('type' => 'pending_id', 'pending_id' => $aPending['id']));
  393. if(empty($aSubscription) || !is_array($aSubscription))
  394. return false;
  395. $iSellerId = (int)$aPending['seller_id'];
  396. $oProvider = $this->_oModule->getObjectProvider($aPending['provider'], $iSellerId);
  397. if($oProvider === false || !$oProvider->isActive())
  398. return false;
  399. if(!$oProvider->cancelRecurring($aPending['id'], $aSubscription['customer_id'], $aSubscription['subscription_id']))
  400. return false;
  401. return true;
  402. }
  403. public function cancelLocal($mixedPending)
  404. {
  405. $aPending = is_array($mixedPending) ? $mixedPending : $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$mixedPending));
  406. if(empty($aPending) || !is_array($aPending) || $aPending['type'] != BX_PAYMENT_TYPE_RECURRING)
  407. return false;
  408. $aSubscription = $this->_oModule->_oDb->getSubscription(array('type' => 'pending_id', 'pending_id' => $aPending['id']));
  409. if(empty($aSubscription) || !is_array($aSubscription))
  410. return false;
  411. $aItems = $this->_oModule->_oConfig->descriptorsM2A($aPending['items']);
  412. foreach($aItems as $aItem)
  413. $this->_oModule->callCancelSubscriptionItem((int)$aItem['module_id'], array($aPending['client_id'], $aPending['seller_id'], $aItem['item_id'], $aItem['item_count'], $aPending['order']));
  414. if(!$this->_oModule->_oDb->deleteSubscription($aSubscription['id'], 'cancel'))
  415. return false;
  416. $this->_oModule->onSubscriptionCancel($aPending, $aSubscription);
  417. return true;
  418. }
  419. protected function _getBlock($sType)
  420. {
  421. $CNF = &$this->_oModule->_oConfig->CNF;
  422. $sMethod = 'displayBlockSbs' . bx_gen_method_name($sType);
  423. if(!$this->_oModule->_oTemplate->isMethodExists($sMethod))
  424. return $this->_bIsApi ? [] : [
  425. 'content' => MsgBox(_t('_Empty'))
  426. ];
  427. $iUserId = $this->_oModule->getProfileId();
  428. if(empty($iUserId))
  429. return $this->_bIsApi ? [] : [
  430. 'content' => MsgBox(_t($CNF['T']['ERR_REQUIRED_LOGIN']))
  431. ];
  432. $mixedBlockContent = $this->_oModule->_oTemplate->$sMethod($iUserId);
  433. if($this->_bIsApi)
  434. return !$mixedBlockContent ? [] : [
  435. bx_api_get_block('subscriptions_' . $sType, $mixedBlockContent)
  436. ];
  437. $this->_oModule->setSiteSubmenu('menu_dashboard', 'system', 'dashboard-subscriptions');
  438. $sBlockSubmenu = $this->_oModule->_oConfig->getObject('menu_sbs_submenu');
  439. $oBlockSubmenu = BxDolMenu::getObjectInstance($sBlockSubmenu);
  440. if($oBlockSubmenu)
  441. $oBlockSubmenu->setSelected($this->MODULE, 'sbs-' . str_replace('_', '-', $sType));
  442. return [
  443. 'content' => $mixedBlockContent,
  444. 'menu' => $this->_oModule->_oConfig->getObject('menu_sbs_submenu')
  445. ];
  446. }
  447. private function _getInterval($iPeriod, $sPeriodUnit, $iTrial = 0)
  448. {
  449. if((int)$iTrial > 0)
  450. return 'P' . $iTrial . 'D';
  451. $sInterval = '';
  452. switch($sPeriodUnit) {
  453. case BX_PAYMENT_SBS_PU_YEAR:
  454. $sInterval = 'P' . $iPeriod . 'Y';
  455. break;
  456. case BX_PAYMENT_SBS_PU_MONTH:
  457. $sInterval = 'P' . $iPeriod . 'M';
  458. break;
  459. case BX_PAYMENT_SBS_PU_WEEK:
  460. $sInterval = 'P' . (7 * $iPeriod) . 'D';
  461. break;
  462. case BX_PAYMENT_SBS_PU_DAY:
  463. $sInterval = 'P' . $iPeriod . 'D';
  464. break;
  465. case BX_PAYMENT_SBS_PU_HOUR:
  466. $sInterval = 'PT' . $iPeriod . 'H';
  467. break;
  468. case BX_PAYMENT_SBS_PU_MINUTE:
  469. $sInterval = 'PT' . $iPeriod . 'I';
  470. break;
  471. }
  472. return $sInterval;
  473. }
  474. }
  475. /** @} */