/web/1/000/076/129/313906/htdocs/styroporzuschnitte24_shop/iclear/wrappers/shopware.base.php (21.3 KB)
<?php
/*************************************************************************
$Id: iclear.php 499 2010-10-06 20:33:34Z dis $
iclear payment system - because secure is simply secure
http://www.iclear.de
Copyright (c) 2001 - 2011 iclear - Christian Arnold
Released under the GNU General Public License
************************************************************************
All rights reserved.
This program is free software licensed under the GNU General Public License (GPL).
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*************************************************************************/
class IclearWrapperShopware extends IclearWrapperBase {
var $lang;
// iclear DMI -> added global order var
var $code;
var $title;
var $description;
var $enabled;
var $order;
var $orderStatusID;
var $currentProductID = 0;
var $specialItemID = 0;
var $showPriceTax;
var $otPaymentItemID = 0;
var $_aPaymentID = array();
var $_aPaymentIDName = array();
/**
*
* @var Local_Iclear_Sendorderb2c_Model_Iclearpayment
* @access protected
*/
protected $_payment = null;
/**
*
* @var Mage_Sales_Model_Quote
* @access protected
*/
protected $_system = null;
protected $_basket = null;
protected $_user = null;
protected $_aSession = null;
protected $_DBCon = null;
var $addressKeysMask = array(
'name' => '',
'company' => '',
'street' => 'info',
'region' => '',
'city' => '',
'postcode' => '',
'state' => '',
);
var $addressKeysUnmask = array(
'company',
'street',
'region',
'city',
'postcode',
'state',
);
var $link = null;
protected $_shopID = 0;
protected $bIframe = false;
protected $sBaseURL = "";
protected $sCoreID = "";
// class constructor
function __construct(&$icCore) {
$this->icVersion = '$Id$';
global $icCore;
parent::IclearWrapperBase($icCore);
if(!defined('IC_WRAPPER_ID')) {
die("Wrapper base class 4 oxid not instantiated!\n");
}
$this->id = IC_WRAPPER_ID;
$this->code = 'iclear';
$lang = $icCore->getLanguage();
$this->lang =& $lang;
$this->_installType = 'create';
$this->_aPaymentID = unserialize( IC_SHOPWARE_MODULE_NAME );
foreach ( $this->_aPaymentID as $i_id ) {
$_aID = explode( '_', $i_id );
if ( !empty ( $_aID[2] ) ) {
$this->_aPaymentIDName[] = "_" . strtoupper ( $_aID[2] );
} else {
$this->_aPaymentIDName[] = "";
}
}
}
/**
* Performs a SQL query
* @param string $sql
*/
function dbQuery( $sql = '' ) {
$rs = false;
/*if ( empty( $this->_DBCon ) ) {
try {
$rs = Shopware()->Bootstrap()->getResource('Db')->query ( $sql );
} catch (Exception $e) {
echo 'Exception abgefangen: ', $e->getMessage(), "\n";
}
} else {
try {
$rs = $this->_DBCon->execute( $sql );
} catch (Exception $e) {
echo 'Exception abgefangen: ', $e->getMessage(), "\n";
die("muu");
}
}*/
if ( is_null( $this->link ) ) {
include $this->icCore->getPath() . '/config.php';
$this->link = mysql_connect( $DB_HOST, $DB_USER, $DB_PASSWORD, false );
mysql_select_db( $DB_DATABASE, $this->link );
}
//$rs = mysql_query( mysql_real_escape_string( $sql ), $this->link );
$rs = mysql_query( $sql, $this->link );
if ( $rs ) {
mysql_free_result($rs);
}
return $rs;
}
/**
* Fetch a single record as array from DB
* @param string $sql
*/
function dbFetchRecord( $sql = '' ) {
$rec = false;
/*if( $rs = Shopware()->Bootstrap()->getResource('Db')->query ( $sql ) ) {
$rec = $rs->fetch(PDO::FETCH_ASSOC);
}*/
if ( is_null( $this->link ) ) {
include $this->icCore->getPath() . '/config.php';
$this->link = mysql_connect( $DB_HOST, $DB_USER, $DB_PASSWORD, false );
mysql_select_db( $DB_DATABASE, $this->link );
}
//$rs = mysql_query( mysql_real_escape_string( $sql ), $this->link );
$rs = mysql_query( $sql, $this->link );
if( mysql_num_rows( $rs ) > 0 ) {
$rec = mysql_fetch_array($rs, MYSQL_ASSOC);
}
return $rec;
}
/**
* Last DB insert ID
*/
function dbLastInsertID() {
/*$oDB = oxDb::getDb( true );
return $oDB->Insert_ID( );*/
}
/**
* Entry point of iclear order processing
*/
function process( ) {
if($this->_basket) {
$soap = $this->icCore->getObject('IclearSOAP');
return $this->icCore->perform($soap, IC_SOAP_SENDORDER_METHOD);
}
}
function setShopID ( $shopID ) {
$this->_shopID = $shopID;
}
function setSystem ( $oSystem ) {
$this->_system =& $oSystem;
}
function setPayment ( $oPayment ) {
$this->_payment =& $oPayment;
}
function setBasket ( $oBasket ) {
$this->_basket =& $oBasket;
}
function setUser ( $oUser ) {
$this->_user =& $oUser;
}
function getOrder() {
return $this->_basket;
}
function setDBCon( $oDB ) {
$this->_DBCon =& $oDB;
}
/**
* actual currency ISO3 code, EUR, e.g.
* @return string $currency
*/
function currency() {
$currency = null;
$currency = $this->_system->sCurrency["currency"];
if ( $currency ) {
return $currency;
}
return '';
}
/**
* item count of current order
* @return int $count
*/
function orderItemCount() {
$rv = 0;
if ( $rv = count($this->_basket["content"]) > 0 )
return $rv;
return 0;
}
/**
* next item of current order
* @return array icSoapItem
*/
function nextOrderItem() {
$item = false;
$id =& $this->currentProductID;
$article =& $this->_basket["content"][$id];
if( is_array( $article ) ) {
$item[IC_SOAP_ITEM_NO] = $article["ordernumber"];
$item[IC_SOAP_ITEM_TITLE] = $this->encodeUTF8 ($article["quantity"] . ' x ' . $article["articlename"]);
$item[IC_SOAP_ITEM_QTY] = 1; // bundling items to single article @ iclear
$item[IC_SOAP_ITEM_PRICE_NET] = $article["netprice"] * $article["quantity"];
$item[IC_SOAP_ITEM_PRICE_GROS] = $article["priceNumeric"] * $article["quantity"];
$item[IC_SOAP_ITEM_VAT_RATE] = $this->_system->sMODULES['sArticles']->sGetArticleTaxById($article["articleID"]);
if (!$item[IC_SOAP_ITEM_VAT_RATE]) {
$item[IC_SOAP_ITEM_VAT_RATE] = 19;
}
}
$id++;
return $item;
}
/**
* get all specials items from shop (shipping, coupons) as an array
* of BasketItem formatted arrays
* @return array
*/
function specialItems() {
$items = false;
if ( $this->_basket["sShippingcosts"] ) {
$item[IC_SOAP_ITEM_NO] = $this->specialItemID;
$item[IC_SOAP_ITEM_TITLE] = $this->encodeUTF8( "Versandkosten" );
$item[IC_SOAP_ITEM_PRICE_NET] = $this->_basket["sShippingcostsNet"];
$item[IC_SOAP_ITEM_PRICE_GROS] = $this->_basket["sShippingcosts"];
$item[IC_SOAP_ITEM_QTY] = 1;
$item[IC_SOAP_ITEM_VAT_RATE] = round ( ( ($this->_basket["sShippingcosts"] - $this->_basket["sShippingcostsNet"] ) / $this->_basket["sShippingcostsNet"] ) * 100);
$items[] = $item;
}
return $items;
}
/**
* Get the current delivery address info from shop-system
* @return IclearAddress
*/
function &deliveryAddress( ) {
$rv = false;
if( $this->_user["shippingaddress"] ) {
$params = array(
IC_SOAP_ADDRESS_SALUTATION => $this->encodeUTF8($this->_user["shippingaddress"]["salutation"]),
IC_SOAP_ADDRESS_FIRSTNAME => str_replace ("'", "", $this->encodeUTF8($this->_user["shippingaddress"]["firstname"])),
IC_SOAP_ADDRESS_LASTNAME => str_replace ("'", "", $this->encodeUTF8($this->_user["shippingaddress"]["lastname"])),
IC_SOAP_ADDRESS_COMPANY => $this->encodeUTF8($this->_user["shippingaddress"]["company"]),
IC_SOAP_ADDRESS_STREET => $this->encodeUTF8($this->_user["shippingaddress"]["street"]),
IC_SOAP_ADDRESS_STREET_NO => $this->encodeUTF8($this->_user["shippingaddress"]["streetnumber"]),
IC_SOAP_ADDRESS_ZIPCODE => $this->encodeUTF8($this->_user["shippingaddress"]["zipcode"]),
IC_SOAP_ADDRESS_CITY => $this->encodeUTF8($this->_user["shippingaddress"]["city"]),
IC_SOAP_ADDRESS_COUNTRY => $this->encodeUTF8($this->_user["additional"]["countryShipping"]["countryiso"]),
);
if ( $this->_user["shippingaddress"]["salutation"] == "mr" )
$params[IC_SOAP_ADDRESS_SALUTATION] = 1;
else if ( $this->_user["shippingaddress"]["salutation"] == "ms" )
$params[IC_SOAP_ADDRESS_SALUTATION] = 0;
else
$params[IC_SOAP_ADDRESS_SALUTATION] = -1;
$address = $this->icCore->getObject('IclearAddress', $instance = true);
if($address->address($params)) {
$rv =& $address;
}
}
return $rv;
}
/**
* get the customer register information from shop-system
* as an array, formatted 4 direct usage in soap call
* @return array
*/
function customerInfo() {
$rv = false;
if(!$this->customerInfo) {
if( $this->_user["billingaddress"] ) {
$info = array(
IC_SOAP_REG_CUSTOMER_ACQUISE_ID => 0,
IC_SOAP_REG_CUSTOMER_BANK_ACCOUNT_ID => '',
IC_SOAP_REG_CUSTOMER_BANK_BIC => '',
IC_SOAP_REG_CUSTOMER_BANK_BLZ => '',
IC_SOAP_REG_CUSTOMER_BANK_CUSTOMER => '',
IC_SOAP_REG_CUSTOMER_BANK_IBAN => '',
IC_SOAP_REG_CUSTOMER_BANK_NAME => '',
IC_SOAP_REG_CUSTOMER_COMPANYNAME => $this->encodeUTF8($this->_user["billingaddress"]["company"]),
IC_SOAP_REG_CUSTOMER_EMAIL => $this->encodeUTF8($this->_user["additional"]["user"]["email"]),
IC_SOAP_REG_CUSTOMER_FAX => $this->encodeUTF8($this->_user["billingaddress"]["fax"]),
IC_SOAP_REG_CUSTOMER_FIRSTNAME => str_replace ("'", "", $this->encodeUTF8($this->_user["billingaddress"]["firstname"])),
IC_SOAP_REG_CUSTOMER_DOB => $this->encodeUTF8($this->_user["billingaddress"]["birthday"] . 'T00:00:00'),
IC_SOAP_REG_CUSTOMER_INVOICE_CITY => $this->encodeUTF8($this->_user["billingaddress"]["city"]),
IC_SOAP_REG_CUSTOMER_INVOICE_COUNTRY => $this->encodeUTF8($this->_user["additional"]["country"]["countryiso"]),
IC_SOAP_REG_CUSTOMER_INVOICE_RECEIVER => str_replace ("'", "", $this->encodeUTF8($this->_user["billingaddress"]["firstname"] . ' ' . $this->_user["billingaddress"]["lastname"])),
IC_SOAP_REG_CUSTOMER_INVOICE_STREET => $this->encodeUTF8($this->_user["billingaddress"]["street"]),
IC_SOAP_REG_CUSTOMER_INVOICE_STREETNO => $this->encodeUTF8($this->_user["billingaddress"]["streetnumber"]),
IC_SOAP_REG_CUSTOMER_INVOICE_ZIPCODE => $this->encodeUTF8($this->_user["billingaddress"]["zipcode"]),
IC_SOAP_REG_CUSTOMER_LASTNAME => str_replace ("'", "", $this->encodeUTF8($this->_user["billingaddress"]["lastname"])),
IC_SOAP_REG_CUSTOMER_PHONE => $this->encodeUTF8($this->_user["billingaddress"]["phone"]),
IC_SOAP_REG_CUSTOMER_EXT_CUSTOMER_ID => $this->encodeUTF8($this->_user["billingaddress"]["userID"]),
IC_SOAP_REG_CUSTOMER_NEWSLETTER_FLAG => '',
);
if ( $this->_user["billingaddress"]["salutation"] == "mr" )
$info[IC_SOAP_REG_CUSTOMER_SALUTATION_ID] = 1;
else if ( $this->_user["billingaddress"]["salutation"] == "ms" )
$info[IC_SOAP_REG_CUSTOMER_SALUTATION_ID] = 0;
else
$info[IC_SOAP_REG_CUSTOMER_SALUTATION_ID] = -1;
$this->customerInfo = $info;
}
}
return $this->customerInfo;
}
/**
* get or set session ID
* @param string $sessionID
* @return string $sessionID
*/
function sessionID($sessionID = '') {
return $this->_user["additional"]["user"]["sessionID"];
}
/**
* customerID of current order
* @return int
*/
function customerID() {
$rv = 0;
if($this->_user) {
$rv = $this->_user["additional"]["user"]["id"];
}
return $rv;
}
/**
* get the iclear shopID from config
* @return int
*/
function shopID() {
return $this->_shopID;
}
/**
* language ISO2 code
* @return string
*/
function languageISO() {
return $this->_user["additional"]["user"]["language"];
}
/**
* returns the iclear URL to the iclear login page
* @return string
*/
function iclearURL() {
$rv = '';
$basket = $this->icCore->getBasket();
if($url = $basket->iclearURL()) {
$rv = $basket->iclearURL();
}
return $rv;
}
/**
* obsolete in magento
*/
function finalizeBasket() {
}
/**
* Abstract method which must be implemented in child classes
*/
function storeOrder() {
die("Store order not implemented in enclosing instance!\n");
}
/**
* recreates the delivery and billing information of a order
*/
function unmaskOrder() {
$rc = false;
$basket = $this->icCore->getBasket();
$ordernumber = $basket->orderID();
$paymentState = 12;
if (!empty($ordernumber) && !empty($paymentState)) {
$sql = 'UPDATE s_order SET cleareddate=now(), cleared=? WHERE ordernumber=?';
Shopware()->Bootstrap()->getResource('Db')->query($sql, array($paymentState, $ordernumber));
$rc = true;
}
return $rc;
}
/**
* set the order state 2 cancel
* works only with waiting orders
* @param int $orderID
*/
function cancelOrder($orderID = 0) {
$rc = false;
$basket = $this->icCore->getBasket();
$ordernumber = $basket->orderID();
$paymentState = 35;
$orderState = 4;
if (!empty($ordernumber) && !empty($paymentState) && !empty($orderState)) {
$sql = 'UPDATE s_order SET cleareddate=now(), cleared=?, status=? WHERE ordernumber=?';
Shopware()->Bootstrap()->getResource('Db')->query($sql, array($paymentState, $orderState, $ordernumber));
$rc = true;
}
return $rc;
}
/**
* returns the shopURL where the iclear system redirects the customer finally to
* called from iclear.php processing endpoint
*/
function shopURL() {
$rv = '';
$basket =& $this->icCore->getBasket();
$aSession = $basket->session( );
$baseURL = $aSession['ic_baseURL'];
$coreID = $aSession['ic_coreID'];
$iframe = $aSession['ic_iframe'];
if($basket->orderAccepted()) {
if($basket->status() == IC_ORDER_CANCEL) {
if ( $iframe ) {
//$rv = $baseURL.'/sViewport,sale/sRefererAllowed,1/sCoreId,'.$coreID.'/';
$rv = $baseURL.'/sTarget,checkout/sViewport,account/sAction,payment';
} else {
//$rv = $baseURL.'/sViewport,sale/sRefererAllowed,1/sCoreId,'.$coreID.'/';
$rv = $baseURL.'/sTarget,checkout/sViewport,account/sAction,payment';
}
} else {
$rv = $baseURL.'/engine/connectors/iclear/notify.php?sCoreId='.$coreID . "&transactionID=" . urlencode ( $basket->basketID( ) ) ;
}
} else {
$lang =& $this->icCore->getLanguage();
$soap =& $this->icCore->getObject('IclearSOAP');
$rv = $baseURL.'/engine/connectors/iclear/notify.php?sCoreId='.$coreID . '&error=1';
}
return $rv;
}
/**
* Installs iclear table in DB, if not present
*/
function setup( $clean = true ) {
include $this->icCore->getPath() . '/config.php';
$this->link = mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD, false);
mysql_select_db($DB_DATABASE);
$this->lang->flush();
$this->lang->setLanguage();
$rv = false;
if ( $this->installTable( $clean ) && $this->installPayment( ) && $this->installPaymentConfigs ( ) && $this->installShipping ( ) ) {
$rv = true;
Shopware()->Template()->utility->clearCompiledTemplate(); // Kompilierte Templates l�schen
Shopware()->Cache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('Shopware_Config')); // Konfiguration leeren
}
$this->lang->flush();
$this->lang->setLanguage('de', IC_INSTALL_DIR . 'language/' . 'de' . '.ini');
return $rv;
}
function beforeSessionSave ( ) {
if ( !is_null( $_SESSION ) ) {
$this->_aSession = $_SESSION;
if ( !empty ($this->sBaseURL) && !empty ($this->sCoreID) ) {
$_SESSION['ic_baseURL'] = $this->sBaseURL;
$_SESSION['ic_coreID'] = $this->sCoreID;
$_SESSION['ic_iframe'] = $this->bIframe;
}
}
}
function afterSessionSave ( ) {
if ( !is_null( $this->_aSession ) ) {
$_SESSION = $this->_aSession;
}
}
function installPayment ( ) {
$rc = false;
$sql = "INSERT INTO
s_core_paymentmeans (`name`, `description`, `template`, `class`, `table`, `hide`, `additionaldescription`, `debit_percent`, `surcharge`, `surchargestring`, `position`, `active`, `esdactive`, `embediframe`, `hideprospect`)
VALUES ";
for ($i = 0; $i < count ( $this->_aPaymentID ); $i++ ) {
if ($i != 0) {
$sql .= ", ";
}
$ic_name = strtolower($this->_aPaymentIDName[$i]);
$desc = $this->lang->getParam( 'INFO_EXTENDED' . $this->_aPaymentIDName[$i] );
$desc = str_replace("./iclear/gfx/iclear_module_logo.png", "https://www.iclear.de/fileadmin/images/merchant/iclear_credit80.png", $desc);
$desc = str_replace("./iclear/gfx/iclear_rechnung50.png", "http://www.iclear.de/fileadmin/images/merchant/iclear_rechnung50.png", $desc);
$sql .= "('iclear".$ic_name."', '".mysql_real_escape_string($this->lang->getParam( 'MODULE_TITLE' . $this->_aPaymentIDName[$i] ),$this->link)."', 'iclear.tpl', 'iclear.php', '', 0, '".mysql_real_escape_string($desc,$this->link)."', 0, 0, '', 1, 1, 1, '../../.../../../../../engine/connectors/iclear/form".$ic_name.".php', 0)";
}
$sql .= ";";
if ( $this->dbQuery ( $sql ) ) {
Shopware()->Template()->utility->clearCompiledTemplate(); // Kompilierte Templates l�schen
Shopware()->Cache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('Shopware_Config')); // Konfiguration leeren
$rc = true;
}
return $rc;
}
function installPaymentConfigs ( ) {
$rc = false;
if ( $this->installPaymentConfigsGroup() ) {
$sql = "SELECT * FROM `s_core_config_groups` WHERE `name` LIKE '%iclear%';";
$res = $this->dbFetchRecord ( $sql );
if ( $res['id'] > 0 ) {
$sql = "INSERT INTO s_core_config ( `group` , `name` , `value` , `description` , `required` , `warning` , `detailtext` , `multilanguage`, `fieldtype` )
VALUES
(". $res['id'] . ", 'iICLEARIFRAME', '1', 'iclear iframe mode aktivieren', '1', '', '', '', 'int'),
(" . $res['id'] . ", 'sICLEARSHOPID', '', 'iclear ShopID', '1', '', '', '', 'text');";
if ( $this->dbQuery ( $sql ) ) {
$rc = true;
}
}
}
return $rc;
}
function installPaymentConfigsGroup ( ) {
$rc = false;
$text = mysql_real_escape_string ( $this->lang->getParam( 'INFO_ICLEAR' ) . "<br />", $this->link);
$sql = "INSERT INTO s_core_config_groups ( id , name , position , parent , file , description , action ) VALUES ( NULL , 'iclear Konfiguration', '0', '17', '', '".$text."', '');";
if ( $this->dbQuery ( $sql ) ) {
$rc = true;
}
return $rc;
}
function installShipping ( ) {
$rc = false;
$shippingID = $this->getShippingID( );
$paymentID = $this->getPaymentID( );
if ( $shippingID && $paymentID ) {
$sql = "INSERT INTO s_premium_dispatch_paymentmeans (dispatchID , paymentID) VALUES ('" . $shippingID . "', '" . $paymentID ."');";
if ( $this->dbQuery ( $sql ) ) {
$rc = true;
}
}
return $rc;
}
function getShippingID ( ) {
$rc = false;
$sql = "SELECT id FROM s_premium_dispatch WHERE name LIKE '%Normal Versand%';";
if ( $res = $this->dbFetchRecord ( $sql ) ) {
return $res['id'];
}
return $rc;
}
function getPaymentID ( ) {
$rc = false;
$sql = "SELECT id FROM s_core_paymentmeans WHERE name LIKE '%iclear%';";
if ( $res = $this->dbFetchRecord ( $sql ) ) {
return $res['id'];
}
return $rc;
}
function setBaseURL ( $sBaseURL ) {
$this->sBaseURL = $sBaseURL;
}
function setCoreID ( $sCoreID ) {
$this->sCoreID = $sCoreID;
}
function setInline ( $inline ) {
if ( $inline )
$this->bIframe = true;
else
$this->bIframe = false;
}
function moduleName ( $name ) {
if ( strlen ( $name ) > 1 ) {
$this->module_name = strtoupper( $name );
}
else {
$this->module_name = "";
}
}
function pageparams ( ) {
$Param = array( );
if ( $this->bIframe ) {
$Param['mode'] = 'inline';
}
else {
$Param['mode'] = 'std';
}
return $Param;
}
function paymentType ( ) {
$rv = false;
if ( strlen( $this->module_name ) > 0 ) {
switch ( $this->module_name ) {
case "INVOICE":
$rv = 'bi';
break;
case "CREDITCARD":
$rv = 'cc';
break;
case "ONLINEBANKING":
$rv = 'ob';
break;
case "PREPAYMENT":
$rv = 'ia';
break;
default:
break;
}
}
return $rv;
}
function conditionsAccepted ( ) {
return 1;
}
}
?>