Go to the documentation of this file.00001 <?php
00002
00007 class Payment extends oxUBase
00008 {
00009
00015 protected $_oPaymentList = null;
00016
00022 protected $_iPaymentCnt = null;
00023
00029 protected $_aAllSets = null;
00030
00036 protected $_iAllSetsCnt = null;
00037
00043 protected $_oEmptyPayment = null;
00044
00050 protected $_sPaymentError = null;
00051
00057 protected $_sPaymentErrorText = null;
00058
00064 protected $_aDynValue = null;
00065
00071 protected $_sCheckedId = null;
00072
00078 protected $_sCheckedPaymentId = null;
00079
00085 protected $_aCreditYears = null;
00086
00092 protected $_sThisTemplate = 'page/checkout/payment.tpl';
00093
00099 protected $_blIsOrderStep = true;
00100
00106 protected $_aTsProducts = null;
00107
00113 protected $_blDynDataFiltered = false;
00114
00115
00119 public function init()
00120 {
00121 $this->_filterDynData();
00122 parent::init();
00123 }
00124
00136 public function render()
00137 {
00138 $myConfig = $this->getConfig();
00139
00140 if ($myConfig->getConfigParam('blPsBasketReservationEnabled')) {
00141 $this->getSession()->getBasketReservations()->renewExpiration();
00142 }
00143
00144 parent::render();
00145
00146
00147
00148
00149
00150
00151 $blAlreadyRedirected = oxRegistry::getConfig()->getRequestParameter('sslredirect') == 'forced';
00152
00153 if ($this->getIsOrderStep()) {
00154
00155
00156
00157 $oBasket = $this->getSession()->getBasket();
00158 $blPsBasketReservationEnabled = $myConfig->getConfigParam('blPsBasketReservationEnabled');
00159 if ($blPsBasketReservationEnabled && (!$oBasket || ($oBasket && !$oBasket->getProductsCount()))) {
00160 oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL() .'cl=basket', true, 302);
00161 }
00162
00163 $oUser = $this->getUser();
00164 if (!$oUser && ($oBasket && $oBasket->getProductsCount() > 0)) {
00165 oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL() . 'cl=basket', false, 302);
00166 } elseif (!$oBasket || !$oUser || ($oBasket && !$oBasket->getProductsCount())) {
00167 oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL() . 'cl=start', false, 302);
00168 }
00169 }
00170
00171 $sFncParameter = oxRegistry::getConfig()->getRequestParameter('fnc');
00172 if ($myConfig->getCurrentShopURL() != $myConfig->getSSLShopURL() && !$blAlreadyRedirected && !$sFncParameter) {
00173 $sPayErrorParameter = oxRegistry::getConfig()->getRequestParameter('payerror');
00174 $sPayErrorTextParameter = oxRegistry::getConfig()->getRequestParameter('payerrortext');
00175 $shopSecureHomeURL = $myConfig->getShopSecureHomeURL();
00176
00177 $sPayError = $sPayErrorParameter ?'payerror='.$sPayErrorParameter:'';
00178 $sPayErrorText = $sPayErrorTextParameter ?'payerrortext='.$sPayErrorTextParameter:'';
00179 $sRedirectURL = $shopSecureHomeURL .'sslredirect=forced&cl=payment&'.$sPayError."&".$sPayErrorText;
00180 oxRegistry::getUtils()->redirect($sRedirectURL, true, 302);
00181 }
00182
00183 if (!$this->getAllSetsCnt()) {
00184
00185 $this->_setDefaultEmptyPayment();
00186 oxRegistry::getSession()->setVariable('sShipSet', null);
00187 }
00188
00189 $this->_unsetPaymentErrors();
00190
00191 return $this->_sThisTemplate;
00192 }
00193
00199 protected function _setDefaultEmptyPayment()
00200 {
00201
00202 if ($this->getConfig()->getConfigParam('blOtherCountryOrder')) {
00203 $oPayment = oxNew('oxpayment');
00204 if ($oPayment->load('oxempty')) {
00205 $this->_oEmptyPayment = $oPayment;
00206 } else {
00207
00208 $this->_sPaymentError = -2;
00209 }
00210 } else {
00211 $this->_sPaymentError = -2;
00212 }
00213 }
00214
00218 protected function _unsetPaymentErrors()
00219 {
00220 $iPayError = oxRegistry::getConfig()->getRequestParameter('payerror');
00221 $sPayErrorText = oxRegistry::getConfig()->getRequestParameter('payerrortext');
00222
00223 if (!($iPayError || $sPayErrorText)) {
00224 $iPayError = oxRegistry::getSession()->getVariable('payerror');
00225 $sPayErrorText = oxRegistry::getSession()->getVariable('payerrortext');
00226 }
00227
00228 if ($iPayError) {
00229 oxRegistry::getSession()->deleteVariable('payerror');
00230 $this->_sPaymentError = $iPayError;
00231 }
00232 if ($sPayErrorText) {
00233 oxRegistry::getSession()->deleteVariable('payerrortext');
00234 $this->_sPaymentErrorText = $sPayErrorText;
00235 }
00236 }
00237
00242 public function changeshipping()
00243 {
00244 $oSession = $this->getSession();
00245
00246 $oBasket = $oSession->getBasket();
00247 $oBasket->setShipping(null);
00248 $oBasket->onUpdate();
00249 $oSession->setVariable('sShipSet', $this->getConfig()->getRequestParameter('sShipSet'));
00250 }
00251
00263 public function validatePayment()
00264 {
00265 $myConfig = $this->getConfig();
00266 $oSession = $this->getSession();
00267
00268
00269
00270 $oUser = $this->getUser();
00271 if (!$oUser) {
00272 $oSession->setVariable('payerror', 2);
00273
00274 return;
00275 }
00276
00277 if (!($sShipSetId = oxRegistry::getConfig()->getRequestParameter('sShipSet'))) {
00278 $sShipSetId = $oSession->getVariable('sShipSet');
00279 }
00280 if (!($sPaymentId = oxRegistry::getConfig()->getRequestParameter('paymentid'))) {
00281 $sPaymentId = $oSession->getVariable('paymentid');
00282 }
00283 if (!($aDynvalue = oxRegistry::getConfig()->getRequestParameter('dynvalue'))) {
00284 $aDynvalue = $oSession->getVariable('dynvalue');
00285 }
00286
00287
00288 if (!$myConfig->getConfigParam('blOtherCountryOrder') && $sPaymentId == 'oxempty') {
00289 $sPaymentId = '';
00290 }
00291
00292
00293 if (!$sPaymentId) {
00294 $oSession->setVariable('payerror', 1);
00295
00296 return;
00297 }
00298
00299 if ($this->getDynDataFiltered() && $sPaymentId == 'oxidcreditcard') {
00300 $oSession->setVariable('payerror', 7);
00301
00302 return;
00303 }
00304
00305 $oBasket = $oSession->getBasket();
00306 $oBasket->setPayment(null);
00307 $oPayment = oxNew('oxpayment');
00308 $oPayment->load($sPaymentId);
00309
00310
00311 $dBasketPrice = $oBasket->getPriceForPayment();
00312
00313 $blOK = $oPayment->isValidPayment($aDynvalue, $myConfig->getShopId(), $oUser, $dBasketPrice, $sShipSetId);
00314
00315 if ($blOK) {
00316 $oSession->setVariable('paymentid', $sPaymentId);
00317 $oSession->setVariable('dynvalue', $aDynvalue);
00318 if (oxRegistry::getConfig()->getRequestParameter('bltsprotection')) {
00319 $sTsProductId = oxRegistry::getConfig()->getRequestParameter('stsprotection');
00320 $oBasket->setTsProductId($sTsProductId);
00321 $oSession->setVariable('stsprotection', $sTsProductId);
00322 } else {
00323 $oSession->deleteVariable('stsprotection');
00324 $oBasket->setTsProductId(null);
00325 }
00326 $oBasket->setShipping($sShipSetId);
00327 $oSession->deleteVariable('_selected_paymentid');
00328
00329 return 'order';
00330 } else {
00331 $oSession->setVariable('payerror', $oPayment->getPaymentErrorNumber());
00332
00333
00334 $oSession->deleteVariable('paymentid');
00335 $oSession->setVariable('_selected_paymentid', $sPaymentId);
00336 $oSession->deleteVariable('stsprotection');
00337 $oBasket->setTsProductId(null);
00338
00339 return;
00340 }
00341 }
00342
00348 public function getPaymentList()
00349 {
00350 if ($this->_oPaymentList === null) {
00351 $this->_oPaymentList = false;
00352
00353 $sActShipSet = oxRegistry::getConfig()->getRequestParameter('sShipSet');
00354 if (!$sActShipSet) {
00355 $sActShipSet = oxRegistry::getSession()->getVariable('sShipSet');
00356 }
00357
00358 $oBasket = $this->getSession()->getBasket();
00359
00360
00361 list($aAllSets, $sActShipSet, $aPaymentList) =
00362 oxRegistry::get("oxDeliverySetList")->getDeliverySetData($sActShipSet, $this->getUser(), $oBasket);
00363
00364 $oBasket->setShipping($sActShipSet);
00365
00366
00367 $this->_setValues($aPaymentList, $oBasket);
00368 $this->_oPaymentList = $aPaymentList;
00369 $this->_aAllSets = $aAllSets;
00370
00371 }
00372
00373 return $this->_oPaymentList;
00374 }
00375
00381 public function getAllSets()
00382 {
00383 if ($this->_aAllSets === null) {
00384 $this->_aAllSets = false;
00385
00386 if ($this->getPaymentList()) {
00387 return $this->_aAllSets;
00388 }
00389 }
00390
00391 return $this->_aAllSets;
00392 }
00393
00399 public function getAllSetsCnt()
00400 {
00401 if ($this->_iAllSetsCnt === null) {
00402 $this->_iAllSetsCnt = 0;
00403
00404 if ($this->getPaymentList()) {
00405 $this->_iAllSetsCnt = count($this->_aAllSets);
00406 }
00407 }
00408
00409 return $this->_iAllSetsCnt;
00410 }
00411
00418 protected function _setValues(& $aPaymentList, $oBasket = null)
00419 {
00420 if (is_array($aPaymentList)) {
00421 foreach ($aPaymentList as $oPayment) {
00422 $oPayment->calculate($oBasket);
00423 $oPayment->aDynValues = $oPayment->getDynValues();
00424 if ($oPayment->oxpayments__oxchecked->value) {
00425 $this->_sCheckedId = $oPayment->getId();
00426 }
00427 }
00428 }
00429 }
00430
00436 public function getEmptyPayment()
00437 {
00438 return $this->_oEmptyPayment;
00439 }
00440
00446 public function getPaymentError()
00447 {
00448 return $this->_sPaymentError;
00449 }
00450
00456 public function getDynDataFiltered()
00457 {
00458 return $this->_blDynDataFiltered;
00459 }
00460
00466 public function getPaymentErrorText()
00467 {
00468 return $this->_sPaymentErrorText;
00469 }
00470
00476 public function isOldDebitValidationEnabled()
00477 {
00478 return !$this->getConfig()->getConfigParam('blSkipDebitOldBankInfo');
00479 }
00480
00486 public function getDynValue()
00487 {
00488 if ($this->_aDynValue === null) {
00489 $this->_aDynValue = false;
00490
00491
00492 if (($aDynValue = oxRegistry::getSession()->getVariable('dynvalue'))) {
00493 $this->_aDynValue = $aDynValue;
00494 } else {
00495 $this->_aDynValue = oxRegistry::getConfig()->getRequestParameter("dynvalue");
00496 }
00497
00498
00499
00500 $aPaymentList = $this->getPaymentList();
00501 if (isset($aPaymentList['oxiddebitnote'])) {
00502 $this->_assignDebitNoteParams();
00503 }
00504 }
00505
00506 return $this->_aDynValue;
00507 }
00508
00513 protected function _assignDebitNoteParams()
00514 {
00515
00516 $oUserPayment = oxNew('oxuserpayment');
00517
00518 if ($oUserPayment->getPaymentByPaymentType($this->getUser(), 'oxiddebitnote')) {
00519 $sUserPaymentField = 'oxuserpayments__oxvalue';
00520 $aAddPaymentData = oxRegistry::getUtils()->assignValuesFromText($oUserPayment->$sUserPaymentField->value);
00521
00522
00523 foreach ($aAddPaymentData as $oData) {
00524 if (!isset($this->_aDynValue[$oData->name]) ||
00525 (isset($this->_aDynValue[$oData->name]) && !$this->_aDynValue[$oData->name])
00526 ) {
00527 $this->_aDynValue[$oData->name] = $oData->value;
00528 }
00529 }
00530 }
00531 }
00532
00539 public function getCheckedPaymentId()
00540 {
00541 if ($this->_sCheckedPaymentId === null) {
00542 if (!($sPaymentID = oxRegistry::getConfig()->getRequestParameter('paymentid'))) {
00543 $sPaymentID = oxRegistry::getSession()->getVariable('paymentid');
00544 }
00545 if ($sPaymentID) {
00546 $sCheckedId = $sPaymentID;
00547 } elseif (($sSelectedPaymentID = oxRegistry::getSession()->getVariable('_selected_paymentid'))) {
00548 $sCheckedId = $sSelectedPaymentID;
00549 } else {
00550
00551 if ($oUser = $this->getUser()) {
00552 $oOrder = oxNew('oxorder');
00553 if (($sLastPaymentId = $oOrder->getLastUserPaymentType($oUser->getId()))) {
00554 $sCheckedId = $sLastPaymentId;
00555 }
00556 }
00557 }
00558
00559
00560 if (!$sCheckedId && $this->_sCheckedId) {
00561 $sCheckedId = $this->_sCheckedId;
00562 }
00563
00564
00565 $oPaymentList = $this->getPaymentList();
00566 if (isset($oPaymentList) && $oPaymentList && !isset($oPaymentList[$sCheckedId])) {
00567 end($oPaymentList);
00568 $sCheckedId = key($oPaymentList);
00569 }
00570 $this->_sCheckedPaymentId = $sCheckedId;
00571 }
00572
00573 return $this->_sCheckedPaymentId;
00574 }
00575
00581 public function getPaymentCnt()
00582 {
00583 if ($this->_iPaymentCnt === null) {
00584 $this->_iPaymentCnt = false;
00585
00586 if ($oPaymentList = $this->getPaymentList()) {
00587 $this->_iPaymentCnt = count($oPaymentList);
00588 }
00589 }
00590
00591 return $this->_iPaymentCnt;
00592 }
00593
00599 public function getCreditYears()
00600 {
00601 if ($this->_aCreditYears === null) {
00602 $this->_aCreditYears = false;
00603
00604 $this->_aCreditYears = range(date('Y'), date('Y') + 10);
00605 }
00606
00607 return $this->_aCreditYears;
00608 }
00609
00618 protected function _checkArrValuesEmpty($aData, $aKeys)
00619 {
00620 if (!is_array($aKeys) || count($aKeys) < 1) {
00621 return false;
00622 }
00623
00624 foreach ($aKeys as $sKey) {
00625 if (isset($aData[$sKey]) && !empty($aData[$sKey])) {
00626 return false;
00627 }
00628 }
00629
00630 return true;
00631 }
00632
00633
00644 protected function _filterDynData()
00645 {
00646
00647 if (oxRegistry::getConfig()->getConfigParam("blStoreCreditCardInfo")) {
00648
00649 $this->_blDynDataFiltered = false;
00650
00651 return;
00652 }
00653
00654 $aDynData = $this->getSession()->getVariable("dynvalue");
00655
00656 $aFields = array("kktype", "kknumber", "kkname", "kkmonth", "kkyear", "kkpruef");
00657
00658 if ($aDynData) {
00659 if (!$this->_checkArrValuesEmpty($aDynData, $aFields)) {
00660 $this->_blDynDataFiltered = true;
00661 }
00662 $aDynData["kktype"] = null;
00663 $aDynData["kknumber"] = null;
00664 $aDynData["kkname"] = null;
00665 $aDynData["kkmonth"] = null;
00666 $aDynData["kkyear"] = null;
00667 $aDynData["kkpruef"] = null;
00668 oxRegistry::getSession()->setVariable("dynvalue", $aDynData);
00669 }
00670
00671 if (!$this->_checkArrValuesEmpty($_REQUEST["dynvalue"], $aFields) ||
00672 !$this->_checkArrValuesEmpty($_POST["dynvalue"], $aFields) ||
00673 !$this->_checkArrValuesEmpty($_GET["dynvalue"], $aFields)
00674 ) {
00675 $this->_blDynDataFiltered = true;
00676 }
00677
00678 unset($_REQUEST["dynvalue"]["kktype"]);
00679 unset($_REQUEST["dynvalue"]["kknumber"]);
00680 unset($_REQUEST["dynvalue"]["kkname"]);
00681 unset($_REQUEST["dynvalue"]["kkmonth"]);
00682 unset($_REQUEST["dynvalue"]["kkyear"]);
00683 unset($_REQUEST["dynvalue"]["kkpruef"]);
00684
00685 unset($_POST["dynvalue"]["kktype"]);
00686 unset($_POST["dynvalue"]["kknumber"]);
00687 unset($_POST["dynvalue"]["kkname"]);
00688 unset($_POST["dynvalue"]["kkmonth"]);
00689 unset($_POST["dynvalue"]["kkyear"]);
00690 unset($_POST["dynvalue"]["kkpruef"]);
00691
00692 unset($_GET["dynvalue"]["kktype"]);
00693 unset($_GET["dynvalue"]["kknumber"]);
00694 unset($_GET["dynvalue"]["kkname"]);
00695 unset($_GET["dynvalue"]["kkmonth"]);
00696 unset($_GET["dynvalue"]["kkyear"]);
00697 unset($_GET["dynvalue"]["kkpruef"]);
00698
00699 }
00700
00706 public function getTsProtections()
00707 {
00708 if ($this->_aTsProducts === null) {
00709 $oBasket = $this->getSession()->getBasket();
00710 $dVat = $oBasket->getAdditionalServicesVatPercent();
00711 if ($dPrice = $oBasket->getPrice()->getBruttoPrice()) {
00712 $oTsProtection = oxNew('oxtsprotection');
00713 $oTsProtection->setVat($dVat);
00714 $this->_aTsProducts = $oTsProtection->getTsProducts($dPrice);
00715 }
00716 }
00717
00718 return $this->_aTsProducts;
00719 }
00720
00726 public function getCheckedTsProductId()
00727 {
00728 if ($this->_sCheckedProductId === null) {
00729 $this->_sCheckedProductId = false;
00730 if ($sId = oxRegistry::getConfig()->getRequestParameter('stsprotection')) {
00731 $this->_sCheckedProductId = $sId;
00732 }
00733 }
00734
00735 return $this->_sCheckedProductId;
00736 }
00737
00743 public function getBreadCrumb()
00744 {
00745 $aPaths = array();
00746 $aPath = array();
00747
00748
00749 $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
00750 $aPath['title'] = oxRegistry::getLang()->translateString('PAY', $iBaseLanguage, false);
00751 $aPath['link'] = $this->getLink();
00752
00753 $aPaths[] = $aPath;
00754
00755 return $aPaths;
00756 }
00757
00763 public function isPaymentVatSplitted()
00764 {
00765 return $this->getConfig()->getConfigParam('blShowVATForPayCharge');
00766 }
00767 }