oxpayment.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxPayment extends oxI18n
00008 {
00014     protected $_oGroups = null;
00015 
00022     protected $_aCountries = null;
00023 
00029     protected $_sClassName = 'oxpayment';
00030 
00036     protected $_aDynValues = null;
00037 
00043     protected $_iPaymentError = null;
00044 
00048     public function __construct()
00049     {
00050         parent::__construct();
00051         $this->init( 'oxpayments' );
00052     }
00053 
00059     public function getGroups()
00060     {
00061         if ( $this->_oGroups == null && ( $sOxid = $this->getId() ) ) {
00062 
00063             // usergroups
00064             $this->_oGroups = oxNew( 'oxlist', 'oxgroups' );
00065 
00066             // performance
00067             $sSelect  = 'select oxgroups.* from oxgroups, oxobject2group ';
00068             $sSelect .= "where oxobject2group.oxobjectid = '$sOxid' ";
00069             $sSelect .= 'and oxobject2group.oxgroupsid=oxgroups.oxid ';
00070             $this->_oGroups->selectString( $sSelect );
00071         }
00072 
00073         return $this->_oGroups;
00074     }
00075 
00083     public function setDynValues( $aDynValues )
00084     {
00085         $this->_aDynValues = $aDynValues;
00086     }
00087 
00096     public function setDynValue( $oKey, $oVal )
00097     {
00098         $this->_aDynValues[$oKey] = $oVal;
00099     }
00100 
00106     public function getDynValues()
00107     {
00108         if ( !$this->_aDynValues ) {
00109             $sRawDynValue = null;
00110             if ( is_object($this->oxpayments__oxvaldesc ) ) {
00111                 $sRawDynValue = $this->oxpayments__oxvaldesc->getRawValue();
00112             }
00113 
00114             $this->_aDynValues = oxUtils::getInstance()->assignValuesFromText( $sRawDynValue );
00115         }
00116         return $this->_aDynValues;
00117     }
00118 
00126     public function getPaymentValue( $dBaseprice )
00127     {
00128         $dRet = 0;
00129 
00130         if ( $this->oxpayments__oxaddsumtype->value == "%") {
00131             $dRet = $dBaseprice * $this->oxpayments__oxaddsum->value/100;
00132         } else {
00133             $oCur = $this->getConfig()->getActShopCurrencyObject();
00134             $dRet = $this->oxpayments__oxaddsum->value * $oCur->rate;
00135         }
00136 
00137         if ( ($dRet * -1 ) > $dBaseprice ) {
00138             $dRet = $dBaseprice;
00139         }
00140 
00141         return $dRet;
00142     }
00143 
00151     public function getPaymentPrice( $oBasket )
00152     {
00153         //getting basket price with applied discounts and vouchers
00154         $dBasketPrice = $oBasket->getPriceForPayment();
00155         $dPrice = $this->getPaymentValue( $dBasketPrice );
00156 
00157         // calculating total price
00158         $oPrice = oxNew( 'oxPrice' );
00159         $oPrice->setBruttoPriceMode();
00160         $oPrice->setPrice( $dPrice );
00161 
00162         if ( $this->getConfig()->getConfigParam( 'blCalcVATForPayCharge' ) && $dPrice > 0 ) {
00163             $oPrice->setVat( $oBasket->getMostUsedVatPercent() );
00164         }
00165 
00166         return $oPrice;
00167     }
00168 
00174     public function getCountries()
00175     {
00176         if ( $this->_aCountries === null ) {
00177 
00178             $this->_aCountries = array();
00179             $sSelect = 'select oxobjectid from oxobject2payment where oxpaymentid="'.$this->getId().'" and oxtype = "oxcountry" ';
00180             $rs = oxDb::getDb()->Execute( $sSelect );
00181             if ( $rs && $rs->recordCount()) {
00182                 while ( !$rs->EOF ) {
00183                     $this->_aCountries[] = $rs->fields[0];
00184                     $rs->moveNext();
00185                 }
00186             }
00187         }
00188         return $this->_aCountries;
00189     }
00190 
00198     public function delete( $sOXID = null )
00199     {
00200         if ( parent::delete( $sOXID ) ) {
00201 
00202             $sOXID = $sOXID?$sOXID:$this->getId();
00203             $oDb = oxDb::getDb();
00204 
00205             // deleting payment related data
00206             $rs = $oDb->execute( "delete from oxobject2payment where oxpaymentid = ".$oDb->quote( $sOXID ) );
00207             return $rs->EOF;
00208         }
00209 
00210         return false;
00211     }
00212 
00224     public function isValidPayment( $aDynvalue, $sShopId, $oUser, $dBasketPrice, $sShipSetId )
00225     {
00226         if ( $this->oxpayments__oxid->value == 'oxempty' ) {
00227             return true;
00228         }
00229 
00230         $oValidator = oxNew( 'oxinputvalidator' );
00231         if ( !$oValidator->validatePaymentInputData( $this->oxpayments__oxid->value, $aDynvalue ) ) {
00232             $this->_iPaymentError = 1;
00233             return false;
00234         }
00235 
00236         $oCur = $this->getConfig()->getActShopCurrencyObject();
00237         $dBasketPrice = $dBasketPrice / $oCur->rate;
00238 
00239         if ( $sShipSetId ) {
00240             $aPaymentList = oxPaymentList::getInstance()->getPaymentList( $sShipSetId, $dBasketPrice, $oUser );
00241 
00242             if ( !array_key_exists( $this->getId(), $aPaymentList ) ) {
00243                 $this->_iPaymentError = -3;
00244                 return false;
00245             }
00246         } else {
00247             $this->_iPaymentError = -2;
00248             return false;
00249         }
00250 
00251         return true;
00252     }
00253 
00259     public function getPaymentErrorNumber()
00260     {
00261         return $this->_iPaymentError;
00262     }
00263 
00264 }

Generated on Mon Oct 26 20:07:16 2009 for OXID eShop CE by  doxygen 1.5.5