Go to the documentation of this file.00001 <?php
00002
00008 class oxPayment extends oxI18n
00009 {
00010
00016 const PAYMENT_ADDSUMRULE_ALLGOODS = 1;
00017
00023 const PAYMENT_ADDSUMRULE_DISCOUNTS = 2;
00024
00030 const PAYMENT_ADDSUMRULE_VOUCHERS = 4;
00031
00037 const PAYMENT_ADDSUMRULE_SHIPCOSTS = 8;
00038
00044 const PAYMENT_ADDSUMRULE_GIFTS = 16;
00045
00051 protected $_oGroups = null;
00052
00059 protected $_aCountries = null;
00060
00066 protected $_sClassName = 'oxpayment';
00067
00073 protected $_aDynValues = null;
00074
00080 protected $_iPaymentError = null;
00081
00087 protected $_blPaymentVatOnTop = false;
00088
00094 protected $_oPrice = null;
00095
00099 public function __construct()
00100 {
00101 $this->setPaymentVatOnTop($this->getConfig()->getConfigParam('blPaymentVatOnTop'));
00102 parent::__construct();
00103 $this->init('oxpayments');
00104 }
00105
00111 public function setPaymentVatOnTop($blOnTop)
00112 {
00113 $this->_blPaymentVatOnTop = $blOnTop;
00114 }
00115
00121 public function getGroups()
00122 {
00123 if ($this->_oGroups == null && ($sOxid = $this->getId())) {
00124
00125
00126 $this->_oGroups = oxNew('oxlist', 'oxgroups');
00127 $sViewName = getViewName("oxgroups", $this->getLanguage());
00128
00129
00130 $sSelect = "select {$sViewName}.* from {$sViewName}, oxobject2group
00131 where oxobject2group.oxobjectid = '{$sOxid}'
00132 and oxobject2group.oxgroupsid={$sViewName}.oxid ";
00133 $this->_oGroups->selectString($sSelect);
00134 }
00135
00136 return $this->_oGroups;
00137 }
00138
00144 public function setDynValues($aDynValues)
00145 {
00146 $this->_aDynValues = $aDynValues;
00147 }
00148
00155 public function setDynValue($oKey, $oVal)
00156 {
00157 $this->_aDynValues[$oKey] = $oVal;
00158 }
00159
00165 public function getDynValues()
00166 {
00167 if (!$this->_aDynValues) {
00168 $sRawDynValue = null;
00169 if (is_object($this->oxpayments__oxvaldesc)) {
00170 $sRawDynValue = $this->oxpayments__oxvaldesc->getRawValue();
00171 }
00172
00173 $this->_aDynValues = oxRegistry::getUtils()->assignValuesFromText($sRawDynValue);
00174 }
00175
00176 return $this->_aDynValues;
00177 }
00178
00186 public function getPaymentValue($dBasePrice)
00187 {
00188 $dRet = 0;
00189
00190 if ($this->oxpayments__oxaddsumtype->value == "%") {
00191 $dRet = $dBasePrice * $this->oxpayments__oxaddsum->value / 100;
00192 } else {
00193 $oCur = $this->getConfig()->getActShopCurrencyObject();
00194 $dRet = $this->oxpayments__oxaddsum->value * $oCur->rate;
00195 }
00196
00197 if (($dRet * -1) > $dBasePrice) {
00198 $dRet = $dBasePrice;
00199 }
00200
00201 return $dRet;
00202 }
00203
00212 public function getBaseBasketPriceForPaymentCostCalc($oBasket)
00213 {
00214 $dBasketPrice = 0;
00215 $iRules = $this->oxpayments__oxaddsumrules->value;
00216
00217
00218 if (!$iRules || ($iRules & self::PAYMENT_ADDSUMRULE_ALLGOODS)) {
00219 $dBasketPrice += $oBasket->getProductsPrice()->getSum($oBasket->isCalculationModeNetto());
00220 }
00221
00222
00223 if ((!$iRules || ($iRules & self::PAYMENT_ADDSUMRULE_DISCOUNTS)) &&
00224 ($oCosts = $oBasket->getTotalDiscount())
00225 ) {
00226 $dBasketPrice -= $oCosts->getPrice();
00227 }
00228
00229
00230 if (!$iRules || ($iRules & self::PAYMENT_ADDSUMRULE_VOUCHERS)) {
00231 $dBasketPrice -= $oBasket->getVoucherDiscValue();
00232 }
00233
00234
00235 if ((!$iRules || ($iRules & self::PAYMENT_ADDSUMRULE_SHIPCOSTS)) &&
00236 ($oCosts = $oBasket->getCosts('oxdelivery'))
00237 ) {
00238 if ($oBasket->isCalculationModeNetto()) {
00239 $dBasketPrice += $oCosts->getNettoPrice();
00240 } else {
00241 $dBasketPrice += $oCosts->getBruttoPrice();
00242 }
00243
00244 }
00245
00246
00247 if (($iRules & self::PAYMENT_ADDSUMRULE_GIFTS) &&
00248 ($oCosts = $oBasket->getCosts('oxwrapping'))
00249 ) {
00250 if ($oBasket->isCalculationModeNetto()) {
00251 $dBasketPrice += $oCosts->getNettoPrice();
00252 } else {
00253 $dBasketPrice += $oCosts->getBruttoPrice();
00254 }
00255 }
00256
00257
00258 if (($iRules & self::PAYMENT_ADDSUMRULE_GIFTS) &&
00259 ($oCosts = $oBasket->getCosts('oxgiftcard'))
00260 ) {
00261
00262 if ($oBasket->isCalculationModeNetto()) {
00263 $dBasketPrice += $oCosts->getNettoPrice();
00264 } else {
00265 $dBasketPrice += $oCosts->getBruttoPrice();
00266 }
00267 }
00268
00269 return $dBasketPrice;
00270 }
00271
00277 public function calculate($oBasket)
00278 {
00279
00280 $dPrice = $this->getPaymentValue($this->getBaseBasketPriceForPaymentCostCalc($oBasket));
00281
00282 if ($dPrice) {
00283
00284 $oPrice = oxNew('oxPrice');
00285 $oPrice->setNettoMode($this->_blPaymentVatOnTop);
00286
00287 $oPrice->setPrice($dPrice);
00288 if ($dPrice > 0) {
00289 $oPrice->setVat($oBasket->getAdditionalServicesVatPercent());
00290 }
00291
00292 $this->_oPrice = $oPrice;
00293 }
00294
00295 }
00296
00302 public function getPrice()
00303 {
00304 return $this->_oPrice;
00305 }
00306
00314 public function getFNettoPrice()
00315 {
00316 if ($this->getPrice()) {
00317 return oxRegistry::getLang()->formatCurrency($this->getPrice()->getNettoPrice());
00318 }
00319 }
00320
00328 public function getFBruttoPrice()
00329 {
00330 if ($this->getPrice()) {
00331 return oxRegistry::getLang()->formatCurrency($this->getPrice()->getBruttoPrice());
00332 }
00333 }
00334
00342 public function getFPriceVat()
00343 {
00344 if ($this->getPrice()) {
00345 return oxRegistry::getLang()->formatCurrency($this->getPrice()->getVatValue());
00346 }
00347 }
00348
00354 public function getCountries()
00355 {
00356 if ($this->_aCountries === null) {
00357 $oDb = oxDb::getDb();
00358 $this->_aCountries = array();
00359 $sSelect = 'select oxobjectid from oxobject2payment where oxpaymentid=' . $oDb->quote($this->getId()) . ' and oxtype = "oxcountry" ';
00360 $rs = $oDb->getCol($sSelect);
00361 $this->_aCountries = $rs;
00362 }
00363
00364 return $this->_aCountries;
00365 }
00366
00374 public function delete($sOxId = null)
00375 {
00376 if (parent::delete($sOxId)) {
00377
00378 $sOxId = $sOxId ? $sOxId : $this->getId();
00379 $oDb = oxDb::getDb();
00380
00381
00382 $rs = $oDb->execute("delete from oxobject2payment where oxpaymentid = " . $oDb->quote($sOxId));
00383
00384 return $rs->EOF;
00385 }
00386
00387 return false;
00388 }
00389
00401 public function isValidPayment($aDynValue, $sShopId, $oUser, $dBasketPrice, $sShipSetId)
00402 {
00403 $myConfig = $this->getConfig();
00404 if ($this->oxpayments__oxid->value == 'oxempty') {
00405
00406 if (!$this->oxpayments__oxactive->value || !$myConfig->getConfigParam("blOtherCountryOrder")) {
00407 $this->_iPaymentError = -2;
00408
00409 return false;
00410 }
00411 if (count(
00412 oxRegistry::get("oxDeliverySetList")
00413 ->getDeliverySetList(
00414 $oUser,
00415 $oUser->getActiveCountry()
00416 )
00417 )
00418 ) {
00419 $this->_iPaymentError = -3;
00420
00421 return false;
00422 }
00423
00424 return true;
00425 }
00426
00427 $mxValidationResult = oxRegistry::get("oxInputValidator")->validatePaymentInputData($this->oxpayments__oxid->value, $aDynValue);
00428
00429 if (is_integer($mxValidationResult)) {
00430 $this->_iPaymentError = $mxValidationResult;
00431
00432 return false;
00433 } elseif ($mxValidationResult === false) {
00434 $this->_iPaymentError = 1;
00435
00436 return false;
00437 }
00438
00439 $oCur = $myConfig->getActShopCurrencyObject();
00440 $dBasketPrice = $dBasketPrice / $oCur->rate;
00441
00442 if ($sShipSetId) {
00443 $aPaymentList = oxRegistry::get("oxPaymentList")->getPaymentList($sShipSetId, $dBasketPrice, $oUser);
00444
00445 if (!array_key_exists($this->getId(), $aPaymentList)) {
00446 $this->_iPaymentError = -3;
00447
00448 return false;
00449 }
00450 } else {
00451 $this->_iPaymentError = -2;
00452
00453 return false;
00454 }
00455
00456 return true;
00457 }
00458
00464 public function getPaymentErrorNumber()
00465 {
00466 return $this->_iPaymentError;
00467 }
00468 }