| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaCore UNA Core
- * @{
- */
- class BxDolPayments extends BxDolFactory implements iBxDolSingleton
- {
- protected $_oDb;
- protected $_aObjects;
- protected $_sActive;
- protected function __construct()
- {
- parent::__construct();
- $this->_oDb = new BxDolPaymentsQuery();
- $this->_aObjects = $this->_oDb->getObjects();
- $this->_sActive = getParam('sys_default_payment');
- }
- static public function getInstance()
- {
- if(!isset($GLOBALS['bxDolClasses']['BxDolPayments']))
- $GLOBALS['bxDolClasses']['BxDolPayments'] = new BxDolPayments();
- return $GLOBALS['bxDolClasses']['BxDolPayments'];
- }
- public function setActive($sActive)
- {
- $this->_sActive = $sActive;
- }
- public function getActive()
- {
- return $this->_sActive;
- }
- public function isActive()
- {
- if(empty($this->_sActive))
- return false;
- if(!BxDolModuleQuery::getInstance()->isModuleByName($this->_sActive))
- return false;
- return true;
- }
- public function getDetailsUrl()
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_details_url', 'Details'))
- return '';
- return BxDolService::call($this->_sActive, 'get_details_url', array(), 'Details');
- }
- public function isAcceptingPayments($iVendorId, $sPaymentType = '')
- {
- if(empty($this->_sActive) || !BxDolRequest::serviceExists($this->_sActive, 'is_accepting_payments'))
- return false;
- $aSrvParams = array($iVendorId, $sPaymentType);
- return BxDolService::call($this->_sActive, 'is_accepting_payments', $aSrvParams);
- }
- public function isPaymentProvider($iVendorId, $sVendorProvider, $sPaymentType = '')
- {
- if(empty($this->_sActive) || !BxDolRequest::serviceExists($this->_sActive, 'is_payment_provider'))
- return false;
- $aSrvParams = array($iVendorId, $sVendorProvider, $sPaymentType);
- return BxDolService::call($this->_sActive, 'is_payment_provider', $aSrvParams);
- }
- public function getPaymentProvider($iVendorId, $sVendorProvider, $sPaymentType = '')
- {
- if(empty($this->_sActive) || !BxDolRequest::serviceExists($this->_sActive, 'get_payment_provider'))
- return false;
- $aSrvParams = array($iVendorId, $sVendorProvider, $sPaymentType);
- return BxDolService::call($this->_sActive, 'get_payment_provider', $aSrvParams);
- }
- public function getPayments()
- {
- $aPayments = array(
- '' => _t('_Select_one')
- );
- foreach($this->_aObjects as $aObject) {
- if(empty($aObject) || !is_array($aObject))
- continue;
- $aPayments[$aObject['object']] = _t($aObject['title']);
- }
- return $aPayments;
- }
- public function updateDependentModules($sModule = 'all', $bInstall = true)
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'update_dependent_modules'))
- return;
- BxDolService::call($this->_sActive, 'update_dependent_modules', array($sModule, $bInstall));
- }
- public function getProvidersCart($iVendorId)
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_providers_cart'))
- return array();
- $aSrvParams = array($iVendorId);
- return BxDolService::call($this->_sActive, 'get_providers_cart', $aSrvParams);
- }
- public function getOption($sOption)
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_option'))
- return '';
- return BxDolService::call($this->_sActive, 'get_option', array($sOption));
- }
- public function getOrdersUrl()
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_orders_url', 'Orders'))
- return '';
- return BxDolService::call($this->_sActive, 'get_orders_url', array(), 'Orders');
- }
- public function getOrdersCount($sType)
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_orders_count', 'Orders'))
- return array();
- $aSrvParams = array($sType);
- return BxDolService::call($this->_sActive, 'get_orders_count', $aSrvParams, 'Orders');
- }
- public function getOrdersInfo($aConditions)
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_orders_info', 'Orders'))
- return array();
- $aSrvParams = array($aConditions);
- return BxDolService::call($this->_sActive, 'get_orders_info', $aSrvParams, 'Orders');
- }
- public function getPendingOrdersInfo($aConditions)
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_pending_orders_info', 'Orders'))
- return array();
- $aSrvParams = array($aConditions);
- return BxDolService::call($this->_sActive, 'get_pending_orders_info', $aSrvParams, 'Orders');
- }
- public function getCartUrl($iVendor = 0)
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_url', 'Cart'))
- return '';
- return BxDolService::call($this->_sActive, 'get_cart_url', array($iVendor), 'Cart');
- }
- public function getCartItemsCount()
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_items_count', 'Cart'))
- return 0;
- $aSrvParams = array();
- return BxDolService::call($this->_sActive, 'get_cart_items_count', $aSrvParams, 'Cart');
- }
- public function getCartItemDescriptor($iVendorId, $iModuleId, $iItemId, $iItemCount)
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_item_descriptor', 'Cart'))
- return '';
- $aSrvParams = array($iVendorId, $iModuleId, $iItemId, $iItemCount);
- return BxDolService::call($this->_sActive, 'get_cart_item_descriptor', $aSrvParams, 'Cart');
- }
- /**
- * Returns cart JavaScript code which should be included in the page to make "Add To Cart" and "Subscribe" buttons work properly.
- */
- public function getCartJs($sType = '', $iVendorId = 0)
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_js', 'Cart'))
- return '';
- $aSrvParams = array($sType, $iVendorId);
- return BxDolService::call($this->_sActive, 'get_cart_js', $aSrvParams, 'Cart');
- }
- /**
- * Adds an item to cart in background mode.
- */
- public function addToCart($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $aCustom = array())
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'add_to_cart', 'Cart'))
- return array();
- $aSrvParams = array($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $aCustom);
- return BxDolService::call($this->_sActive, 'add_to_cart', $aSrvParams, 'Cart');
- }
- /**
- * Returns "Add To Cart" JavaScript code to use in onclick attribute.
- */
- public function getAddToCartJs($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect = false, $aCustom = array())
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_add_to_cart_js', 'Cart'))
- return array();
- $aSrvParams = array($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect, $aCustom);
- return BxDolService::call($this->_sActive, 'get_add_to_cart_js', $aSrvParams, 'Cart');
- }
- /**
- * Returns the whole "Add To Cart" link including HTML tag BUTTON and cart JavaScript code.
- */
- public function getAddToCartLink($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect = false, $aCustom = array())
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_add_to_cart_link', 'Cart'))
- return '';
- $aSrvParams = array($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect, $aCustom);
- return BxDolService::call($this->_sActive, 'get_add_to_cart_link', $aSrvParams, 'Cart');
- }
- public function getSubscriptionsUrl()
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscriptions_url', 'Subscriptions'))
- return '';
- return BxDolService::call($this->_sActive, 'get_subscriptions_url', array(), 'Subscriptions');
- }
- public function getSubscribeUrl($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1)
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscribe_url', 'Subscriptions'))
- return '';
- return BxDolService::call($this->_sActive, 'get_subscribe_url', array($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount), 'Subscriptions');
- }
- /**
- * Returns "Subscribe" JavaScript code to use in onclick attribute.
- */
- public function getSubscribeJs($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1, $sRedirect = '', $aCustom = array())
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscribe_js', 'Subscriptions'))
- return array();
- $aSrvParams = array($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount, $sRedirect, $aCustom);
- return BxDolService::call($this->_sActive, 'get_subscribe_js', $aSrvParams, 'Subscriptions');
- }
- /**
- * Returns the whole "Subscribe" link including HTML tag BUTTON and cart JavaScript code.
- */
- public function getSubscribeLink($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount = 1, $sRedirect = '', $aCustom = array())
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'get_subscribe_link', 'Subscriptions'))
- return '';
- $aSrvParams = array($iVendorId, $sVendorProvider, $mixedModuleId, $iItemId, $iItemCount, $sRedirect, $aCustom);
- return BxDolService::call($this->_sActive, 'get_subscribe_link', $aSrvParams, 'Subscriptions');
- }
- public function initializeCheckout($iVendorId, $sProvider, $aItems = array())
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'initialize_checkout'))
- return '';
- $aSrvParams = array($iVendorId, $sProvider, $aItems);
- return BxDolService::call($this->_sActive, 'initialize_checkout', $aSrvParams);
- }
- /**
- * Isn't used anywhere for now. Is needed when license 'prolong' is requested from license keeping module like Market and ACL.
- */
- public function prolongSubscription($sOrderId)
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'prolong_subscription'))
- return '';
- $aSrvParams = array($sOrderId);
- return BxDolService::call($this->_sActive, 'prolong_subscription', $aSrvParams);
- }
- public function generateLicense()
- {
- if(!BxDolRequest::serviceExists($this->_sActive, 'generate_license'))
- return '';
- $aSrvParams = array();
- return BxDolService::call($this->_sActive, 'generate_license', $aSrvParams, 'Module', true);
- }
- }
- /** @} */
|