BxPaymentTemplate.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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 BxPaymentTemplate extends BxBaseModPaymentTemplate
  12. {
  13. protected $_sLangsPrefix;
  14. function __construct(&$oConfig, &$oDb)
  15. {
  16. $this->MODULE = 'bx_payment';
  17. parent::__construct($oConfig, $oDb);
  18. $this->_sLangsPrefix = $this->_oConfig->getPrefix('langs');
  19. }
  20. public function addJsCssOrders()
  21. {
  22. $this->addJs(array(
  23. 'jquery-ui/jquery-ui.min.js',
  24. 'jquery.form.min.js',
  25. 'jquery.anim.js',
  26. 'jquery.webForms.js',
  27. 'orders.js'
  28. ));
  29. $this->addCss(array('orders.css'));
  30. }
  31. public function addJsCssSubscriptions()
  32. {
  33. $this->addJs(array('jquery.form.min.js', 'jquery.anim.js', 'jquery.webForms.js', 'main.js', 'subscriptions.js'));
  34. $this->addCss(array('orders.css', 'subscriptions.css'));
  35. }
  36. public function addJsCssCart($sType = '', $iVendorId = 0)
  37. {
  38. $this->addJsTranslation(array('_bx_payment_err_nothing_selected'));
  39. $this->addJs(array('jquery.anim.js', 'main.js', 'cart.js'));
  40. $this->addCss(array('orders.css', 'cart.css'));
  41. $oModule = $this->getModule();
  42. if(!empty($iVendorId)) {
  43. $sMethod = 'getVendorInfoProviders' . bx_gen_method_name($sType);
  44. $aProviders = $this->_oDb->$sMethod($iVendorId);
  45. foreach($aProviders as $sProvider => $aProvider)
  46. $oModule->getObjectProvider($sProvider, $iVendorId)->addJsCss();
  47. }
  48. }
  49. public function addJsCssInvoices()
  50. {
  51. $this->addCss(array('invoices.css'));
  52. }
  53. public function displayBlockCheckoutOffline($oBuyer, $oSeller, $aData)
  54. {
  55. $CNF = &$this->_oConfig->CNF;
  56. $sTxtQt = _t('_bx_payment_txt_checkout_qt');
  57. $aTmplVarsItems = array();
  58. foreach($aData['items'] as $iIndex => $aItem)
  59. $aTmplVarsItems[] = array(
  60. 'item_index' => $iIndex + 1,
  61. 'item_title' => $aItem['title'],
  62. 'item_quantity' => $aItem['quantity'] . $sTxtQt
  63. );
  64. $this->addCss(array('checkout.css'));
  65. return $this->parseHtmlByName('checkout_offline.html', array(
  66. 'message' => _t('_bx_payment_txt_checkout_for', $oSeller->getDisplayName()),
  67. 'bx_repeat:items' => $aTmplVarsItems,
  68. 'amount' => $aData['currency']['sign'] . sprintf("%.2f", (float)($aData['amount'])),
  69. 'redirect_url' => $aData['return_url']
  70. ));
  71. }
  72. public function displayCartJs($sType = '', $iVendorId = 0)
  73. {
  74. $this->addJsCssCart($sType, $iVendorId);
  75. return $this->displayJsCode('cart');
  76. }
  77. public function displayAddToCartJs($iVendorId, $iModuleId, $iItemId, $iItemCount, $bNeedRedirect = false, $aCustom = array())
  78. {
  79. $sJsCode = $this->displayCartJs(BX_PAYMENT_TYPE_SINGLE, $iVendorId);
  80. $sJsMethod = $this->parseHtmlByName('add_to_cart_js.html', array(
  81. 'js_object' => $this->_oConfig->getJsObject('cart'),
  82. 'vendor_id' => $iVendorId,
  83. 'module_id' => $iModuleId,
  84. 'item_id' => $iItemId,
  85. 'item_count' => $iItemCount,
  86. 'need_redirect' => (int)$bNeedRedirect,
  87. 'custom' => !empty($aCustom) && is_array($aCustom) ? base64_encode(json_encode($aCustom)) : ''
  88. ));
  89. return array($sJsCode, $sJsMethod);
  90. }
  91. public function displayAddToCartLink($iVendorId, $iModuleId, $iItemId, $iItemCount, $bNeedRedirect = false, $aCustom = array())
  92. {
  93. $this->addJsCssCart(BX_PAYMENT_TYPE_SINGLE, $iVendorId);
  94. return $this->parseHtmlByName('add_to_cart.html', array(
  95. 'js_object' => $this->_oConfig->getJsObject('cart'),
  96. 'js_content' => $this->displayJsCode('cart'),
  97. 'txt_add_to_cart' => _t($this->_sLangsPrefix . 'txt_add_to_cart'),
  98. 'vendor_id' => $iVendorId,
  99. 'module_id' => $iModuleId,
  100. 'item_id' => $iItemId,
  101. 'item_count' => $iItemCount,
  102. 'need_redirect' => (int)$bNeedRedirect,
  103. 'custom' => !empty($aCustom) && is_array($aCustom) ? base64_encode(json_encode($aCustom)) : ''
  104. ));
  105. }
  106. public function displaySubscribeJs($iVendorId, $sVendorProvider, $iModuleId, $iItemId, $iItemCount = 1, $sRedirect = '', $aCustom = array())
  107. {
  108. return $this->displaySubscribeJsWithAddons($iVendorId, $sVendorProvider, $iModuleId, $iItemId, $iItemCount, '', $sRedirect, $aCustom);
  109. }
  110. public function displaySubscribeJsWithAddons($iVendorId, $sVendorProvider, $iModuleId, $iItemId, $iItemCount = 1, $sItemAddons = '', $sRedirect = '', $aCustom = array())
  111. {
  112. $aSellerProviders = $this->_oDb->getVendorInfoProvidersRecurring($iVendorId);
  113. if(empty($sVendorProvider) && count($aSellerProviders) == 1) {
  114. $aCartItem = array($iVendorId, $iModuleId, $iItemId, $iItemCount, $sItemAddons);
  115. $this->addJsCssCart(BX_PAYMENT_TYPE_RECURRING, $iVendorId);
  116. return $this->getModule()->getProviderButtonJs($aCartItem, array_shift($aSellerProviders), $sRedirect, $aCustom);
  117. }
  118. return array(
  119. $this->displayCartJs(BX_PAYMENT_TYPE_RECURRING, $iVendorId),
  120. $this->parseHtmlByName('subscribe_js.html', array(
  121. 'js_object' => $this->_oConfig->getJsObject('cart'),
  122. 'vendor_id' => $iVendorId,
  123. 'vendor_provider' => $sVendorProvider,
  124. 'module_id' => $iModuleId,
  125. 'item_id' => $iItemId,
  126. 'item_count' => $iItemCount,
  127. 'redirect' => !empty($sRedirect) ? $sRedirect : '',
  128. 'custom' => !empty($aCustom) && is_array($aCustom) ? base64_encode(json_encode($aCustom)) : ''
  129. ))
  130. );
  131. }
  132. public function displaySubscribeLink($iVendorId, $sVendorProvider, $iModuleId, $iItemId, $iItemCount = 1, $sRedirect = '', $aCustom = array())
  133. {
  134. $this->addJsCssCart(BX_PAYMENT_TYPE_RECURRING, $iVendorId);
  135. return $this->parseHtmlByName('subscribe.html', array(
  136. 'js_object' => $this->_oConfig->getJsObject('cart'),
  137. 'js_content' => $this->displayJsCode('cart'),
  138. 'txt_add_to_cart' => _t($this->_sLangsPrefix . 'txt_subscribe'),
  139. 'vendor_id' => $iVendorId,
  140. 'vendor_provider' => $sVendorProvider,
  141. 'module_id' => $iModuleId,
  142. 'item_id' => $iItemId,
  143. 'item_count' => $iItemCount,
  144. 'redirect' => !empty($sRedirect) ? $sRedirect : '',
  145. 'custom' => !empty($aCustom) && is_array($aCustom) ? base64_encode(json_encode($aCustom)) : ''
  146. ));
  147. }
  148. public function displaySubscriptionGetDetails($iId)
  149. {
  150. return $this->_displaySubscriptionData('get_details', $iId);
  151. }
  152. public function displaySubscriptionChangeDetails($iId)
  153. {
  154. return $this->_displaySubscriptionData('change_details', $iId);
  155. }
  156. public function displaySubscriptionGetBilling($iId)
  157. {
  158. return $this->_displaySubscriptionData('get_billing', $iId);
  159. }
  160. public function displaySubscriptionChangeBilling($iId)
  161. {
  162. return $this->_displaySubscriptionData('change_billing', $iId);
  163. }
  164. public function displayBlockCarts($iClientId)
  165. {
  166. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getObject('grid_carts'));
  167. if(!$oGrid)
  168. return MsgBox(_t($this->_sLangsPrefix . 'msg_no_results'));
  169. $oGrid->addQueryParam('client_id', $iClientId);
  170. if($this->_bIsApi)
  171. return $oGrid->getCodeAPI();
  172. $this->addJsCssCart(BX_PAYMENT_TYPE_SINGLE);
  173. return $this->displayJsCode('cart') . $oGrid->getCode();
  174. }
  175. public function displayBlockCart($iClientId, $iSellerId = 0)
  176. {
  177. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getObject('grid_cart'));
  178. if(!$oGrid || empty($iSellerId))
  179. return MsgBox(_t($this->_sLangsPrefix . 'msg_no_results'));
  180. $oGrid->addQueryParam('client_id', $iClientId);
  181. $oGrid->addQueryParam('seller_id', $iSellerId);
  182. if($this->_bIsApi)
  183. return $oGrid->getCodeAPI();
  184. $this->addJsCssCart(BX_PAYMENT_TYPE_SINGLE, $iSellerId);
  185. return $this->displayJsCode('cart') . $oGrid->getCode();
  186. }
  187. public function displayBlockHistory($iClientId, $iSellerId)
  188. {
  189. return $this->_displayBlockHistory('grid_history', $iClientId, $iSellerId);
  190. }
  191. public function displayBlockSbsListMy($iClientId)
  192. {
  193. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getObject('grid_sbs_list_my'), $this->getModule()->_oTemplate);
  194. if(!$oGrid || empty($iClientId))
  195. return $this->_bIsApi ? false : MsgBox(_t($this->_sLangsPrefix . 'msg_no_results'));
  196. $oGrid->addQueryParam('client_id', $iClientId);
  197. if($this->_bIsApi)
  198. return $oGrid->getCodeAPI(true);
  199. $this->addJsCssSubscriptions();
  200. return $this->displayJsCode(BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION) . $oGrid->getCode();
  201. }
  202. public function displayBlockSbsListAll()
  203. {
  204. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getObject('grid_sbs_list_all'), $this->getModule()->_oTemplate);
  205. if(!$oGrid)
  206. return $this->_bIsApi ? false : MsgBox(_t($this->_sLangsPrefix . 'msg_no_results'));
  207. if($this->_bIsApi)
  208. return $oGrid->getCodeAPI(true);
  209. $this->addJsCssSubscriptions();
  210. return $this->displayJsCode(BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION) . $oGrid->getCode();
  211. }
  212. public function displayBlockSbsHistory($iClientId)
  213. {
  214. return $this->_displayBlockHistory('grid_sbs_history', $iClientId);
  215. }
  216. public function displayBlockSbsDetails($iClientId)
  217. {
  218. return 'Details would be here';
  219. }
  220. public function displayBlockOrders($sType, $iSellerId)
  221. {
  222. $sGrid = $this->_oConfig->getObject('grid_' . $sType);
  223. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  224. if(!$oGrid || empty($iSellerId))
  225. return '';
  226. $oGrid->addQueryParam('seller_id', $iSellerId);
  227. if($this->_bIsApi)
  228. return $oGrid->getCodeAPI();
  229. $this->addJsCssOrders();
  230. return $this->displayJsCode($sType, [
  231. 'sObjNameGrid' => $sGrid,
  232. 'sParamsDivider' => $this->_oConfig->getDivider('DIVIDER_GRID_FILTERS'),
  233. 'sTextSearchInput' => _t('_sys_grid_search')
  234. ]) . $oGrid->getCode();
  235. }
  236. public function displayOrder($sType, $iId)
  237. {
  238. $sMethodName = 'getOrder' . bx_gen_method_name($sType);
  239. $aOrder = $this->_oDb->$sMethodName(array('type' => 'id', 'id' => $iId));
  240. if($this->_bIsApi)
  241. return $this->displayOrderAPI($sType, $aOrder);
  242. $oModule = $this->getModule();
  243. $aSeller = $oModule->getVendorInfo((int)$aOrder['seller_id']);
  244. $aClient = $oModule->getProfileInfo((int)$aOrder['client_id']);
  245. if(in_array($sType, [BX_PAYMENT_ORDERS_TYPE_PENDING, BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION]))
  246. $aItems = $this->_oConfig->descriptorsM2A($aOrder['items']);
  247. else
  248. $aItems = $this->_oConfig->descriptorsM2A($this->_oConfig->descriptorA2S([$aOrder['seller_id'], $aOrder['module_id'], $aOrder['item_id'], $aOrder['item_count']]));
  249. $aTmplVarsLicense = array();
  250. if(in_array($sType, array(BX_PAYMENT_ORDERS_TYPE_PROCESSED, BX_PAYMENT_ORDERS_TYPE_HISTORY)))
  251. $aTmplVarsLicense = array(
  252. 'txt_license' => _t($this->_sLangsPrefix . 'txt_license'),
  253. 'license' => $aOrder['license']
  254. );
  255. $bTmplVarsShowSlrAtr = !empty($aOrder['author_id']) && $aOrder['seller_id'] != $aOrder['author_id'];
  256. $aTmplVarsAuthor = array();
  257. if($bTmplVarsShowSlrAtr) {
  258. $aAuthor = $oModule->getProfileInfo((int)$aOrder['author_id']);
  259. $aTmplVarsAuthor = array(
  260. 'txt_author' => _t($this->_sLangsPrefix . 'txt_author'),
  261. 'author_name' => $aAuthor['name'],
  262. 'author_url' => $aAuthor['link'],
  263. );
  264. }
  265. $aTmplVarsSeller = array(
  266. 'txt_seller' => _t($this->_sLangsPrefix . 'txt_seller'),
  267. 'bx_if:show_link' => array(
  268. 'condition' => !empty($aSeller['link']),
  269. 'content' => array(
  270. 'seller_name' => $aSeller['name'],
  271. 'seller_url' => $aSeller['link'],
  272. )
  273. ),
  274. 'bx_if:show_text' => array(
  275. 'condition' => empty($aSeller['link']),
  276. 'content' => array(
  277. 'seller_name' => $aSeller['name']
  278. )
  279. ),
  280. );
  281. $aTmplVarsCustom = [];
  282. if(in_array($sType, [BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION])) {
  283. $sOrder = $aOrder['order'];
  284. if($oModule->_isModerator() && ($aItem = reset($aItems))) {
  285. $aItemModule = bx_srv((int)$aItem['module_id'], 'get_payment_data');
  286. if(($sUrlBrowse = $aItemModule['url_browse_order_administration'] ?? false))
  287. $sOrder = $this->displayLink('link', [
  288. 'href' => bx_replace_markers($sUrlBrowse, [
  289. 'order' => $sOrder
  290. ]),
  291. 'title' => bx_html_attribute($sOrder),
  292. 'content' => $sOrder
  293. ]);
  294. }
  295. $aTmplVarsCustom = [
  296. 'txt_order' => _t($this->_sLangsPrefix . 'txt_subscription'),
  297. 'order' => $sOrder,
  298. 'txt_customer_id' => _t($this->_sLangsPrefix . 'txt_customer_id'),
  299. 'customer_id' => $aOrder['customer_id'] ?? '',
  300. 'bx_if:show_deleted' => [
  301. 'condition' => false,
  302. 'content' => [
  303. 'txt_deleted' => _t($this->_sLangsPrefix . 'txt_deleted'),
  304. 'txt_deleted_reason' => _t($this->_sLangsPrefix . 'txt_deleted_reason'),
  305. 'deleted' => 0,
  306. 'deleted_reason' => ''
  307. ]
  308. ]
  309. ];
  310. if(($sK = 'deleted') && isset($aOrder[$sK]) && $aOrder[$sK]) {
  311. $aTmplVarsCustom['bx_if:show_deleted']['condition'] = true;
  312. $aTmplVarsCustom['bx_if:show_deleted']['content'] = array_merge($aTmplVarsCustom['bx_if:show_deleted']['content'], [
  313. 'deleted' => bx_time_js($aOrder[$sK], BX_FORMAT_DATE_TIME, true),
  314. 'deleted_reason' => $aOrder['deleted_reason'] ?? ''
  315. ]);
  316. }
  317. }
  318. $aResult = array_merge(array(
  319. 'txt_client' => _t($this->_sLangsPrefix . 'txt_client'),
  320. 'txt_order' => _t($this->_sLangsPrefix . 'txt_order'),
  321. 'txt_processed_with' => _t($this->_sLangsPrefix . 'txt_processed_with'),
  322. 'txt_message' => _t($this->_sLangsPrefix . 'txt_message'),
  323. 'txt_date' => _t($this->_sLangsPrefix . 'txt_date'),
  324. 'txt_products' => _t($this->_sLangsPrefix . 'txt_products'),
  325. 'client_name' => $aClient['name'],
  326. 'client_url' => $aClient['link'],
  327. 'bx_if:show_seller' => array(
  328. 'condition' => $bTmplVarsShowSlrAtr,
  329. 'content' => $aTmplVarsSeller
  330. ),
  331. 'bx_if:show_license' => array(
  332. 'condition' => !empty($aTmplVarsLicense),
  333. 'content' => $aTmplVarsLicense
  334. ),
  335. 'order' => $aOrder['order'],
  336. 'provider' => _t('_bx_payment_txt_name_' . $aOrder['provider']),
  337. 'error' => $aOrder['error_msg'],
  338. 'date' => bx_time_js($aOrder['date'], BX_FORMAT_DATE_TIME, true),
  339. 'bx_if:show_author' => array(
  340. 'condition' => $bTmplVarsShowSlrAtr,
  341. 'content' => $aTmplVarsAuthor
  342. ),
  343. 'bx_repeat:items' => array()
  344. ), $aTmplVarsSeller, $aTmplVarsCustom);
  345. foreach($aItems as $aItem) {
  346. $aInfo = $oModule->callGetCartItem((int)$aItem['module_id'], array($aItem['item_id'], $aOrder['client_id']));
  347. if(!empty($aInfo) && is_array($aInfo))
  348. $aResult['bx_repeat:items'][] = array(
  349. 'bx_if:link' => array(
  350. 'condition' => !empty($aInfo['url']),
  351. 'content' => array(
  352. 'title' => $aInfo['title'],
  353. 'url' => $aInfo['url']
  354. )
  355. ),
  356. 'bx_if:text' => array(
  357. 'condition' => empty($aInfo['url']),
  358. 'content' => array(
  359. 'title' => $aInfo['title'],
  360. )
  361. ),
  362. 'quantity' => $aItem['item_count'],
  363. 'price' => $this->_oConfig->getPrice($aOrder['type'], $aInfo),
  364. 'currency_code' => $aSeller['currency_code']
  365. );
  366. }
  367. return $this->parseHtmlByName('order_' . $sType . '.html', $aResult);
  368. }
  369. public function displayOrderAPI($sType, $aOrder)
  370. {
  371. $oModule = $this->getModule();
  372. $aSeller = $oModule->getVendorInfo((int)$aOrder['seller_id']);
  373. $bSubscription = in_array($sType, [BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION]);
  374. $aResult = [
  375. [_t($this->_sLangsPrefix . 'txt_seller'), $aSeller['name']],
  376. [_t($this->_sLangsPrefix . 'txt_' . ($bSubscription ? 'subscription' : 'order')), $aOrder['order']],
  377. ];
  378. if($bSubscription)
  379. $aResult[] = [_t($this->_sLangsPrefix . 'txt_customer_id'), $aOrder['customer_id']];
  380. if(in_array($sType, [BX_PAYMENT_ORDERS_TYPE_PROCESSED, BX_PAYMENT_ORDERS_TYPE_HISTORY]))
  381. $aResult[] = [_t($this->_sLangsPrefix . 'txt_license'), $aOrder['license']];
  382. $aResult[] = [_t($this->_sLangsPrefix . 'txt_date'), $aOrder['date']];
  383. if(in_array($sType, [BX_PAYMENT_ORDERS_TYPE_PENDING, BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION]))
  384. $aItems = $this->_oConfig->descriptorsM2A($aOrder['items']);
  385. else
  386. $aItems = $this->_oConfig->descriptorsM2A($this->_oConfig->descriptorA2S(array($aOrder['seller_id'], $aOrder['module_id'], $aOrder['item_id'], $aOrder['item_count'])));
  387. $sProducts = '';
  388. foreach($aItems as $aItem) {
  389. $aInfo = $oModule->callGetCartItem((int)$aItem['module_id'], array($aItem['item_id'], $aOrder['client_id']));
  390. if(empty($aInfo) || !is_array($aInfo))
  391. continue;
  392. $sProducts .= $aInfo['title'] . ' (' . $aItem['item_count'] . ') - ' . $this->_oConfig->getPrice($aOrder['type'], $aInfo) . $aSeller['currency_code'] . ', ';
  393. }
  394. $aResult[] = [_t($this->_sLangsPrefix . 'txt_products'), trim($sProducts, ", ")];
  395. return $aResult;
  396. }
  397. public function displayBlockInvoices()
  398. {
  399. $sGrid = $this->_oConfig->getObject('grid_invoices');
  400. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  401. if(!$oGrid)
  402. return MsgBox(_t($this->_sLangsPrefix . 'msg_no_results'));
  403. $this->addJsCssInvoices();
  404. return $oGrid->getCode();
  405. }
  406. public function displayItems($iSellerId, $sType, $aItems = [], $aParams = [])
  407. {
  408. $oModule = $this->getModule();
  409. $oForm = new BxTemplFormView([]);
  410. $sSign = !$this->_oConfig->isSingleSeller() ? $oModule->getVendorCurrencySign($iSellerId) : $this->_oConfig->getDefaultCurrencySign();
  411. $bFilter = !empty($aParams['filter']);
  412. $sFilter = $bFilter ? $aParams['filter'] : '';
  413. $aTmplVarsItems = [];
  414. if(!empty($aItems) && is_array($aItems))
  415. foreach($aItems as $aItem) {
  416. if($bFilter && stripos($aItem['title'], $sFilter) === false)
  417. continue;
  418. $fPrice = $this->_oConfig->getPrice($sType, $aItem);
  419. $aInputCheckbox = array(
  420. 'type' => 'checkbox',
  421. 'name' => 'items[]',
  422. 'value' => $aItem['id']
  423. );
  424. $aInputPrice = array(
  425. 'type' => 'text',
  426. 'name' => 'item-price-' . $aItem['id'],
  427. 'value' => $fPrice
  428. );
  429. $aInputQuantity = array(
  430. 'type' => 'text',
  431. 'name' => 'item-quantity-' . $aItem['id'],
  432. 'value' => 1
  433. );
  434. $aTmplVarsItems[$aItem['name']] = array(
  435. 'id' => $aItem['id'],
  436. 'price' => $fPrice,
  437. 'price_f' => _t_format_currency_ext($fPrice, ['sign' => $sSign]),
  438. 'bx_if:link' => array(
  439. 'condition' => !empty($aItem['url']),
  440. 'content' => array(
  441. 'url' => $aItem['url'],
  442. 'title' => $aItem['title']
  443. )
  444. ),
  445. 'bx_if:text' => array(
  446. 'condition' => empty($aItem['url']),
  447. 'content' => array(
  448. 'title' => $aItem['title']
  449. )
  450. ),
  451. 'input_checkbox' => $oForm->genInput($aInputCheckbox),
  452. 'input_price' => $oForm->genInput($aInputPrice),
  453. 'input_quantity' => $oForm->genInput($aInputQuantity),
  454. );
  455. }
  456. $bTmplVarsItems = !empty($aTmplVarsItems) && is_array($aTmplVarsItems);
  457. if($bTmplVarsItems) {
  458. ksort($aTmplVarsItems);
  459. $aTmplVarsItems = array_values($aTmplVarsItems);
  460. }
  461. else
  462. $aTmplVarsItems = MsgBox(_t($this->_sLangsPrefix . 'msg_no_results'));
  463. $sInputFilter = '';
  464. if($bFilter || $bTmplVarsItems) {
  465. $sJsMethod = 'javascript:' . $this->_oModule->_oConfig->getJsObject('processed') . '.filterItems(event, this);';
  466. $aInputFilter = [
  467. 'type' => 'text',
  468. 'name' => 'filter',
  469. 'value' => $sFilter,
  470. 'attrs' => [
  471. 'placeholder' => _t('_sys_search_placeholder'),
  472. 'onkeydown' => $sJsMethod,
  473. 'onpaste' => $sJsMethod
  474. ]
  475. ];
  476. $sInputFilter = $oForm->genInput($aInputFilter);
  477. }
  478. return $this->parseHtmlByName('items.html', array(
  479. 'html_id' => $this->_oConfig->getHtmlIds('processed', 'order_processed_items'),
  480. 'input_filter' => $sInputFilter,
  481. 'bx_repeat:items' => $aTmplVarsItems
  482. ));
  483. }
  484. public function displayProvidersSelector($aCartItem, $aProviders, $sRedirect = '', $aCustom = array())
  485. {
  486. $oModule = $this->getModule();
  487. $aTmplVarsProviders = array();
  488. foreach($aProviders as $sProvider => $aProvider) {
  489. list($sJsCode, $sJsOnclick) = $oModule->getProviderButtonJs($aCartItem, $aProvider, $sRedirect, $aCustom);
  490. $sCaptionKey = '_bx_payment_txt_subscribe_' . $aProvider['name'];
  491. $sCaptionValue = _t($sCaptionKey);
  492. if(strcmp($sCaptionKey, $sCaptionValue) == 0)
  493. $sCaptionValue = _t($aProvider['caption']);
  494. $aTmplVarsProviders[] = array(
  495. 'button' => $this->parseHtmlByName('providers_select_button.html', array(
  496. 'onclick' => $sJsOnclick,
  497. 'title' => _t('_bx_payment_txt_checkout_with', $sCaptionValue),
  498. 'js_code' => $sJsCode
  499. ))
  500. );
  501. }
  502. return $this->parseHtmlByName('providers_select.html', array(
  503. 'bx_repeat:providers' => $aTmplVarsProviders
  504. ));
  505. }
  506. protected function _displayBlockHistory($sObject, $iClientId, $iSellerId = 0)
  507. {
  508. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getObject($sObject), $this->getModule()->_oTemplate);
  509. if(!$oGrid || empty($iClientId))
  510. return $this->_bIsApi ? false : MsgBox(_t($this->_sLangsPrefix . 'msg_no_results'));
  511. $oGrid->addQueryParam('client_id', $iClientId);
  512. if(!empty($iSellerId))
  513. $oGrid->addQueryParam('seller_id', $iSellerId);
  514. if($this->_bIsApi)
  515. return $oGrid->getCodeAPI();
  516. $this->addJsCssOrders();
  517. return $this->displayJsCode(BX_PAYMENT_ORDERS_TYPE_HISTORY) . $oGrid->getCode();
  518. }
  519. protected function _displaySubscriptionData($sType, $iId)
  520. {
  521. $aResult = array('code' => 1, 'message' => _t('_bx_payment_err_cannot_perform'));
  522. $aPending = $this->_oDb->getOrderPending(array('type' => 'id', 'id' => $iId));
  523. if(empty($aPending) || !is_array($aPending))
  524. return $aResult;
  525. $aSubscription = $this->_oDb->getSubscription(array('type' => 'pending_id', 'pending_id' => $iId));
  526. if(empty($aSubscription) || !is_array($aSubscription))
  527. return $aResult;
  528. $mixedResult = $this->getModule()->isAllowedManage($aPending);
  529. if($mixedResult !== true)
  530. return array('code' => 2, 'message' => $mixedResult);
  531. $sMethod = bx_gen_method_name($sType) . 'Recurring';
  532. $oProvider = $this->getModule()->getObjectProvider($aPending['provider'], $aPending['seller_id']);
  533. if($oProvider === false || !$oProvider->isActive() || !method_exists($oProvider, $sMethod))
  534. return $aResult;
  535. $mixedContent = $oProvider->$sMethod($iId, $aSubscription['customer_id'], $aSubscription['subscription_id']);
  536. if(empty($mixedContent))
  537. return $aResult;
  538. else if(is_array($mixedContent))
  539. return $mixedContent;
  540. $sKey = 'order_' . BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION . '_' . $sType;
  541. $sId = $this->_oConfig->getHtmlIds(BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION, $sKey);
  542. $sTitle = _t($this->_sLangsPrefix . 'popup_title_ods_' . $sKey);
  543. return array('popup' => array(
  544. 'html' => BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $mixedContent),
  545. 'options' => array('closeOnOuterClick' => 1)
  546. ));
  547. }
  548. }
  549. /** @} */