00001 <?php
00002
00008 class oxPayment extends oxI18n
00009 {
00015 protected $_oGroups = null;
00016
00023 protected $_aCountries = null;
00024
00030 protected $_sClassName = 'oxpayment';
00031
00037 protected $_aDynValues = null;
00038
00042 public function __construct()
00043 {
00044 parent::__construct();
00045 $this->init( 'oxpayments' );
00046 }
00047
00053 public function getGroups()
00054 {
00055 if ( $this->_oGroups == null && $sOxid = $this->getId() ) {
00056
00057
00058 $this->_oGroups = oxNew( 'oxlist', 'oxgroups' );
00059
00060
00061 $sSelect = 'select oxgroups.* from oxgroups, oxobject2group ';
00062 $sSelect .= "where oxobject2group.oxobjectid = '$sOxid' ";
00063 $sSelect .= 'and oxobject2group.oxgroupsid=oxgroups.oxid ';
00064 $this->_oGroups->selectString( $sSelect );
00065 }
00066
00067 return $this->_oGroups;
00068 }
00069
00077 public function setDynValues( $aDynValues )
00078 {
00079 $this->_aDynValues = $aDynValues;
00080 }
00081
00090 public function setDynValue( $oKey, $oVal )
00091 {
00092 $this->_aDynValues[$oKey] = $oVal;
00093 }
00094
00100 public function getDynValues()
00101 {
00102 if ( !$this->_aDynValues ) {
00103 $this->_aDynValues = oxUtils::getInstance()->assignValuesFromText( $this->oxpayments__oxvaldesc->value );
00104 }
00105 return $this->_aDynValues;
00106 }
00107
00115 public function getPaymentValue( $dBaseprice )
00116 {
00117 $dRet = 0;
00118
00119 if ( $this->oxpayments__oxaddsumtype->value == "%") {
00120 $dRet = $dBaseprice * $this->oxpayments__oxaddsum->value/100;
00121 } else {
00122 $oCur = $this->getConfig()->getActShopCurrencyObject();
00123 $dRet = $this->oxpayments__oxaddsum->value * $oCur->rate;
00124 }
00125
00126 if ( ($dRet * -1 ) > $dBaseprice ) {
00127 $dRet = $dBaseprice;
00128 }
00129
00130 return $dRet;
00131 }
00132
00140 public function getPaymentPrice( $oBasket )
00141 {
00142 $dBasketPrice = $oBasket->getDiscountProductsPrice()->getBruttoSum();
00143 $dPrice = $this->getPaymentValue( $dBasketPrice );
00144
00145
00146 $oPrice = oxNew( 'oxPrice' );
00147 $oPrice->setBruttoPriceMode();
00148 $oPrice->setPrice( $dPrice );
00149
00150 if ( $this->getConfig()->getConfigParam( 'blCalcVATForPayCharge' ) && $dPrice > 0 ) {
00151 $oPrice->setVat( $oBasket->getMostUsedVatPercent() );
00152 }
00153
00154 return $oPrice;
00155 }
00156
00162 public function getCountries()
00163 {
00164 if ( $this->_aCountries === null ) {
00165
00166 $this->_aCountries = array();
00167 $sSelect = 'select oxobjectid from oxobject2payment where oxpaymentid="'.$this->getId().'" and oxtype = "oxcountry" ';
00168 $rs = oxDb::getDb()->Execute( $sSelect );
00169 if ( $rs && $rs->recordCount()) {
00170 while ( !$rs->EOF ) {
00171 $this->_aCountries[] = $rs->fields[0];
00172 $rs->moveNext();
00173 }
00174 }
00175 }
00176 return $this->_aCountries;
00177 }
00178
00186 public function delete( $sOXID = null )
00187 {
00188 if ( parent::delete( $sOXID ) ) {
00189
00190 $sOXID = $sOXID?$sOXID:$this->getId();
00191
00192
00193 $rs = oxDb::getDb()->execute( "delete from oxobject2payment where oxpaymentid = '$sOXID' " );
00194 return $rs->EOF;
00195 }
00196
00197 return false;
00198 }
00199
00211 public function isValidPayment( $aDynvalue, $sShopId, $oUser, $dBasketPrice, $sShipSetId )
00212 {
00213 if ( $this->oxpayments__oxid->value == 'oxempty' ) {
00214 return true;
00215 }
00216
00217 $oValidator = oxNew( 'oxinputvalidator' );
00218 if ( !$oValidator->validatePaymentInputData( $this->oxpayments__oxid->value, $aDynvalue ) ) {
00219 return false;
00220 }
00221
00222 $oCur = $this->getConfig()->getActShopCurrencyObject();
00223 $dBasketPrice = $dBasketPrice / $oCur->rate;
00224
00225 if ( $sShipSetId ) {
00226 $aPaymentList = oxPaymentList::getInstance()->getPaymentList( $sShipSetId, $dBasketPrice, $oUser );
00227
00228 if ( !array_key_exists( $this->getId(), $aPaymentList ) ) {
00229 return false;
00230 }
00231 } else {
00232 return false;
00233 }
00234
00235 return true;
00236 }
00237 }