Просмотр исходного кода

Ticket #259 - Payment system: Core changes.

AntonLV 10 лет назад
Родитель
Сommit
4a81b88044

+ 24 - 0
cart.php

@@ -0,0 +1,24 @@
+<?php
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+require_once('./inc/header.inc.php');
+require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
+
+bx_import('BxDolLanguages');
+
+check_logged();
+
+$sUrl = BxDolPayments::getInstance()->getCartUrl();
+if(empty($sUrl))
+	BxDolTemplate::getInstance()->displayPageNotFound();
+
+header('Location: ' . $sUrl);
+exit;
+
+/** @} */

+ 176 - 0
inc/classes/BxDolPayments.php

@@ -0,0 +1,176 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+class BxDolPayments extends BxDol implements iBxDolSingleton
+{
+	protected $_oDb;
+
+	protected $_aObjects;
+	protected $_sActive;
+
+    public 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 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 getProviders($iVendorId, $sProvider = '')
+    {
+    	if(!BxDolRequest::serviceExists($this->_sActive, 'get_providers'))
+    		return array();
+
+    	$aSrvParams = array($iVendorId, $sProvider);
+        return BxDolService::call($this->_sActive, 'get_providers', $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'))
+    		return '';
+
+    	return BxDolService::call($this->_sActive, 'get_orders_url');
+    }
+
+    public function getCartUrl()
+    {
+    	if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_url'))
+    		return '';
+
+    	return BxDolService::call($this->_sActive, 'get_cart_url');
+    }
+
+    public function getCartItems()
+    {
+    	if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_items'))
+    		return MsgBox(_t('_sys_txt_empty'));
+
+    	return BxDolService::call($this->_sActive, 'get_cart_items');
+    }
+
+    public function getCartItemCount($iUserId, $iOldCount = 0)
+    {
+    	if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_item_count'))
+    		return array('count' => 0, 'messages' => array());
+
+		$aSrvParams = array($iUserId, $iOldCount);
+    	return BxDolService::call($this->_sActive, 'get_cart_item_count', $aSrvParams);
+    }
+
+    public function getCartItemDescriptor($iVendorId, $iModuleId, $iItemId, $iItemCount)
+    {
+    	if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_item_descriptor'))
+    		return '';
+
+    	$aSrvParams = array($iVendorId, $iModuleId, $iItemId, $iItemCount);
+		return BxDolService::call($this->_sActive, 'get_cart_item_descriptor', $aSrvParams);
+    }
+    
+    public function getCartJs($bWrapped = true)
+    {
+    	if(!BxDolRequest::serviceExists($this->_sActive, 'get_cart_js'))
+			return '';
+
+		$aSrvParams = array($bWrapped);
+		return BxDolService::call($this->_sActive, 'get_cart_js', $aSrvParams);
+    }
+
+    public function getAddToCartJs($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect = false, $bWrapped = true)
+    {
+    	if(!BxDolRequest::serviceExists($this->_sActive, 'get_add_to_cart_js'))
+			return array();
+
+		$aSrvParams = array($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect, $bWrapped);
+		return BxDolService::call($this->_sActive, 'get_add_to_cart_js', $aSrvParams);
+    }
+
+    public function getAddToCartLink($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect = false)
+    {
+		if(!BxDolRequest::serviceExists($this->_sActive, 'get_add_to_cart_link'))
+			return '';
+
+		$aSrvParams = array($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect);
+		return BxDolService::call($this->_sActive, 'get_add_to_cart_link', $aSrvParams);
+    }
+
+    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);
+    }
+
+	public function prolongSubscription($sOrderId)
+    {
+    	if(!BxDolRequest::serviceExists($this->_sActive, 'prolong_subscription'))
+			return '';
+
+		$aSrvParams = array($sOrderId);
+		return BxDolService::call($this->_sActive, 'prolong_subscription', $aSrvParams);
+    }
+}
+
+/** @} */

+ 32 - 0
inc/classes/BxDolPaymentsQuery.php

@@ -0,0 +1,32 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+/**
+ * @see BxDolPayments
+ */
+class BxDolPaymentsQuery extends BxDolDb
+{
+	public function __construct()
+    {
+    	parent::__construct();
+    }
+
+    public function getObjects()
+    {
+    	$sQuery = $this->prepare("SELECT * FROM `sys_objects_payments` WHERE 1");
+    	
+        $aObjects = $this->getAll($sQuery);
+        if(empty($aObjects) || !is_array($aObjects))
+            return array();
+
+        return $aObjects;
+    }
+}
+
+/** @} */

Разница между файлами не показана из-за своего большого размера
+ 0 - 1
install/sql/system.sql


+ 21 - 0
modules/boonex/air/data/template/system/scripts/BxTemplPaymentsServices.php

@@ -0,0 +1,21 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+/**
+ * @see BxBasePaymentsServices
+ */
+class BxTemplPaymentsServices extends BxBasePaymentsServices
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+}
+
+/** @} */

+ 3 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -79,6 +79,7 @@
 	<string name="_Reset"><![CDATA[Reset]]></string>
 	<string name="_Search"><![CDATA[Search]]></string>
 	<string name="_Section"><![CDATA[Section]]></string>
+	<string name="_Select_one"><![CDATA[Select one...]]></string>
 	<string name="_Select_all"><![CDATA[Select all]]></string>
 	<string name="_Show"><![CDATA[Show]]></string>
 	<string name="_Sorry, your IP been banned"><![CDATA[Sorry, your IP has been banned]]></string>
@@ -1148,6 +1149,8 @@
 	<string name="_adm_stg_cpt_option_sys_cache_memcache_port"><![CDATA[Memcached server port]]></string>
 	<string name="_adm_stg_cpt_option_sys_db_cache_enable"><![CDATA[Enable DB cache]]></string>
 	<string name="_adm_stg_cpt_option_sys_db_cache_engine"><![CDATA[DB cache engine (other than File option may require custom server setup)]]></string>
+	<string name="_adm_stg_cpt_option_sys_default_payment"><![CDATA[Payment module]]></string>
+	<string name="_adm_stg_err_option_sys_default_payment"><![CDATA[You need to install at least one payment processing module and activate it here by selecting from the list.]]></string>
 	<string name="_adm_stg_cpt_option_sys_format_date"><![CDATA[Date Format]]></string>
 	<string name="_adm_stg_cpt_option_sys_format_datetime"><![CDATA[Datetime Format]]></string>
 	<string name="_adm_stg_cpt_option_sys_format_time"><![CDATA[Time Format]]></string>

+ 21 - 0
modules/boonex/lagoon/data/template/system/scripts/BxTemplPaymentsServices.php

@@ -0,0 +1,21 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+/**
+ * @see BxBasePaymentsServices
+ */
+class BxTemplPaymentsServices extends BxBasePaymentsServices
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+}
+
+/** @} */

+ 21 - 0
modules/boonex/ocean/data/template/system/scripts/BxTemplPaymentsServices.php

@@ -0,0 +1,21 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+/**
+ * @see BxBasePaymentsServices
+ */
+class BxTemplPaymentsServices extends BxBasePaymentsServices
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+}
+
+/** @} */

+ 3 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -79,6 +79,7 @@
 	<string name="_Reset"><![CDATA[Сбросить]]></string>
 	<string name="_Search"><![CDATA[Поиск]]></string>
 	<string name="_Section"><![CDATA[Отдел]]></string>
+	<string name="_Select_one"><![CDATA[Выберите один...]]></string>
 	<string name="_Select_all"><![CDATA[Выбрать всё]]></string>
 	<string name="_Show"><![CDATA[Показать]]></string>
 	<string name="_Sorry, your IP been banned"><![CDATA[Извините, Ваш IP был забанен]]></string>
@@ -1148,6 +1149,8 @@
 	<string name="_adm_stg_cpt_option_sys_cache_memcache_port"><![CDATA[Memcached - порт сервера]]></string>
 	<string name="_adm_stg_cpt_option_sys_db_cache_enable"><![CDATA[Задействовать кэш БД]]></string>
 	<string name="_adm_stg_cpt_option_sys_db_cache_engine"><![CDATA[Кэш-движок для БД (значение, отличное от File, может потребовать дополнительной настройки сервера)]]></string>
+	<string name="_adm_stg_cpt_option_sys_default_payment"><![CDATA[Модуль оплаты]]></string>
+	<string name="_adm_stg_err_option_sys_default_payment"><![CDATA[Вам нужно установить как минимум один модуль для обработки проплат и активировать его, выбрав из списка.]]></string>
 	<string name="_adm_stg_cpt_option_sys_format_date"><![CDATA[Формат Даты]]></string>
 	<string name="_adm_stg_cpt_option_sys_format_datetime"><![CDATA[Формат Даты и Времени]]></string>
 	<string name="_adm_stg_cpt_option_sys_format_time"><![CDATA[Формат Времени]]></string>

+ 24 - 0
orders.php

@@ -0,0 +1,24 @@
+<?php
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+require_once('./inc/header.inc.php');
+require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
+
+bx_import('BxDolLanguages');
+
+check_logged();
+
+$sUrl = BxDolPayments::getInstance()->getOrdersUrl();
+if(empty($sUrl))
+	BxDolTemplate::getInstance()->displayPageNotFound();
+
+header('Location: ' . $sUrl);
+exit;
+
+/** @} */

+ 26 - 0
template/scripts/BxBasePaymentsServices.php

@@ -0,0 +1,26 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+/**
+ * System services related to Payments.
+ */
+class BxBasePaymentsServices extends BxDol
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    public function serviceGetPayments()
+    {
+        return BxDolPayments::getInstance()->getPayments();
+    }
+}
+
+/** @} */

Некоторые файлы не были показаны из-за большого количества измененных файлов