BxDolPayments.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. class BxDolPayments extends BxDolFactory implements iBxDolSingleton
  10. {
  11. protected $_oDb;
  12. protected $_aObjects;
  13. protected $_sActive;
  14. protected function __construct()
  15. {
  16. parent::__construct();
  17. $this->_oDb = new BxDolPaymentsQuery();
  18. $this->_aObjects = $this->_oDb->getObjects();
  19. $this->_sActive = getParam('sys_default_payment');
  20. }
  21. static public function getInstance()
  22. {
  23. if(!isset($GLOBALS['bxDolClasses']['BxDolPayments']))
  24. $GLOBALS['bxDolClasses']['BxDolPayments'] = new BxDolPayments();
  25. return $GLOBALS['bxDolClasses']['BxDolPayments'];
  26. }
  27. public function setActive($sActive)
  28. {
  29. $this->_sActive = $sActive;
  30. }
  31. public function getActive()
  32. {
  33. return $this->_sActive;
  34. }
  35. public function isActive()
  36. {
  37. if(empty($this->_sActive))
  38. return false;
  39. if(!BxDolModuleQuery::getInstance()->isModuleByName($this->_sActive))
  40. return false;
  41. return true;
  42. }
  43. public function isCreditsOnly()
  44. {
  45. if(empty($this->_sActive) || !BxDolRequest::serviceExists($this->_sActive, 'is_credits_only'))
  46. return false;
  47. return bx_srv($this->_sActive, 'is_credits_only');
  48. }
  49. public function getDetailsUrl()
  50. {
  51. if(!BxDolRequest::serviceExists($this->_sActive, 'get_details_url', 'Details'))
  52. return '';
  53. return bx_srv($this->_sActive, 'get_details_url', array(), 'Details');
  54. }
  55. public function isAcceptingPayments($iVendorId, $sPaymentType = '')
  56. {
  57. if(empty($this->_sActive) || !BxDolRequest::serviceExists($this->_sActive, 'is_accepting_payments'))
  58. return false;
  59. $aSrvParams = array($iVendorId, $sPaymentType);
  60. return bx_srv($this->_sActive, 'is_accepting_payments', $aSrvParams);
  61. }
  62. /**
  63. * @deprecated since version 11.0.0
  64. *
  65. * @see BxDolPayments::isProviderOptions
  66. */
  67. public function isPaymentProvider($iVendorId, $sVendorProvider, $sPaymentType = '')
  68. {
  69. return $this->isProviderOptions($iVendorId, $sVendorProvider);
  70. }
  71. /**
  72. * @deprecated since version 11.0.0
  73. *
  74. * @see BxDolPayments::getProviderOptions
  75. */
  76. public function getPaymentProvider($iVendorId, $sVendorProvider, $sPaymentType = '')
  77. {
  78. return $this->getProviderOptions($iVendorId, $sVendorProvider, $sPaymentType);
  79. }
  80. public function isProviderOptions($iVendorId, $sVendorProvider, $sPaymentType = '')
  81. {
  82. if(empty($this->_sActive) || !BxDolRequest::serviceExists($this->_sActive, 'is_provider_options'))
  83. return false;
  84. $aSrvParams = array($iVendorId, $sVendorProvider, $sPaymentType);
  85. return bx_srv($this->_sActive, 'is_provider_options', $aSrvParams);
  86. }
  87. public function getProvider($sProvider, $mixedVendorId = BX_PAYMENT_EMPTY_ID)
  88. {
  89. if(empty($this->_sActive) || !BxDolRequest::serviceExists($this->_sActive, 'get_provider'))
  90. return false;
  91. $aSrvParams = array($sProvider, $mixedVendorId);
  92. return bx_srv($this->_sActive, 'get_provider', $aSrvParams);
  93. }
  94. public function getProviderOptions($iVendorId, $sVendorProvider, $sPaymentType = '')
  95. {
  96. if(empty($this->_sActive) || !BxDolRequest::serviceExists($this->_sActive, 'get_provider_options'))
  97. return false;
  98. $aSrvParams = array($iVendorId, $sVendorProvider, $sPaymentType);
  99. return bx_srv($this->_sActive, 'get_provider_options', $aSrvParams);
  100. }
  101. public function getModulesWithPayments()
  102. {
  103. if(empty($this->_sActive) || !BxDolRequest::serviceExists($this->_sActive, 'get_modules_with_payments'))
  104. return false;
  105. return bx_srv($this->_sActive, 'get_modules_with_payments', array());
  106. }
  107. public function getProductsNames($iVendor = 0, $iLimit = 1000)
  108. {
  109. $aRet = array();
  110. $aModules = $this->getModulesWithPayments();
  111. foreach ($aModules as $sModule) {
  112. if(!BxDolRequest::serviceExists($sModule, 'get_products_names'))
  113. continue;
  114. $aKeys = bx_srv($sModule, 'get_products_names', array($iVendor, $iLimit));
  115. if (!$aKeys)
  116. continue;
  117. $aValues = array_fill(0, count($aKeys), $sModule);
  118. $aRet = array_merge($aRet, array_combine($aKeys, $aValues));
  119. }
  120. return $aRet;
  121. }
  122. public function getPayments()
  123. {
  124. $aPayments = array(
  125. '' => _t('_Select_one')
  126. );
  127. foreach($this->_aObjects as $aObject) {
  128. if(empty($aObject) || !is_array($aObject))
  129. continue;
  130. $aPayments[$aObject['object']] = _t($aObject['title']);
  131. }
  132. return $aPayments;
  133. }
  134. public function updateDependentModules($sModule = 'all', $bInstall = true)
  135. {
  136. if(!BxDolRequest::serviceExists($this->_sActive, 'update_dependent_modules'))
  137. return;
  138. bx_srv($this->_sActive, 'update_dependent_modules', array($sModule, $bInstall));
  139. }
  140. public function getProvidersCart($iVendorId)
  141. {
  142. if(!BxDolRequest::serviceExists($this->_sActive, 'get_providers_cart'))
  143. return array();
  144. $aSrvParams = array($iVendorId);
  145. return bx_srv($this->_sActive, 'get_providers_cart', $aSrvParams);
  146. }
  147. public function getOption($sOption)
  148. {
  149. if(!BxDolRequest::serviceExists($this->_sActive, 'get_option'))
  150. return '';
  151. return bx_srv($this->_sActive, 'get_option', array($sOption));
  152. }
  153. public function getOrdersUrl()
  154. {
  155. if(!BxDolRequest::serviceExists($this->_sActive, 'get_orders_url', 'Orders'))
  156. return '';
  157. return bx_srv($this->_sActive, 'get_orders_url', array(), 'Orders');
  158. }
  159. public function getOrdersCount($sType)
  160. {
  161. if(!BxDolRequest::serviceExists($this->_sActive, 'get_orders_count', 'Orders'))
  162. return array();
  163. $aSrvParams = array($sType);
  164. return bx_srv($this->_sActive, 'get_orders_count', $aSrvParams, 'Orders');
  165. }
  166. public function getOrdersInfo($aConditions)
  167. {
  168. if(!BxDolRequest::serviceExists($this->_sActive, 'get_orders_info', 'Orders'))
  169. return array();
  170. $aSrvParams = array($aConditions);
  171. return bx_srv($this->_sActive, 'get_orders_info', $aSrvParams, 'Orders');
  172. }
  173. public function getPendingOrdersInfo($aConditions)
  174. {
  175. if(!BxDolRequest::serviceExists($this->_sActive, 'get_pending_orders_info', 'Orders'))
  176. return array();
  177. $aSrvParams = array($aConditions);
  178. return bx_srv($this->_sActive, 'get_pending_orders_info', $aSrvParams, 'Orders');
  179. }
  180. public function getSubscriptionOrdersInfo($aConditions)
  181. {
  182. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscription_orders_info', 'Subscriptions'))
  183. return array();
  184. $aSrvParams = array($aConditions);
  185. return bx_srv($this->_sActive, 'get_subscription_orders_info', $aSrvParams, 'Subscriptions');
  186. }
  187. public function getSubscriptionsInfo($aConditions, $bCheckInProvider = false)
  188. {
  189. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscriptions_info', 'Subscriptions'))
  190. return array();
  191. $aSrvParams = array($aConditions, $bCheckInProvider);
  192. return bx_srv($this->_sActive, 'get_subscriptions_info', $aSrvParams, 'Subscriptions');
  193. }
  194. public function getCartUrl($iVendor = 0)
  195. {
  196. if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_url', 'Cart'))
  197. return '';
  198. return bx_srv($this->_sActive, 'get_cart_url', array($iVendor), 'Cart');
  199. }
  200. public function getCartItemsCount()
  201. {
  202. if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_items_count', 'Cart'))
  203. return 0;
  204. $aSrvParams = array();
  205. return bx_srv($this->_sActive, 'get_cart_items_count', $aSrvParams, 'Cart');
  206. }
  207. public function getCartItems($iVendorId, $iModuleId)
  208. {
  209. if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_items', 'Cart'))
  210. return 0;
  211. $aSrvParams = array($iVendorId, $iModuleId);
  212. return bx_srv($this->_sActive, 'get_cart_items', $aSrvParams, 'Cart');
  213. }
  214. public function getCartItemDescriptor($iVendorId, $iModuleId, $iItemId, $iItemCount)
  215. {
  216. if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_item_descriptor', 'Cart'))
  217. return '';
  218. $aSrvParams = array($iVendorId, $iModuleId, $iItemId, $iItemCount);
  219. return bx_srv($this->_sActive, 'get_cart_item_descriptor', $aSrvParams, 'Cart');
  220. }
  221. /**
  222. * Returns cart JavaScript code which should be included in the page to make "Add To Cart" and "Subscribe" buttons work properly.
  223. */
  224. public function getCartJs($sType = '', $iVendorId = 0)
  225. {
  226. if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_js', 'Cart'))
  227. return '';
  228. $aSrvParams = array($sType, $iVendorId);
  229. return bx_srv($this->_sActive, 'get_cart_js', $aSrvParams, 'Cart');
  230. }
  231. /**
  232. * Adds an item to cart in background mode.
  233. */
  234. public function addToCart($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $aCustom = array())
  235. {
  236. if(!BxDolRequest::serviceExists($this->_sActive, 'add_to_cart', 'Cart'))
  237. return array();
  238. $aSrvParams = array($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $aCustom);
  239. return bx_srv($this->_sActive, 'add_to_cart', $aSrvParams, 'Cart');
  240. }
  241. /**
  242. * Returns "Add To Cart" JavaScript code to use in onclick attribute.
  243. */
  244. public function getAddToCartJs($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect = false, $aCustom = array())
  245. {
  246. if(!BxDolRequest::serviceExists($this->_sActive, 'get_add_to_cart_js', 'Cart'))
  247. return array();
  248. $aSrvParams = array($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect, $aCustom);
  249. return bx_srv($this->_sActive, 'get_add_to_cart_js', $aSrvParams, 'Cart');
  250. }
  251. /**
  252. * Returns the whole "Add To Cart" link including HTML tag BUTTON and cart JavaScript code.
  253. */
  254. public function getAddToCartLink($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect = false, $aCustom = array())
  255. {
  256. if(!BxDolRequest::serviceExists($this->_sActive, 'get_add_to_cart_link', 'Cart'))
  257. return '';
  258. $aSrvParams = array($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect, $aCustom);
  259. return bx_srv($this->_sActive, 'get_add_to_cart_link', $aSrvParams, 'Cart');
  260. }
  261. public function getSubscriptionsUrl()
  262. {
  263. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscriptions_url', 'Subscriptions'))
  264. return '';
  265. return bx_srv($this->_sActive, 'get_subscriptions_url', array(), 'Subscriptions');
  266. }
  267. public function getSubscribeUrl($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1)
  268. {
  269. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscribe_url', 'Subscriptions'))
  270. return '';
  271. return bx_srv($this->_sActive, 'get_subscribe_url', array($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount), 'Subscriptions');
  272. }
  273. /**
  274. * Returns "Subscribe" JavaScript code to use in onclick attribute.
  275. */
  276. public function getSubscribeJs($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1, $sRedirect = '', $aCustom = array())
  277. {
  278. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscribe_js', 'Subscriptions'))
  279. return array();
  280. $aSrvParams = array($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount, $sRedirect, $aCustom);
  281. return bx_srv($this->_sActive, 'get_subscribe_js', $aSrvParams, 'Subscriptions');
  282. }
  283. /**
  284. * Returns "Subscribe" JavaScript code to use in onclick attribute.
  285. */
  286. public function getSubscribeJsWithAddons($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1, $sItemAddons = '', $sRedirect = '', $aCustom = array())
  287. {
  288. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscribe_js_with_addons', 'Subscriptions'))
  289. return array();
  290. $aSrvParams = array($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount, $sItemAddons, $sRedirect, $aCustom);
  291. return bx_srv($this->_sActive, 'get_subscribe_js_with_addons', $aSrvParams, 'Subscriptions');
  292. }
  293. /**
  294. * Returns the whole "Subscribe" link including HTML tag BUTTON and cart JavaScript code.
  295. */
  296. public function getSubscribeLink($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1, $sRedirect = '', $aCustom = array())
  297. {
  298. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscribe_link', 'Subscriptions'))
  299. return '';
  300. $aSrvParams = array($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount, $sRedirect, $aCustom);
  301. return bx_srv($this->_sActive, 'get_subscribe_link', $aSrvParams, 'Subscriptions');
  302. }
  303. public function sendSubscriptionExpirationLetters($iPendingId, $sOrderId)
  304. {
  305. if(!BxDolRequest::serviceExists($this->_sActive, 'send_subscription_expiration_letters', 'Subscriptions'))
  306. return '';
  307. $aSrvParams = array($iPendingId, $sOrderId);
  308. return bx_srv($this->_sActive, 'send_subscription_expiration_letters', $aSrvParams, 'Subscriptions');
  309. }
  310. public function initializeCheckout($iVendorId, $sProvider, $aItems = array())
  311. {
  312. if(!BxDolRequest::serviceExists($this->_sActive, 'initialize_checkout'))
  313. return '';
  314. $aSrvParams = array($iVendorId, $sProvider, $aItems);
  315. return bx_srv($this->_sActive, 'initialize_checkout', $aSrvParams);
  316. }
  317. /**
  318. * Isn't used anywhere for now. Is needed when license 'prolong' is requested from license keeping module like Market and ACL.
  319. */
  320. public function prolongSubscription($sOrderId)
  321. {
  322. if(!BxDolRequest::serviceExists($this->_sActive, 'prolong_subscription'))
  323. return '';
  324. $aSrvParams = array($sOrderId);
  325. return bx_srv($this->_sActive, 'prolong_subscription', $aSrvParams);
  326. }
  327. public function generateLicense()
  328. {
  329. if(!BxDolRequest::serviceExists($this->_sActive, 'generate_license'))
  330. return '';
  331. $aSrvParams = array();
  332. return bx_srv($this->_sActive, 'generate_license', $aSrvParams, 'Module', true);
  333. }
  334. }
  335. /** @} */