Quellcode durchsuchen

#259 - Payment system: Base module.

AntonLV vor 10 Jahren
Ursprung
Commit
fc1c312632

+ 98 - 0
modules/base/payment/classes/BxBaseModPaymentCart.php

@@ -0,0 +1,98 @@
+<?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    BasePayment Base classes for Payment like modules
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+class BxBaseModPaymentCart extends BxDol
+{
+	protected $MODULE;
+	protected $_oModule;
+
+	function __construct()
+    {
+        parent::__construct();
+
+        $this->_oModule = BxDolModule::getInstance($this->MODULE);
+    }
+
+	public function serviceGetCartLink()
+    {
+    	if(!$this->_oModule->isLogged())
+            return '';
+
+    	return $this->_oModule->_oConfig->getUrl('cart');
+    }
+
+    public function serviceGetCartJs($bWrapped = true)
+    {
+        return $this->_oModule->_oTemplate->displayCartJs($bWrapped);
+    }
+
+	public function serviceGetAddToCartLink($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect = false)
+    {
+        $iModuleId = $this->_oModule->_oConfig->getModuleId($mixedModuleId);
+        if(empty($iModuleId))
+            return '';
+
+		return $this->_oModule->_oTemplate->displayAddToCartLink($iVendorId, $iModuleId, $iItemId, $iItemCount, $bNeedRedirect);
+    }
+
+    public function serviceGetAddToCartJs($iVendorId, $mixedModuleId, $iItemId, $iItemCount, $bNeedRedirect = false, $bWrapped = true)
+    {
+		$iModuleId = $this->_oModule->_oConfig->getModuleId($mixedModuleId);
+        if(empty($iModuleId))
+            return '';
+
+        return $this->_oModule->_oTemplate->displayAddToCartJs($iVendorId, $iModuleId, $iItemId, $iItemCount, $bNeedRedirect, $bWrapped);
+    }
+
+	public function serviceGetCartItemDescriptor($iVendorId, $iModuleId, $iItemId, $iItemCount)
+	{
+		return $this->_oModule->_oConfig->descriptorA2S(array($iVendorId, $iModuleId, $iItemId, $iItemCount));
+	}
+
+    public function serviceGetCartItemsCount($iUserId = 0)
+    {
+    	$iUserId = !empty($iUserId) ? $iUserId : $this->_oModule->getProfileId();
+        if(empty($iUserId))
+            return 0;
+
+        $aInfo = $this->getInfo($iUserId);
+
+        $iCount = 0;
+        foreach($aInfo as $iVendorId => $aVendorCart)
+            $iCount += $aVendorCart['items_count'];
+
+        return $iCount;
+    }
+
+	protected function _parseByVendor($iUserId)
+    {
+        $sItems = $this->_oModule->_oDb->getCartItems($iUserId);
+        return $this->_reparseBy($this->_oModule->_oConfig->descriptorsM2A($sItems), 'vendor_id');
+    }
+
+    protected function _parseByModule($iUserId)
+    {
+        $sItems = $this->_oModule->_oDb->getCartItems($iUserId);
+        return $this->_reparseBy($this->_oModule->_oConfig->descriptorsM2A($sItems), 'module_id');
+    }
+
+	protected function _reparseBy($aItems, $sKey)
+    {
+        $aResult = array();
+        foreach($aItems as $aItem)
+            if(isset($aItem[$sKey]))
+                $aResult[$aItem[$sKey]][] = $aItem;
+
+        return $aResult;
+    }
+}
+
+/** @} */

+ 161 - 0
modules/base/payment/classes/BxBaseModPaymentConfig.php

@@ -0,0 +1,161 @@
+<?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    BasePayment Base classes for Payment like modules
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+class BxBaseModPaymentConfig extends BxBaseModGeneralConfig
+{
+	protected $_oDb;
+
+	protected $_iSiteId;
+	protected $_sCurrencySign;
+    protected $_sCurrencyCode;
+
+    protected $_aKeys;
+    protected $_aUrls;
+    protected $_aDividers;
+
+    protected $_aPerPage;
+    protected $_aHtmlIds;
+
+    protected $_sAnimationEffect;
+    protected $_iAnimationSpeed;
+
+    function __construct($aModule)
+    {
+        parent::__construct($aModule);
+
+        $this->_aKeys = array(
+        	'session_key_pending' => $this->_sName . '_pending_id',
+        	'request_key_pending' => $this->_sName . '_pending_id'
+        );
+
+        $this->_aUrls = array();
+
+        $this->_aDividers = array(
+        	'descriptor' => '_',
+        	'descriptors' => ':'
+        );
+
+		$this->_aPrefixes = array(
+			'general' => $this->_sName . '_',
+			'langs' => '_' . $this->_sName . '_',
+        	'options' => $this->_sName . '_'
+		);
+
+		$this->_aObjects = array_merge($this->_aObjects, array(
+			'form_pendings' => $this->_sName . '_form_pendings',
+			'form_processed' => $this->_sName . '_form_processed',
+			'display_pendings_process' => $this->_sName . '_form_pendings_process',
+			'display_processed_add' => $this->_sName . '_form_processed_add',
+
+			'menu_cart_submenu' => $this->_sName . '_menu_cart_submenu',
+        	'menu_orders_submenu' => $this->_sName . '_menu_orders_submenu',
+
+			'grid_history' => $this->_sName . '_grid_orders_history',
+			'grid_processed' => $this->_sName . '_grid_orders_processed',
+			'grid_pending' => $this->_sName . '_grid_orders_pending'
+		));
+
+		$this->_aPerPage = array();
+		$this->_aHtmlIds = array();
+
+		$this->_sAnimationEffect = 'fade';
+        $this->_iAnimationSpeed = 'slow';
+    }
+
+    public function init(&$oDb)
+    {
+    	$this->_oDb = $oDb;
+    	
+    	$sPrefix = $this->getPrefix('options');
+        $this->_iSiteId = (int)$this->_oDb->getParam($sPrefix . 'site_admin');
+        $this->_sCurrencySign = $this->_oDb->getParam($sPrefix . 'default_currency_sign');
+        $this->_sCurrencyCode = $this->_oDb->getParam($sPrefix . 'default_currency_code');
+    }
+
+    public function getSiteId()
+    {
+        if(empty($this->_iSiteId))
+            return $this->_oDb->getFirstAdminId();
+
+        return $this->_iSiteId;
+    }
+
+    public function getCurrencySign()
+    {
+        return $this->_sCurrencySign;
+    }
+
+    public function getCurrencyCode()
+    {
+        return $this->_sCurrencyCode;
+    }
+
+	public function getKey($sType)
+    {
+    	if(empty($sType))
+            return $this->_aKeys;
+
+        return isset($this->_aKeys[$sType]) ? $this->_aKeys[$sType] : '';
+    }
+
+    public function getUrl($sType, $aParams = array(), $bSsl = false)
+    {
+    	if(empty($sType))
+            return $this->_aUrls;
+
+		$sResult = '';
+		if(!isset($this->_aUrls[$sType]))
+			return $sResult;
+
+		if(strncmp($this->_aUrls[$sType], BX_DOL_URL_ROOT, strlen(BX_DOL_URL_ROOT)) == 0)
+			$sResult = bx_append_url_params($this->_aUrls[$sType], $aParams);
+		else
+			$sResult = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($this->_aUrls[$sType], $aParams);
+
+    	return $bSsl ? $this->http2https($sResult) : $sResult;
+    }
+
+	public function getDivider($sType)
+    {
+    	if(empty($sType))
+            return $this->_aDividers;
+
+        return isset($this->_aDividers[$sType]) ? $this->_aDividers[$sType] : '';
+    }
+
+	public function getPerPage($sType = 'default')
+    {
+    	if(empty($sType))
+            return $this->_aPerPage;
+
+        return isset($this->_aPerPage[$sType]) ? $this->_aPerPage[$sType] : '';
+    }
+
+	public function getHtmlIds($sType, $sKey = '')
+    {
+        if(empty($sKey))
+            return isset($this->_aHtmlIds[$sType]) ? $this->_aHtmlIds[$sType] : array();
+
+        return isset($this->_aHtmlIds[$sType][$sKey]) ? $this->_aHtmlIds[$sType][$sKey] : '';
+    }
+
+    public function getAnimationEffect()
+    {
+        return $this->_sAnimationEffect;
+    }
+
+	public function getAnimationSpeed()
+    {
+        return $this->_iAnimationSpeed;
+    }
+}
+
+/** @} */

+ 46 - 0
modules/base/payment/classes/BxBaseModPaymentDb.php

@@ -0,0 +1,46 @@
+<?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    BasePayment Base classes for Payment like modules
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+class BxBaseModPaymentDb extends BxBaseModGeneralDb
+{
+    function __construct(&$oConfig)
+    {
+        parent::__construct($oConfig);
+    }
+
+	public function insertModule($aData)
+    {
+    	$sQuery = $this->prepare("INSERT IGNORE INTO `" . $this->_sPrefix . "modules`(`name`) VALUES(?)", $aData['name']);
+		$this->query($sQuery);
+    }
+
+    public function deleteModule($aData)
+    {
+    	$sQuery = $this->prepare("DELETE FROM `" . $this->_sPrefix . "modules` WHERE `name`=? LIMIT 1", $aData['name']);
+    	$this->query($sQuery);
+    }
+
+    public function getModules()
+    {
+        $sQuery = $this->prepare("SELECT
+				`tsm`.`id` AS `id`,
+				`tm`.`name` AS `name`,
+				`tsm`.`title` AS `title`,
+				`tsm`.`uri` AS `uri`
+            FROM `" . $this->_sPrefix . "modules` AS `tm`
+            LEFT JOIN `sys_modules` AS `tsm` ON `tm`.`name`=`tsm`.`name`
+            ORDER BY `tsm`.`date`");
+
+        return $this->getAll($sQuery);
+    }
+}
+
+/** @} */

+ 119 - 0
modules/base/payment/classes/BxBaseModPaymentGridOrders.php

@@ -0,0 +1,119 @@
+<?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    BasePayment Base classes for Payment like modules
+ * @ingroup     TridentModules
+ * 
+ * @{
+ */
+
+class BxBaseModPaymentGridOrders extends BxTemplGrid
+{
+	protected $MODULE;
+	protected $_oModule;
+
+	protected $_sOrdersType;
+
+	protected $_sLangsPrefix;
+	protected $_sCurrencySign;
+
+    public function __construct ($aOptions, $oTemplate = false)
+    {
+        parent::__construct ($aOptions, $oTemplate);
+
+        $this->_oModule = BxDolModule::getInstance($this->MODULE);
+
+        $this->_sLangsPrefix = $this->_oModule->_oConfig->getPrefix('langs');
+        $this->_sCurrencySign = $this->_oModule->_oConfig->getCurrencySign();
+
+        $this->_sDefaultSortingOrder = 'DESC';
+
+	    $iSellerId = bx_get('seller_id');
+        if($iSellerId !== false)
+            $this->_aQueryAppend['seller_id'] = (int)$iSellerId;
+
+	    $iClientId = bx_get('client_id');
+        if($iClientId !== false)
+            $this->_aQueryAppend['client_id'] = (int)$iClientId;
+    }
+
+    public function addQueryParam($sKey, $sValue)
+    {
+    	if(empty($sKey) || !isset($sValue))
+    		return;
+
+		$this->_aQueryAppend[$sKey] = $sValue;
+    }
+
+    public function performActionViewOrder()
+    {
+    	$aIds = bx_get('ids');
+        if(!$aIds || !is_array($aIds)) 
+        	return echoJson(array());
+
+        $iId = (int)$aIds[0];
+
+        $sKey = 'order_' . $this->_sOrdersType . '_view';
+    	$sId = $this->_oModule->_oConfig->getHtmlIds($sKey);
+    	$sTitle = _t($this->_sLangsPrefix . 'grid_orders_popup_' . $sKey);
+    	$sContent = $this->_oModule->getObjectOrders()->getOrder($this->_sOrdersType, $iId);
+
+    	return echoJson(array('popup' => BxTemplFunctions::getInstance()->popupBox($sId, $sTitle, $sContent)));
+    }
+
+    public function performActionCancel()
+    {
+    	$aIds = bx_get('ids');
+        if(!$aIds || !is_array($aIds)) 
+        	return echoJson(array());
+
+		$oOrders = $this->_oModule->getObjectOrders();
+
+		$iAffected = 0;
+		$aAffected = array();
+		foreach($aIds as $iId)
+			if($oOrders->cancel($this->_sOrdersType, $iId)) {
+				$aAffected[] = $iId;
+            	$iAffected++;
+			}
+
+        echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aAffected) : array('msg' => _t($this->_sLangsPrefix . 'err_cannot_perform')));
+    }
+
+	protected function _getCellClientId($mixedValue, $sKey, $aField, $aRow)
+    {
+    	return parent::_getCellDefault($this->_toProfile($mixedValue), $sKey, $aField, $aRow);
+    }
+
+	protected function _getCellSellerId($mixedValue, $sKey, $aField, $aRow)
+    {
+    	return parent::_getCellDefault($this->_toProfile($mixedValue), $sKey, $aField, $aRow);
+    }
+
+	protected function _getCellAmount($mixedValue, $sKey, $aField, $aRow)
+    {
+        return parent::_getCellDefault($this->_sCurrencySign . $mixedValue, $sKey, $aField, $aRow);
+    }
+
+	protected function _getCellDate($mixedValue, $sKey, $aField, $aRow)
+    {
+        return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
+    }
+
+    protected function _toProfile($mixedValue)
+    {
+    	$aProfile = $this->_oModule->getProfileInfo((int)$mixedValue);
+
+    	return $this->_oModule->_oTemplate->parseHtmlByName('profile_link.html', array(
+            'href' => $aProfile['link'],
+            'title' => bx_html_attribute($aProfile['name']),
+            'content' => $aProfile['name']
+        ));
+    }
+    
+    
+}
+
+/** @} */

+ 25 - 0
modules/base/payment/classes/BxBaseModPaymentJoin.php

@@ -0,0 +1,25 @@
+<?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    BasePayment Base classes for Payment like modules
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+class BxBaseModPaymentJoin extends BxDol
+{
+	protected $MODULE;
+	protected $_oModule;
+
+	function __construct()
+    {
+        parent::__construct();
+
+        $this->_oModule = BxDolModule::getInstance($this->MODULE);
+    }
+}
+
+/** @} */

+ 185 - 0
modules/base/payment/classes/BxBaseModPaymentModule.php

@@ -0,0 +1,185 @@
+<?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    BasePayment Base classes for Payment like modules
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+class BxBaseModPaymentModule extends BxDolModule
+{
+	protected $_sLangsPrefix;
+
+	function __construct($aModule)
+    {
+        parent::__construct($aModule);
+
+        $this->_oConfig->init($this->_oDb);
+
+        $this->_sLangsPrefix = $this->_oConfig->getPrefix('langs');
+    }
+
+	public function serviceUpdateDependentModules($sModule = 'all', $bInstall = true)
+    {
+    	$aModules = $sModule == 'all' ? $this->_oDb->getModulesBy(array('type' => 'modules')) : array($this->_oDb->getModuleByName($sModule));
+
+        foreach($aModules as $aModule) {
+        	$mixedData = $this->callGetPaymentData($aModule['name']);
+        	if($mixedData === false)
+        		continue;
+
+			$sMethodName = $bInstall ? 'insertModule' : 'deleteModule';
+			$this->_oDb->$sMethodName($mixedData);
+        }
+    }
+
+    public function serviceGetCurrencyInfo()
+    {
+        return array(
+            'sign' => $this->_oConfig->getCurrencySign(),
+            'code' => $this->_oConfig->getCurrencyCode()
+        );
+    }
+
+	public function serviceGetOption($sOption)
+    {
+    	return $this->_oDb->getParam($this->_oConfig->getPrefix('options') . $sOption);
+    }
+
+	public function serviceGetProviders($iVendorId, $sProvider = '')
+	{
+		$aVendorProviders = $this->_oDb->getVendorInfoProviders($iVendorId, $sProvider);
+
+		$aResult = array();
+		foreach($aVendorProviders as $aProvider) {
+			$aProvider['caption_cart'] = _t($this->_sLangsPrefix . 'txt_cart_' . $aProvider['name']);
+
+			$aResult[] = $aProvider;
+		}
+
+		return $aResult;
+	}
+
+	public function getVendorInfo($iUserId)
+    {
+        return array_merge($this->getProfileInfo($iUserId), array(
+        	'currency_code' => $this->_oConfig->getCurrencyCode(),
+			'currency_sign' => $this->_oConfig->getCurrencySign()
+        ));
+    }
+
+    public function getProfileId()
+    {
+    	return bx_get_logged_profile_id();
+    }
+
+	public function getProfileInfo($iUserId = 0)
+    {
+        $oProfile = $this->getObjectUser($iUserId);
+
+        return array(
+        	'id' => $iUserId,
+            'name' => $oProfile->getDisplayName(),
+            'link' => $oProfile->getUrl(),
+            'icon' => $oProfile->getIcon(),
+            'unit' => $oProfile->getUnit(),
+        	'active' => $oProfile->isActive(),
+        );
+    }
+    
+    public function getObjectUser($iUserId = 0)
+    {
+    	bx_import('BxDolProfile');
+        $oProfile = BxDolProfile::getInstance($iUserId);
+        if (!$oProfile) {
+            bx_import('BxDolProfileUndefined');
+            $oProfile = BxDolProfileUndefined::getInstance();
+        }
+
+        return $oProfile;
+    }
+
+	public function getObjectJoin()
+    {
+        $sClassName = $this->_oConfig->getClassPrefix() . 'Join';
+        if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
+        	bx_import('Join', $this->_aModule);
+            $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
+        }
+
+        return $GLOBALS['bxDolClasses'][$sClassName];
+    }
+
+	public function getObjectCart()
+    {
+        $sClassName = $this->_oConfig->getClassPrefix() . 'Cart';
+        if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
+        	bx_import('Cart', $this->_aModule);
+            $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
+        }
+
+        return $GLOBALS['bxDolClasses'][$sClassName];
+    }
+
+    public function getObjectOrders()
+    {
+    	$sClassName = $this->_oConfig->getClassPrefix() . 'Orders';
+        if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
+        	bx_import('Orders', $this->_aModule);
+            $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
+        }
+
+        return $GLOBALS['bxDolClasses'][$sClassName];
+    }
+
+	public function getObjectDetails()
+    {
+    	$sClassName = $this->_oConfig->getClassPrefix() . 'Details';
+        if(!isset($GLOBALS['bxDolClasses'][$sClassName])) {
+        	bx_import('Details', $this->_aModule);
+            $GLOBALS['bxDolClasses'][$sClassName] = new $sClassName();
+        }
+
+        return $GLOBALS['bxDolClasses'][$sClassName];
+    }
+
+	public function getObjectProvider($sProvider, $mixedVendorId = BX_PAYMENT_EMPTY_ID)
+	{
+		$aProvider = is_numeric($mixedVendorId) && (int)$mixedVendorId != BX_PAYMENT_EMPTY_ID ? $this->_oDb->getVendorInfoProviders((int)$mixedVendorId, $sProvider) : $this->_oDb->getProviders($sProvider);
+        $sClassPath = !empty($aProvider['class_file']) ? BX_DIRECTORY_PATH_ROOT . $aProvider['class_file'] : $this->_oConfig->getClassPath() . $aProvider['class_name'] . '.php';
+        if(empty($aProvider) || !file_exists($sClassPath))
+        	return false;
+
+        require_once($sClassPath);
+        return new $aProvider['class_name']($aProvider);
+	}
+
+    public function callGetPaymentData($mixedModule)
+    {
+    	$sMethod = 'get_payment_data';
+		if(!BxDolRequest::serviceExists($mixedModule, $sMethod)) 
+			return false;
+
+		return BxDolService::call($mixedModule, $sMethod);
+    }
+
+    public function callGetCartItem($mixedModule, $aParams)
+    {
+    	return BxDolService::call($mixedModule, 'get_cart_item', $aParams);
+    }
+
+    public function callGetCartItems($mixedModule, $aParams)
+    {
+    	return BxDolService::call($mixedModule, 'get_cart_items', $aParams);
+    }
+
+    public function callRegisterCartItem($mixedModule, $aParams)
+    {
+    	return BxDolService::call($mixedModule, 'register_cart_item', $aParams);
+    }
+}
+
+/** @} */

+ 33 - 0
modules/base/payment/classes/BxBaseModPaymentOrders.php

@@ -0,0 +1,33 @@
+<?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    BasePayment Base classes for Payment like modules
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+class BxBaseModPaymentOrders extends BxDol
+{
+	protected $MODULE;
+	protected $_oModule;
+
+	function __construct()
+    {
+        parent::__construct();
+
+        $this->_oModule = BxDolModule::getInstance($this->MODULE);
+    }
+
+	public function serviceGetOrdersLink()
+    {
+    	if(!$this->_oModule->isLogged())
+            return '';
+
+    	return $this->_oModule->_oConfig->getUrl('orders');
+    }
+}
+
+/** @} */

+ 73 - 0
modules/base/payment/classes/BxBaseModPaymentProvider.php

@@ -0,0 +1,73 @@
+<?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    BasePayment Base classes for Payment like modules
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+interface iBxBaseModPaymentProvider
+{
+	public function initializeCheckout($iPendingId, $aCartInfo, $bRecurring = false, $iRecurringDays = 0);
+    public function finalizeCheckout(&$aData);
+    public function checkoutFinished();
+}
+
+class BxBaseModPaymentProvider extends BxDol
+{
+	protected $MODULE;
+	protected $_oModule;
+
+	protected $_sLangsPrefix;
+
+    protected $_iId;
+    protected $_sName;
+    protected $_sCaption;
+    protected $_sPrefix;
+    protected $_aOptions;
+    protected $_bRedirectOnResult;
+
+    function __construct($aConfig)
+    {
+        parent::__construct();
+
+        $this->_oModule = BxDolModule::getInstance($this->MODULE);
+
+        $this->_sLangsPrefix = $this->_oModule->_oConfig->getPrefix('langs');
+
+        $this->_iId = (int)$aConfig['id'];
+        $this->_sName = $aConfig['name'];
+        $this->_sCaption = _t($aConfig['caption']);
+        $this->_sPrefix = $aConfig['option_prefix'];
+        $this->_aOptions = !empty($aConfig['options']) ? $aConfig['options'] : array();
+        $this->_bRedirectOnResult = false;
+    }
+
+    /**
+     * TODO: Check whether the method is needed or not. 
+     * Is used on success only.
+     */
+	public function needRedirect()
+    {
+        return $this->_bRedirectOnResult;
+    }
+
+    protected function getOptionsByPending($iPendingId)
+    {
+        $aPending = $this->_oModule->_oDb->getPending(array(
+            'type' => 'id',
+            'id' => (int)$iPendingId
+        ));
+        return $this->_oModule->_oDb->getOptions((int)$aPending['seller_id'], $this->_iId);
+    }
+
+    protected function getOption($sName)
+    {
+        return isset($this->_aOptions[$this->_sPrefix . $sName]) ? $this->_aOptions[$this->_sPrefix . $sName]['value'] : "";
+    }
+}
+
+/** @} */

+ 112 - 0
modules/base/payment/classes/BxBaseModPaymentTemplate.php

@@ -0,0 +1,112 @@
+<?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    BasePayment Base classes for Payment like modules
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+class BxBaseModPaymentTemplate extends BxBaseModGeneralTemplate
+{
+    function __construct($oConfig, $oDb)
+    {
+        parent::__construct($oConfig, $oDb);
+    }
+
+	public function displayJsCode($sType, $aParams = array(), $aRequestParams = array())
+    {
+    	$sJsClass = $this->_oConfig->getJsClass($sType);
+    	$sJsObject = $this->_oConfig->getJsObject($sType);
+
+    	$aParams = array_merge(array(
+    		'sActionUrl' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri(), 
+    		'sObjName' => $sJsObject,
+    		'sAnimationEffect' => $this->_oConfig->getAnimationEffect(),
+    		'iAnimationSpeed' => $this->_oConfig->getAnimationSpeed(),
+    		'aHtmlIds' => $this->_oConfig->getHtmlIds($sType),
+    		'oRequestParams' => $aRequestParams
+    	), $aParams);
+
+        return $this->_wrapInTagJsCode("var " . $sJsObject . " = new " . $sJsClass . "(" . json_encode($aParams) . ");");
+    }
+
+	public function displayPageCode(&$aParams)
+    {
+		check_logged();
+		$oTemplate = BxDolTemplate::getInstance();
+
+        $iIndex = isset($aParams['index']) ? (int)$aParams['index'] : BX_PAGE_DEFAULT;
+        $oTemplate->setPageNameIndex($iIndex);
+
+        if(isset($aParams['js']))
+			$oTemplate->addJs($aParams['js']);
+		if(isset($aParams['css']))
+			$oTemplate->addCss($aParams['css']);
+
+		if(isset($aParams['title']['page']))
+            $oTemplate->setPageHeader($aParams['title']['page']);
+        if(isset($aParams['title']['block']))
+         	$oTemplate->setPageParams(array('header_text' => $aParams['title']['block']));
+
+        if(isset($aParams['content']))
+            foreach($aParams['content'] as $sKey => $sValue)
+            	$oTemplate->setPageContent($sKey, $sValue);
+
+		$oTemplate->getPageCode();
+    }
+
+	public function displayPageCodeResponse($sMessage, $bWrap = true)
+    {
+		$aParams = array(
+            'title' => array(
+                'page' => _t($this->_sLangsPrefix . 'page_title_response')
+            ),
+            'content' => array(
+                'page_main_code' => $bWrap ? MsgBox(_t($sMessage)) : $sMessage
+            )
+        );
+        $this->displayPageCode($aParams);
+    }
+
+    public function displayPageCodeError($sMessage, $bWrap = true)
+    {
+		$aParams = array(
+            'title' => array(
+                'page' => _t($this->_sLangsPrefix . 'page_title_error')
+            ),
+            'content' => array(
+                'page_main_code' => $bWrap ? MsgBox(_t($sMessage)) : $sMessage
+            )
+        );
+        $this->displayPageCode($aParams);
+    }
+
+    public function displayPageCodeRedirect($sUrl, $aData = array(), $sMethod = 'post', $sMessage = '', $bWrap = true)
+    {
+    	if(empty($sMessage))
+    		$sMessage = $this->_sLangsPrefix . 'msg_redirecting';
+
+    	$aTmplVarsData = array();
+    	if(!empty($aData) && is_array($aData))
+    		foreach($aData as $sKey => $mixedValue)
+    			$aTmplVarsData[] = array('name' => bx_html_attribute($sKey), 'value' => bx_html_attribute($mixedValue));
+
+    	$aParams = array(
+    		'index' => BX_PAGE_CLEAR,
+    		'content' => array(
+                'page_main_code' => $this->parseHtmlByName('redirect.html', array(
+    				'content' => $bWrap ? MsgBox(_t($sMessage)) : $sMessage,
+    				'action' => $sUrl,
+    				'method' => $sMethod,
+    				'bx_repeat:items' => $aTmplVarsData
+    			))
+    		)
+    	);
+    	$this->displayPageCode($aParams);
+    }
+}
+
+/** @} */