1
0

BxDolPayments.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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 getDetailsUrl()
  44. {
  45. if(!BxDolRequest::serviceExists($this->_sActive, 'get_details_url', 'Details'))
  46. return '';
  47. return BxDolService::call($this->_sActive, 'get_details_url', array(), 'Details');
  48. }
  49. public function isAcceptingPayments($iVendorId, $sPaymentType = '')
  50. {
  51. if(empty($this->_sActive) || !BxDolRequest::serviceExists($this->_sActive, 'is_accepting_payments'))
  52. return false;
  53. $aSrvParams = array($iVendorId, $sPaymentType);
  54. return BxDolService::call($this->_sActive, 'is_accepting_payments', $aSrvParams);
  55. }
  56. public function isPaymentProvider($iVendorId, $sVendorProvider, $sPaymentType = '')
  57. {
  58. if(empty($this->_sActive) || !BxDolRequest::serviceExists($this->_sActive, 'is_payment_provider'))
  59. return false;
  60. $aSrvParams = array($iVendorId, $sVendorProvider, $sPaymentType);
  61. return BxDolService::call($this->_sActive, 'is_payment_provider', $aSrvParams);
  62. }
  63. public function getPaymentProvider($iVendorId, $sVendorProvider, $sPaymentType = '')
  64. {
  65. if(empty($this->_sActive) || !BxDolRequest::serviceExists($this->_sActive, 'get_payment_provider'))
  66. return false;
  67. $aSrvParams = array($iVendorId, $sVendorProvider, $sPaymentType);
  68. return BxDolService::call($this->_sActive, 'get_payment_provider', $aSrvParams);
  69. }
  70. public function getPayments()
  71. {
  72. $aPayments = array(
  73. '' => _t('_Select_one')
  74. );
  75. foreach($this->_aObjects as $aObject) {
  76. if(empty($aObject) || !is_array($aObject))
  77. continue;
  78. $aPayments[$aObject['object']] = _t($aObject['title']);
  79. }
  80. return $aPayments;
  81. }
  82. public function updateDependentModules($sModule = 'all', $bInstall = true)
  83. {
  84. if(!BxDolRequest::serviceExists($this->_sActive, 'update_dependent_modules'))
  85. return;
  86. BxDolService::call($this->_sActive, 'update_dependent_modules', array($sModule, $bInstall));
  87. }
  88. public function getProvidersCart($iVendorId)
  89. {
  90. if(!BxDolRequest::serviceExists($this->_sActive, 'get_providers_cart'))
  91. return array();
  92. $aSrvParams = array($iVendorId);
  93. return BxDolService::call($this->_sActive, 'get_providers_cart', $aSrvParams);
  94. }
  95. public function getOption($sOption)
  96. {
  97. if(!BxDolRequest::serviceExists($this->_sActive, 'get_option'))
  98. return '';
  99. return BxDolService::call($this->_sActive, 'get_option', array($sOption));
  100. }
  101. public function getOrdersUrl()
  102. {
  103. if(!BxDolRequest::serviceExists($this->_sActive, 'get_orders_url', 'Orders'))
  104. return '';
  105. return BxDolService::call($this->_sActive, 'get_orders_url', array(), 'Orders');
  106. }
  107. public function getOrdersCount($sType)
  108. {
  109. if(!BxDolRequest::serviceExists($this->_sActive, 'get_orders_count', 'Orders'))
  110. return array();
  111. $aSrvParams = array($sType);
  112. return BxDolService::call($this->_sActive, 'get_orders_count', $aSrvParams, 'Orders');
  113. }
  114. public function getOrdersInfo($aConditions)
  115. {
  116. if(!BxDolRequest::serviceExists($this->_sActive, 'get_orders_info', 'Orders'))
  117. return array();
  118. $aSrvParams = array($aConditions);
  119. return BxDolService::call($this->_sActive, 'get_orders_info', $aSrvParams, 'Orders');
  120. }
  121. public function getPendingOrdersInfo($aConditions)
  122. {
  123. if(!BxDolRequest::serviceExists($this->_sActive, 'get_pending_orders_info', 'Orders'))
  124. return array();
  125. $aSrvParams = array($aConditions);
  126. return BxDolService::call($this->_sActive, 'get_pending_orders_info', $aSrvParams, 'Orders');
  127. }
  128. public function getSubscriptionOrdersInfo($aConditions)
  129. {
  130. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscription_orders_info', 'Subscriptions'))
  131. return array();
  132. $aSrvParams = array($aConditions);
  133. return BxDolService::call($this->_sActive, 'get_subscription_orders_info', $aSrvParams, 'Subscriptions');
  134. }
  135. public function getSubscriptionsInfo($aConditions, $bCheckInProvider = false)
  136. {
  137. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscriptions_info', 'Subscriptions'))
  138. return array();
  139. $aSrvParams = array($aConditions, $bCheckInProvider);
  140. return BxDolService::call($this->_sActive, 'get_subscriptions_info', $aSrvParams, 'Subscriptions');
  141. }
  142. public function getCartUrl($iVendor = 0)
  143. {
  144. if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_url', 'Cart'))
  145. return '';
  146. return BxDolService::call($this->_sActive, 'get_cart_url', array($iVendor), 'Cart');
  147. }
  148. public function getCartItemsCount()
  149. {
  150. if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_items_count', 'Cart'))
  151. return 0;
  152. $aSrvParams = array();
  153. return BxDolService::call($this->_sActive, 'get_cart_items_count', $aSrvParams, 'Cart');
  154. }
  155. public function getCartItemDescriptor($iVendorId, $iModuleId, $iItemId, $iItemCount)
  156. {
  157. if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_item_descriptor', 'Cart'))
  158. return '';
  159. $aSrvParams = array($iVendorId, $iModuleId, $iItemId, $iItemCount);
  160. return BxDolService::call($this->_sActive, 'get_cart_item_descriptor', $aSrvParams, 'Cart');
  161. }
  162. /**
  163. * Returns cart JavaScript code which should be included in the page to make "Add To Cart" and "Subscribe" buttons work properly.
  164. */
  165. public function getCartJs($sType = '', $iVendorId = 0)
  166. {
  167. if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_js', 'Cart'))
  168. return '';
  169. $aSrvParams = array($sType, $iVendorId);
  170. return BxDolService::call($this->_sActive, 'get_cart_js', $aSrvParams, 'Cart');
  171. }
  172. /**
  173. * Adds an item to cart in background mode.
  174. */
  175. public function addToCart($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $aCustom = array())
  176. {
  177. if(!BxDolRequest::serviceExists($this->_sActive, 'add_to_cart', 'Cart'))
  178. return array();
  179. $aSrvParams = array($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $aCustom);
  180. return BxDolService::call($this->_sActive, 'add_to_cart', $aSrvParams, 'Cart');
  181. }
  182. /**
  183. * Returns "Add To Cart" JavaScript code to use in onclick attribute.
  184. */
  185. public function getAddToCartJs($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect = false, $aCustom = array())
  186. {
  187. if(!BxDolRequest::serviceExists($this->_sActive, 'get_add_to_cart_js', 'Cart'))
  188. return array();
  189. $aSrvParams = array($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect, $aCustom);
  190. return BxDolService::call($this->_sActive, 'get_add_to_cart_js', $aSrvParams, 'Cart');
  191. }
  192. /**
  193. * Returns the whole "Add To Cart" link including HTML tag BUTTON and cart JavaScript code.
  194. */
  195. public function getAddToCartLink($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect = false, $aCustom = array())
  196. {
  197. if(!BxDolRequest::serviceExists($this->_sActive, 'get_add_to_cart_link', 'Cart'))
  198. return '';
  199. $aSrvParams = array($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect, $aCustom);
  200. return BxDolService::call($this->_sActive, 'get_add_to_cart_link', $aSrvParams, 'Cart');
  201. }
  202. public function getSubscriptionsUrl()
  203. {
  204. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscriptions_url', 'Subscriptions'))
  205. return '';
  206. return BxDolService::call($this->_sActive, 'get_subscriptions_url', array(), 'Subscriptions');
  207. }
  208. public function getSubscribeUrl($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1)
  209. {
  210. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscribe_url', 'Subscriptions'))
  211. return '';
  212. return BxDolService::call($this->_sActive, 'get_subscribe_url', array($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount), 'Subscriptions');
  213. }
  214. /**
  215. * Returns "Subscribe" JavaScript code to use in onclick attribute.
  216. */
  217. public function getSubscribeJs($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1, $sRedirect = '', $aCustom = array())
  218. {
  219. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscribe_js', 'Subscriptions'))
  220. return array();
  221. $aSrvParams = array($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount, $sRedirect, $aCustom);
  222. return BxDolService::call($this->_sActive, 'get_subscribe_js', $aSrvParams, 'Subscriptions');
  223. }
  224. /**
  225. * Returns the whole "Subscribe" link including HTML tag BUTTON and cart JavaScript code.
  226. */
  227. public function getSubscribeLink($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1, $sRedirect = '', $aCustom = array())
  228. {
  229. if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscribe_link', 'Subscriptions'))
  230. return '';
  231. $aSrvParams = array($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount, $sRedirect, $aCustom);
  232. return BxDolService::call($this->_sActive, 'get_subscribe_link', $aSrvParams, 'Subscriptions');
  233. }
  234. public function sendSubscriptionExpirationLetters($iPendingId, $sOrderId)
  235. {
  236. if(!BxDolRequest::serviceExists($this->_sActive, 'send_subscription_expiration_letters', 'Subscriptions'))
  237. return '';
  238. $aSrvParams = array($iPendingId, $sOrderId);
  239. return BxDolService::call($this->_sActive, 'send_subscription_expiration_letters', $aSrvParams, 'Subscriptions');
  240. }
  241. public function initializeCheckout($iVendorId, $sProvider, $aItems = array())
  242. {
  243. if(!BxDolRequest::serviceExists($this->_sActive, 'initialize_checkout'))
  244. return '';
  245. $aSrvParams = array($iVendorId, $sProvider, $aItems);
  246. return BxDolService::call($this->_sActive, 'initialize_checkout', $aSrvParams);
  247. }
  248. /**
  249. * Isn't used anywhere for now. Is needed when license 'prolong' is requested from license keeping module like Market and ACL.
  250. */
  251. public function prolongSubscription($sOrderId)
  252. {
  253. if(!BxDolRequest::serviceExists($this->_sActive, 'prolong_subscription'))
  254. return '';
  255. $aSrvParams = array($sOrderId);
  256. return BxDolService::call($this->_sActive, 'prolong_subscription', $aSrvParams);
  257. }
  258. public function generateLicense()
  259. {
  260. if(!BxDolRequest::serviceExists($this->_sActive, 'generate_license'))
  261. return '';
  262. $aSrvParams = array();
  263. return BxDolService::call($this->_sActive, 'generate_license', $aSrvParams, 'Module', true);
  264. }
  265. }
  266. /** @} */