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
00041 public function __construct()
00042 {
00043 parent::__construct();
00044 $this->init( 'oxpayments' );
00045 }
00046
00052 public function getGroups()
00053 {
00054 if ( $this->_oGroups == null && $sOxid = $this->getId() ) {
00055
00056
00057 $this->_oGroups = oxNew( 'oxlist', 'oxgroups' );
00058
00059
00060 $sSelect = 'select oxgroups.* from oxgroups, oxobject2group ';
00061 $sSelect .= "where oxobject2group.oxobjectid = '$sOxid' ";
00062 $sSelect .= 'and oxobject2group.oxgroupsid=oxgroups.oxid ';
00063 $this->_oGroups->selectString( $sSelect );
00064 }
00065
00066 return $this->_oGroups;
00067 }
00068
00076 public function setDynValues( $aDynValues )
00077 {
00078 $this->_aDynValues = $aDynValues;
00079 }
00080
00089 public function setDynValue( $oKey, $oVal )
00090 {
00091 $this->_aDynValues[$oKey] = $oVal;
00092 }
00093
00099 public function getDynValues()
00100 {
00101 if ( !$this->_aDynValues ) {
00102 $sRawDynValue = null;
00103 if ( is_object($this->oxpayments__oxvaldesc ) ) {
00104 $sRawDynValue = $this->oxpayments__oxvaldesc->getRawValue();
00105 }
00106
00107 $this->_aDynValues = oxUtils::getInstance()->assignValuesFromText( $sRawDynValue );
00108 }
00109 return $this->_aDynValues;
00110 }
00111
00119 public function getPaymentValue( $dBaseprice )
00120 {
00121 $dRet = 0;
00122
00123 if ( $this->oxpayments__oxaddsumtype->value == "%") {
00124 $dRet = $dBaseprice * $this->oxpayments__oxaddsum->value/100;
00125 } else {
00126 $oCur = $this->getConfig()->getActShopCurrencyObject();
00127 $dRet = $this->oxpayments__oxaddsum->value * $oCur->rate;
00128 }
00129
00130 if ( ($dRet * -1 ) > $dBaseprice ) {
00131 $dRet = $dBaseprice;
00132 }
00133
00134 return $dRet;
00135 }
00136
00144 public function getPaymentPrice( $oBasket )
00145 {
00146
00147 $dBasketPrice = $oBasket->getPriceForPayment();
00148 $dPrice = $this->getPaymentValue( $dBasketPrice );
00149
00150
00151 $oPrice = oxNew( 'oxPrice' );
00152 $oPrice->setBruttoPriceMode();
00153 $oPrice->setPrice( $dPrice );
00154
00155 if ( $this->getConfig()->getConfigParam( 'blCalcVATForPayCharge' ) && $dPrice > 0 ) {
00156 $oPrice->setVat( $oBasket->getMostUsedVatPercent() );
00157 }
00158
00159 return $oPrice;
00160 }
00161
00167 public function getCountries()
00168 {
00169 if ( $this->_aCountries === null ) {
00170
00171 $this->_aCountries = array();
00172 $sSelect = 'select oxobjectid from oxobject2payment where oxpaymentid="'.$this->getId().'" and oxtype = "oxcountry" ';
00173 $rs = oxDb::getDb()->Execute( $sSelect );
00174 if ( $rs && $rs->recordCount()) {
00175 while ( !$rs->EOF ) {
00176 $this->_aCountries[] = $rs->fields[0];
00177 $rs->moveNext();
00178 }
00179 }
00180 }
00181 return $this->_aCountries;
00182 }
00183
00191 public function delete( $sOXID = null )
00192 {
00193 if ( parent::delete( $sOXID ) ) {
00194
00195 $sOXID = $sOXID?$sOXID:$this->getId();
00196
00197
00198 $rs = oxDb::getDb()->execute( "delete from oxobject2payment where oxpaymentid = '$sOXID' " );
00199 return $rs->EOF;
00200 }
00201
00202 return false;
00203 }
00204
00216 public function isValidPayment( $aDynvalue, $sShopId, $oUser, $dBasketPrice, $sShipSetId )
00217 {
00218 if ( $this->oxpayments__oxid->value == 'oxempty' ) {
00219 return true;
00220 }
00221
00222 $oValidator = oxNew( 'oxinputvalidator' );
00223 if ( !$oValidator->validatePaymentInputData( $this->oxpayments__oxid->value, $aDynvalue ) ) {
00224 return false;
00225 }
00226
00227 $oCur = $this->getConfig()->getActShopCurrencyObject();
00228 $dBasketPrice = $dBasketPrice / $oCur->rate;
00229
00230 if ( $sShipSetId ) {
00231 $aPaymentList = oxPaymentList::getInstance()->getPaymentList( $sShipSetId, $dBasketPrice, $oUser );
00232
00233 if ( !array_key_exists( $this->getId(), $aPaymentList ) ) {
00234 return false;
00235 }
00236 } else {
00237 return false;
00238 }
00239
00240 return true;
00241 }
00242 }