Go to the documentation of this file.00001 <?php
00002
00007 class Payment extends oxUBase
00008 {
00013 protected $_oPaymentList = null;
00014
00019 protected $_iPaymentCnt = null;
00020
00025 protected $_aAllSets = null;
00026
00031 protected $_iAllSetsCnt = null;
00032
00037 protected $_oEmptyPayment = null;
00038
00043 protected $_sPaymentError = null;
00044
00049 protected $_sPaymentErrorText = null;
00050
00055 protected $_aDynValue = null;
00056
00061 protected $_sCheckedId = null;
00062
00067 protected $_sCheckedPaymentId = null;
00068
00073 protected $_aCreditYears = null;
00074
00079 protected $_sThisTemplate = 'payment.tpl';
00080
00085 protected $_blIsOrderStep = true;
00086
00091 protected $_aTsProducts = null;
00092
00098 public function init()
00099 {
00100 $this->_filterDynData();
00101 parent::init();
00102 }
00103
00120 public function render()
00121 {
00122 $myConfig = $this->getConfig();
00123
00124 if ($myConfig->getConfigParam( 'blPsBasketReservationEnabled' )) {
00125 $this->getSession()->getBasketReservations()->renewExpiration();
00126 }
00127
00128 parent::render();
00129
00130
00131
00132
00133
00134 $blAlreadyRedirected = oxConfig::getParameter( 'sslredirect' ) == 'forced';
00135
00136 if ( $myConfig->getCurrentShopURL() != $myConfig->getSSLShopURL() && !$blAlreadyRedirected && !oxConfig::getParameter('fnc') ) {
00137 $sPayError = oxConfig::getParameter( 'payerror' )?'payerror='.oxConfig::getParameter( 'payerror' ):'';
00138 $sPayErrorText = oxConfig::getParameter('payerrortext')?'payerrortext='.oxConfig::getParameter( 'payerrortext' ):'';
00139 $sRedirectURL = $myConfig->getShopSecureHomeURL().'sslredirect=forced&cl=payment&'.$sPayError."&".$sPayErrorText;
00140 oxUtils::getInstance()->redirect( $sRedirectURL );
00141 }
00142
00143
00144
00145 $oBasket = $this->getSession()->getBasket();
00146 if ( $myConfig->getConfigParam( 'blPsBasketReservationEnabled' ) && (!$oBasket || ( $oBasket && !$oBasket->getProductsCount() )) ) {
00147 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() .'cl=basket' );
00148 }
00149 $oUser = $this->getUser();
00150 if ( !$oBasket || !$oUser || ( $oBasket && !$oBasket->getProductsCount() ) ) {
00151 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() .'cl=start' );
00152 }
00153
00154
00155 $this->_aViewData[ 'payments' ] = $this->getPaymentList();
00156
00157
00158 $this->_aViewData['allShipsetsCnt'] = $this->getAllSetsCnt();
00159 $this->_aViewData['allShipsets'] = $this->getAllSets();
00160
00161 if ( !$this->getAllSetsCnt() ) {
00162
00163 $this->_setDefaultEmptyPayment();
00164 oxSession::setVar( 'sShipSet', null );
00165 }
00166
00167 $this->_unsetPaymentErrors();
00168
00169 $this->_aViewData['oxemptypayment'] = $this->getEmptyPayment();
00170 $this->_aViewData['payerror'] = $this->getPaymentError();
00171 $this->_aViewData['payerrortext'] = $this->getPaymentErrorText();
00172
00173 $this->_aViewData['dynvalue'] = $this->getDynValue();
00174
00175
00176 $this->_aViewData['defpaymentid'] = $this->getCheckedPaymentId();
00177 $this->_aViewData['paymencnt'] = $this->getPaymentCnt();
00178
00179
00180 $this->_aViewData['creditYears'] = $this->getCreditYears();
00181
00182 return $this->_sThisTemplate;
00183 }
00184
00192 protected function _setDefaultEmptyPayment()
00193 {
00194
00195 if ( $this->getConfig()->getConfigParam( 'blOtherCountryOrder' ) ) {
00196 $oPayment = oxNew( 'oxpayment' );
00197 if ( $oPayment->load( 'oxempty' ) ) {
00198 $this->_oEmptyPayment = $oPayment;
00199 } else {
00200
00201 $this->_sPaymentError = -2;
00202 }
00203 } else {
00204 $this->_sPaymentError = -2;
00205 }
00206 }
00207
00213 protected function _unsetPaymentErrors()
00214 {
00215 $iPayError = oxConfig::getParameter( 'payerror' );
00216 $iPayErrorText = oxConfig::getParameter( 'payerrortext' );
00217
00218 if ( $iPayError ) {
00219 oxSession::deleteVar( 'payerror' );
00220 $this->_sPaymentError = $iPayError;
00221
00222 }
00223 if ( $iPayErrorText ) {
00224 oxSession::deleteVar( 'payerrortext' );
00225 $this->_sPaymentErrorText = $iPayErrorText;
00226
00227 }
00228 }
00229
00236 public function changeshipping()
00237 {
00238 $mySession = $this->getSession();
00239
00240 oxSession::setVar( 'sShipSet', oxConfig::getParameter( 'sShipSet' ) );
00241 $oBasket = $mySession->getBasket();
00242 $oBasket->setShipping( null );
00243 $oBasket->onUpdate();
00244 }
00245
00257 public function validatePayment()
00258 {
00259 $myConfig = $this->getConfig();
00260 $mySession = $this->getSession();
00261
00262
00263
00264 $oUser = $this->getUser();
00265 if ( !$oUser ) {
00266 oxSession::setVar( 'payerror', 2 );
00267 return;
00268 }
00269
00270 if (! ($sShipSetId = oxConfig::getParameter( 'sShipSet' ))) {
00271 $sShipSetId = oxSession::getVar('sShipSet');
00272 }
00273 $sPaymentId = oxConfig::getParameter( 'paymentid' );
00274 $aDynvalue = oxConfig::getParameter( 'dynvalue' );
00275
00276
00277 if ( !$myConfig->getConfigParam( 'blOtherCountryOrder' ) && $sPaymentId == 'oxempty' ) {
00278 $sPaymentId = '';
00279 }
00280
00281
00282 if ( !$sPaymentId ) {
00283 oxSession::setVar( 'payerror', 1 );
00284 return;
00285 }
00286
00287 $oBasket = $mySession->getBasket();
00288 $oBasket->setPayment(null);
00289 $oPayment = oxNew( 'oxpayment' );
00290 $oPayment->load( $sPaymentId );
00291
00292
00293 $dBasketPrice = $oBasket->getPriceForPayment();
00294
00295 $blOK = $oPayment->isValidPayment( $aDynvalue, $myConfig->getShopId(), $oUser, $dBasketPrice, $sShipSetId );
00296
00297 if ( $blOK ) {
00298 oxSession::setVar( 'paymentid', $sPaymentId );
00299 oxSession::setVar( 'dynvalue', $aDynvalue );
00300 if ( oxConfig::getParameter( 'bltsprotection' ) ) {
00301 $sTsProductId = oxConfig::getParameter( 'stsprotection' );
00302 $oBasket->setTsProductId($sTsProductId);
00303 oxSession::setVar( 'stsprotection', $sTsProductId );
00304 } else {
00305 oxSession::deleteVar( 'stsprotection' );
00306 $oBasket->setTsProductId(null);
00307 }
00308 $oBasket->setShipping($sShipSetId);
00309 oxSession::deleteVar( '_selected_paymentid' );
00310 return 'order';
00311 } else {
00312 oxSession::setVar( 'payerror', $oPayment->getPaymentErrorNumber() );
00313
00314
00315 oxSession::deleteVar( 'paymentid' );
00316 oxSession::setVar( '_selected_paymentid', $sPaymentId );
00317 oxSession::deleteVar( 'stsprotection' );
00318 $oBasket->setTsProductId(null);
00319 return;
00320 }
00321 }
00322
00328 public function getPaymentList()
00329 {
00330 if ( $this->_oPaymentList === null ) {
00331 $this->_oPaymentList = false;
00332
00333 $sActShipSet = oxConfig::getParameter( 'sShipSet' );
00334 $oBasket = $this->getSession()->getBasket();
00335
00336
00337 list( $aAllSets, $sActShipSet, $aPaymentList ) = oxDeliverySetList::getInstance()->getDeliverySetData( $sActShipSet, $this->getUser(), $oBasket );
00338
00339 oxSession::setVar( 'sShipSet', $sActShipSet );
00340 $oBasket->setShipping( $sActShipSet );
00341
00342
00343 $this->_setDeprecatedValues( $aPaymentList, $oBasket );
00344 $this->_oPaymentList = $aPaymentList;
00345 $this->_aAllSets = $aAllSets;
00346
00347 }
00348 return $this->_oPaymentList;
00349 }
00350
00356 public function getAllSets()
00357 {
00358 if ( $this->_aAllSets === null ) {
00359 $this->_aAllSets = false;
00360
00361 if ($this->getPaymentList()) {
00362 return $this->_aAllSets;
00363 }
00364 }
00365 return $this->_aAllSets;
00366 }
00367
00373 public function getAllSetsCnt()
00374 {
00375 if ( $this->_iAllSetsCnt === null ) {
00376 $this->_iAllSetsCnt = 0;
00377
00378 if ($this->getPaymentList()) {
00379 $this->_iAllSetsCnt = count($this->_aAllSets);
00380 }
00381 }
00382 return $this->_iAllSetsCnt;
00383 }
00384
00393 protected function _setDeprecatedValues( & $aPaymentList, $oBasket = null )
00394 {
00395 if ( is_array($aPaymentList) ) {
00396 $oLang = oxLang::getInstance();
00397 foreach ( $aPaymentList as $oPayment ) {
00398 $oPrice = $oPayment->getPaymentPrice( $oBasket );
00399 $oPayment->dAddPaymentSum = $oPrice->getBruttoPrice();
00400 $oPayment->fAddPaymentSum = $oLang->formatCurrency( $oPayment->dAddPaymentSum, $oBasket->getBasketCurrency() );
00401 $oPayment->aDynValues = $oPayment->getDynValues();
00402 if ( $oPayment->oxpayments__oxchecked->value ) {
00403 $this->_sCheckedId = $oPayment->getId();
00404 }
00405 }
00406 }
00407 }
00408
00414 public function getEmptyPayment()
00415 {
00416 return $this->_oEmptyPayment;
00417 }
00418
00424 public function getPaymentError()
00425 {
00426 return $this->_sPaymentError;
00427 }
00428
00434 public function getPaymentErrorText()
00435 {
00436 return $this->_sPaymentErrorText;
00437 }
00438
00444 public function getDynValue()
00445 {
00446 if ( $this->_aDynValue === null ) {
00447 $this->_aDynValue = false;
00448
00449
00450 if ( ( $aDynValue = oxSession::getVar( 'dynvalue' ) ) ) {
00451 $this->_aDynValue = $aDynValue;
00452 } else {
00453 $this->_aDynValue = oxConfig::getParameter( "dynvalue");
00454 }
00455
00456
00457
00458 $aPaymentList = $this->getPaymentList();
00459 if ( isset( $aPaymentList['oxiddebitnote'] ) ) {
00460 $this->_assignDebitNoteParams();
00461 }
00462 }
00463 return $this->_aDynValue;
00464 }
00465
00472 protected function _assignDebitNoteParams()
00473 {
00474
00475 $oUserPayment = oxNew( 'oxuserpayment');
00476
00477 if ( $oUserPayment->getPaymentByPaymentType( $this->getUser(), 'oxiddebitnote' ) ) {
00478 $aAddPaymentData = oxUtils::getInstance()->assignValuesFromText( $oUserPayment->oxuserpayments__oxvalue->value );
00479
00480
00481 foreach ( $aAddPaymentData as $oData ) {
00482 if ( !isset( $this->_aDynValue[$oData->name] ) ||
00483 ( isset( $this->_aDynValue[$oData->name] ) && !$this->_aDynValue[$oData->name] ) ) {
00484 $this->_aDynValue[$oData->name] = $oData->value;
00485 }
00486 }
00487 }
00488 }
00489
00496 public function getCheckedPaymentId()
00497 {
00498 if ( $this->_sCheckedPaymentId === null ) {
00499 if ( ( $sPaymentID = oxConfig::getParameter( 'paymentid' ) ) ) {
00500 $sCheckedId = $sPaymentID;
00501 } elseif ( ( $sSelectedPaymentID = oxSession::getVar( '_selected_paymentid' ) ) ) {
00502 $sCheckedId = $sSelectedPaymentID;
00503 } else {
00504
00505 if ( $oUser = $this->getUser()) {
00506 $oOrder = oxNew('oxorder');
00507 if ( ( $sLastPaymentId = $oOrder->getLastUserPaymentType( $oUser->getId()) ) ) {
00508 $sCheckedId = $sLastPaymentId;
00509 }
00510 }
00511 }
00512
00513
00514 if ( !$sCheckedId && $this->_sCheckedId ) {
00515 $sCheckedId = $this->_sCheckedId;
00516 }
00517
00518
00519 $oPaymentList = $this->getPaymentList();
00520 if ( isset( $oPaymentList ) && $oPaymentList && !isset( $oPaymentList[$sCheckedId] ) ) {
00521 end($oPaymentList);
00522 $sCheckedId = key( $oPaymentList );
00523 }
00524 $this->_sCheckedPaymentId = $sCheckedId;
00525 }
00526
00527 return $this->_sCheckedPaymentId;
00528 }
00529
00535 public function getPaymentCnt()
00536 {
00537 if ( $this->_iPaymentCnt === null ) {
00538 $this->_iPaymentCnt = false;
00539
00540 if ($oPaymentList = $this->getPaymentList()) {
00541 $this->_iPaymentCnt = count($oPaymentList);
00542 }
00543 }
00544 return $this->_iPaymentCnt;
00545 }
00546
00552 public function getCreditYears()
00553 {
00554 if ( $this->_aCreditYears === null ) {
00555 $this->_aCreditYears = false;
00556
00557 $this->_aCreditYears = range( date('Y'), date('Y') + 10 );
00558 }
00559 return $this->_aCreditYears;
00560 }
00561
00572 protected function _filterDynData()
00573 {
00574
00575 if (oxConfig::getInstance()->getConfigParam("blStoreCreditCardInfo"))
00576
00577 return;
00578
00579 $aDynData = $this->getSession()->getVar("dynvalue");
00580
00581 if ($aDynData) {
00582 $aDynData["kktype"] = null;
00583 $aDynData["kknumber"] = null;
00584 $aDynData["kkname"] = null;
00585 $aDynData["kkmonth"] = null;
00586 $aDynData["kkyear"] = null;
00587 $aDynData["kkpruef"] = null;
00588 $this->getSession()->setVar("dynvalue", $aDynData);
00589 }
00590
00591
00592 unset($_REQUEST["dynvalue"]["kktype"]);
00593 unset($_REQUEST["dynvalue"]["kknumber"]);
00594 unset($_REQUEST["dynvalue"]["kkname"]);
00595 unset($_REQUEST["dynvalue"]["kkmonth"]);
00596 unset($_REQUEST["dynvalue"]["kkyear"]);
00597 unset($_REQUEST["dynvalue"]["kkpruef"]);
00598
00599 unset($_POST["dynvalue"]["kktype"]);
00600 unset($_POST["dynvalue"]["kknumber"]);
00601 unset($_POST["dynvalue"]["kkname"]);
00602 unset($_POST["dynvalue"]["kkmonth"]);
00603 unset($_POST["dynvalue"]["kkyear"]);
00604 unset($_POST["dynvalue"]["kkpruef"]);
00605
00606 unset($_GET["dynvalue"]["kktype"]);
00607 unset($_GET["dynvalue"]["kknumber"]);
00608 unset($_GET["dynvalue"]["kkname"]);
00609 unset($_GET["dynvalue"]["kkmonth"]);
00610 unset($_GET["dynvalue"]["kkyear"]);
00611 unset($_GET["dynvalue"]["kkpruef"]);
00612
00613 }
00614
00620 public function getTsProtections()
00621 {
00622 if ( $this->_aTsProducts === null ) {
00623 $oBasket = $this->getSession()->getBasket();
00624 if ( $dPrice = $oBasket->getPrice()->getBruttoPrice() ) {
00625 $oTsProtection = oxNew('oxtsprotection');
00626 $this->_aTsProducts = $oTsProtection->getTsProducts($dPrice);
00627 }
00628 }
00629 return $this->_aTsProducts;
00630 }
00631
00637 public function getCheckedTsProductId()
00638 {
00639 if ( $this->_sCheckedProductId === null ) {
00640 $this->_sCheckedProductId = false;
00641 if ( $sId = oxConfig::getParameter( 'stsprotection' ) ) {
00642 $this->_sCheckedProductId = $sId;
00643 }
00644 }
00645 return $this->_sCheckedProductId;
00646 }
00647
00648 }