BxDolPayments.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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 getInvoicesUrl()
  195. {
  196. if(!BxDolRequest::serviceExists($this->_sActive, 'get_invoices_url', 'Commissions'))
  197. return '';
  198. return bx_srv($this->_sActive, 'get_invoices_url', array(), 'Commissions');
  199. }
  200. public function getInvoicesCount($sType)
  201. {
  202. if(!BxDolRequest::serviceExists($this->_sActive, 'get_invoices_count', 'Commissions'))
  203. return array();
  204. $aSrvParams = array($sType);
  205. return bx_srv($this->_sActive, 'get_invoices_count', $aSrvParams, 'Commissions');
  206. }
  207. public function getCartUrl($iVendor = 0)
  208. {
  209. if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_url', 'Cart'))
  210. return '';
  211. return bx_srv($this->_sActive, 'get_cart_url', array($iVendor), 'Cart');
  212. }
  213. public function getCartItemsCount()
  214. {
  215. if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_items_count', 'Cart'))
  216. return 0;
  217. $aSrvParams = array();
  218. return bx_srv($this->_sActive, 'get_cart_items_count', $aSrvParams, 'Cart');
  219. }
  220. public function getCartItems($iVendorId, $iModuleId)
  221. {
  222. if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_items', 'Cart'))
  223. return 0;
  224. $aSrvParams = array($iVendorId, $iModuleId);
  225. return bx_srv($this->_sActive, 'get_cart_items', $aSrvParams, 'Cart');
  226. }
  227. public function getCartItemDescriptor($iVendorId, $iModuleId, $iItemId, $iItemCount)
  228. {
  229. if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_item_descriptor', 'Cart'))
  230. return '';
  231. $aSrvParams = array($iVendorId, $iModuleId, $iItemId, $iItemCount);
  232. return bx_srv($this->_sActive, 'get_cart_item_descriptor', $aSrvParams, 'Cart');
  233. }
  234. /**
  235. * Returns cart JavaScript code which should be included in the page to make "Add To Cart" and "Subscribe" buttons work properly.
  236. */
  237. public function getCartJs($sType = '', $iVendorId = 0)
  238. {
  239. if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_js', 'Cart'))
  240. return '';
  241. $aSrvParams = array($sType, $iVendorId);
  242. return bx_srv($this->_sActive, 'get_cart_js', $aSrvParams, 'Cart');
  243. }
  244. /**
  245. * Adds an item to cart in background mode.
  246. */
  247. public function addToCart($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $aCustom = array())
  248. {
  249. if(!BxDolRequest::serviceExists($this->_sActive, 'add_to_cart', 'Cart'))
  250. return array();
  251. $aSrvParams = array($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $aCustom);
  252. return bx_srv($this->_sActive, 'add_to_cart', $aSrvParams, 'Cart');
  253. }
  254. /**
  255. * Returns "Add To Cart" JavaScript code to use in onclick attribute.
  256. */
  257. public function getAddToCartJs($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect = false, $aCustom = array())
  258. {
  259. if(!BxDolRequest::serviceExists($this->_sActive, 'get_add_to_cart_js', 'Cart'))
  260. return array();
  261. $aSrvParams = array($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect, $aCustom);
  262. return bx_srv($this->_sActive, 'get_add_to_cart_js', $aSrvParams, 'Cart');
  263. }
  264. /**
  265. * Returns the whole "Add To Cart" link including HTML tag BUTTON and cart JavaScript code.
  266. */
  267. public function getAddToCartLink($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect = false, $aCustom = array())
  268. {
  269. if(!BxDolRequest::serviceExists($this->_sActive, 'get_add_to_cart_link', 'Cart'))
  270. return '';
  271. $aSrvParams = array($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect, $aCustom);
  272. return bx_srv($this->_sActive, 'get_add_to_cart_link', $aSrvParams, 'Cart');
  273. }
  274. public function getSubscriptionsUrl()
  275. {
  276. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscriptions_url', 'Subscriptions'))
  277. return '';
  278. return bx_srv($this->_sActive, 'get_subscriptions_url', array(), 'Subscriptions');
  279. }
  280. public function getSubscribeUrl($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1)
  281. {
  282. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscribe_url', 'Subscriptions'))
  283. return '';
  284. return bx_srv($this->_sActive, 'get_subscribe_url', array($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount), 'Subscriptions');
  285. }
  286. /**
  287. * Returns "Subscribe" JavaScript code to use in onclick attribute.
  288. */
  289. public function getSubscribeJs($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1, $sRedirect = '', $aCustom = array())
  290. {
  291. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscribe_js', 'Subscriptions'))
  292. return array();
  293. $aSrvParams = array($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount, $sRedirect, $aCustom);
  294. return bx_srv($this->_sActive, 'get_subscribe_js', $aSrvParams, 'Subscriptions');
  295. }
  296. /**
  297. * Returns "Subscribe" JavaScript code to use in onclick attribute.
  298. */
  299. public function getSubscribeJsWithAddons($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1, $sItemAddons = '', $sRedirect = '', $aCustom = array())
  300. {
  301. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscribe_js_with_addons', 'Subscriptions'))
  302. return array();
  303. $aSrvParams = array($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount, $sItemAddons, $sRedirect, $aCustom);
  304. return bx_srv($this->_sActive, 'get_subscribe_js_with_addons', $aSrvParams, 'Subscriptions');
  305. }
  306. /**
  307. * Returns the whole "Subscribe" link including HTML tag BUTTON and cart JavaScript code.
  308. */
  309. public function getSubscribeLink($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1, $sRedirect = '', $aCustom = array())
  310. {
  311. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscribe_link', 'Subscriptions'))
  312. return '';
  313. $aSrvParams = array($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount, $sRedirect, $aCustom);
  314. return bx_srv($this->_sActive, 'get_subscribe_link', $aSrvParams, 'Subscriptions');
  315. }
  316. public function sendSubscriptionExpirationLetters($iPendingId, $sOrderId)
  317. {
  318. if(!BxDolRequest::serviceExists($this->_sActive, 'send_subscription_expiration_letters', 'Subscriptions'))
  319. return '';
  320. $aSrvParams = array($iPendingId, $sOrderId);
  321. return bx_srv($this->_sActive, 'send_subscription_expiration_letters', $aSrvParams, 'Subscriptions');
  322. }
  323. public function initializeCheckout($iVendorId, $sProvider, $aItems = array())
  324. {
  325. if(!BxDolRequest::serviceExists($this->_sActive, 'initialize_checkout'))
  326. return '';
  327. $aSrvParams = array($iVendorId, $sProvider, $aItems);
  328. return bx_srv($this->_sActive, 'initialize_checkout', $aSrvParams);
  329. }
  330. /**
  331. * Isn't used anywhere for now. Is needed when license 'prolong' is requested from license keeping module like Market and ACL.
  332. */
  333. public function prolongSubscription($sOrderId)
  334. {
  335. if(!BxDolRequest::serviceExists($this->_sActive, 'prolong_subscription'))
  336. return '';
  337. $aSrvParams = array($sOrderId);
  338. return bx_srv($this->_sActive, 'prolong_subscription', $aSrvParams);
  339. }
  340. public function generateLicense()
  341. {
  342. if(!BxDolRequest::serviceExists($this->_sActive, 'generate_license'))
  343. return '';
  344. $aSrvParams = array();
  345. return bx_srv($this->_sActive, 'generate_license', $aSrvParams, 'Module', true);
  346. }
  347. }
  348. /** @} */