payment.php
Go to the documentation of this file.00001 <?php
00002
00006 require_once oxConfig::getInstance()->getConfigParam( 'sCoreDir' ) . "ccval/ccval.php";
00007
00012 class Payment extends oxUBase
00013 {
00018 protected $_oPaymentList = null;
00019
00024 protected $_iPaymentCnt = null;
00025
00030 protected $_aAllSets = null;
00031
00036 protected $_iAllSetsCnt = null;
00037
00042 protected $_oEmptyPayment = null;
00043
00048 protected $_sPaymentError = null;
00049
00054 protected $_sPaymentErrorText = null;
00055
00060 protected $_aDynValue = null;
00061
00066 protected $_sCheckedId = null;
00067
00072 protected $_sCheckedPaymentId = null;
00073
00078 protected $_aCreditYears = null;
00079
00084 protected $_sThisTemplate = 'payment.tpl';
00085
00090 protected $_blIsOrderStep = true;
00091
00097 public function init()
00098 {
00099 $this->_filterDynData();
00100
00101 parent::init();
00102
00103 if ( ( $soxAddressId = oxConfig::getParameter( 'oxaddressid' ) ) ) {
00104 oxSession::setVar( 'deladdrid', $soxAddressId );
00105 }
00106 }
00107
00124 public function render()
00125 {
00126 parent::render();
00127
00128 $myConfig = $this->getConfig();
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 $oUser = $this->getUser();
00146 $oBasket = $this->getSession()->getBasket();
00147 if ( !$oBasket || !$oUser || ( $oBasket && !$oBasket->getProductsCount() ) ) {
00148 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() .'cl=start' );
00149 }
00150
00151
00152 $this->_aViewData[ 'payments' ] = $this->getPaymentList();
00153
00154
00155 $this->_aViewData['allShipsetsCnt'] = $this->getAllSetsCnt();
00156 $this->_aViewData['allShipsets'] = $this->getAllSets();
00157
00158 if ( !$this->getAllSetsCnt() ) {
00159
00160 $this->_setDefaultEmptyPayment();
00161 oxSession::setVar( 'sShipSet', null );
00162 }
00163
00164 $this->_unsetPaymentErrors();
00165
00166 $this->_aViewData['oxemptypayment'] = $this->getEmptyPayment();
00167 $this->_aViewData['payerror'] = $this->getPaymentError();
00168 $this->_aViewData['payerrortext'] = $this->getPaymentErrorText();
00169
00170 $this->_aViewData['dynvalue'] = $this->getDynValue();
00171
00172
00173 $this->_aViewData['defpaymentid'] = $this->getCheckedPaymentId();
00174 $this->_aViewData['paymencnt'] = $this->getPaymentCnt();
00175
00176
00177 $this->_aViewData['creditYears'] = $this->getCreditYears();
00178
00179 return $this->_sThisTemplate;
00180 }
00181
00189 protected function _setDefaultEmptyPayment()
00190 {
00191
00192 if ( $this->getConfig()->getConfigParam( 'blOtherCountryOrder' ) ) {
00193 $oPayment = oxNew( 'oxpayment' );
00194 if ( $oPayment->load( 'oxempty' ) ) {
00195 $this->_oEmptyPayment = $oPayment;
00196 } else {
00197
00198 $this->_sPaymentError = -2;
00199 }
00200 } else {
00201 $this->_sPaymentError = -2;
00202 }
00203 }
00204
00210 protected function _unsetPaymentErrors()
00211 {
00212 $iPayError = oxConfig::getParameter( 'payerror' );
00213 $iPayErrorText = oxConfig::getParameter( 'payerrortext' );
00214
00215 if ( $iPayError ) {
00216 oxSession::deleteVar( 'payerror' );
00217 $this->_sPaymentError = $iPayError;
00218
00219 }
00220 if ( $iPayErrorText ) {
00221 oxSession::deleteVar( 'payerrortext' );
00222 $this->_sPaymentErrorText = $iPayErrorText;
00223
00224 }
00225 }
00226
00233 public function changeshipping()
00234 {
00235 $mySession = $this->getSession();
00236
00237 oxSession::setVar( 'sShipSet', oxConfig::getParameter( 'sShipSet' ) );
00238 $oBasket = $mySession->getBasket();
00239 $oBasket->setShipping( null );
00240 $oBasket->onUpdate();
00241 }
00242
00256 public function validatePayment()
00257 {
00258 $myConfig = $this->getConfig();
00259 $mySession = $this->getSession();
00260
00261
00262
00263 $oUser = $this->getUser();
00264 if ( !$oUser ) {
00265 oxSession::setVar( 'payerror', 2 );
00266 return;
00267 }
00268
00269 if (! ($sShipSetId = oxConfig::getParameter( 'sShipSet' ))) {
00270 $sShipSetId = oxSession::getVar('sShipSet');
00271 }
00272 $sPaymentId = oxConfig::getParameter( 'paymentid' );
00273 $aDynvalue = oxConfig::getParameter( 'dynvalue' );
00274
00275
00276 if ( !$myConfig->getConfigParam( 'blOtherCountryOrder' ) && $sPaymentId == 'oxempty' ) {
00277 $sPaymentId = '';
00278 }
00279
00280
00281 if ( !$sPaymentId ) {
00282 oxSession::setVar( 'payerror', 1 );
00283 return;
00284 }
00285
00286 $oBasket = $mySession->getBasket();
00287 $oBasket->setPayment(null);
00288 $oPayment = oxNew( 'oxpayment' );
00289 $oPayment->load( $sPaymentId );
00290
00291
00292 $dBasketPrice = $oBasket->getPriceForPayment();
00293
00294 $blOK = $oPayment->isValidPayment( $aDynvalue, $myConfig->getShopId(), $oUser, $dBasketPrice, $sShipSetId );
00295
00296 if ( $blOK ) {
00297 oxSession::setVar( 'paymentid', $sPaymentId );
00298 oxSession::setVar( 'dynvalue', $aDynvalue );
00299 $oBasket->setShipping($sShipSetId);
00300 oxSession::deleteVar( '_selected_paymentid' );
00301 return 'order';
00302 } else {
00303 oxSession::setVar( 'payerror', $oPayment->getPaymentErrorNumber() );
00304
00305
00306 oxSession::deleteVar( 'paymentid' );
00307 oxSession::setVar( '_selected_paymentid', $sPaymentId );
00308 return;
00309 }
00310 }
00311
00317 public function getPaymentList()
00318 {
00319 if ( $this->_oPaymentList === null ) {
00320 $this->_oPaymentList = false;
00321
00322 $sActShipSet = oxConfig::getParameter( 'sShipSet' );
00323 $oBasket = $this->getSession()->getBasket();
00324
00325
00326 list( $aAllSets, $sActShipSet, $aPaymentList ) = oxDeliverySetList::getInstance()->getDeliverySetData( $sActShipSet, $this->getUser(), $oBasket );
00327
00328 oxSession::setVar( 'sShipSet', $sActShipSet );
00329 $oBasket->setShipping( $sActShipSet );
00330
00331
00332 $this->_setDeprecatedValues( $aPaymentList, $oBasket );
00333 $this->_oPaymentList = $aPaymentList;
00334 $this->_aAllSets = $aAllSets;
00335
00336 }
00337 return $this->_oPaymentList;
00338 }
00339
00345 public function getAllSets()
00346 {
00347 if ( $this->_aAllSets === null ) {
00348 $this->_aAllSets = false;
00349
00350 if ($this->getPaymentList()) {
00351 return $this->_aAllSets;
00352 }
00353 }
00354 return $this->_aAllSets;
00355 }
00356
00362 public function getAllSetsCnt()
00363 {
00364 if ( $this->_iAllSetsCnt === null ) {
00365 $this->_iAllSetsCnt = 0;
00366
00367 if ($this->getPaymentList()) {
00368 $this->_iAllSetsCnt = count($this->_aAllSets);
00369 }
00370 }
00371 return $this->_iAllSetsCnt;
00372 }
00373
00382 protected function _setDeprecatedValues( & $aPaymentList, $oBasket = null )
00383 {
00384 if ( is_array($aPaymentList) ) {
00385 $oLang = oxLang::getInstance();
00386 foreach ( $aPaymentList as $oPayment ) {
00387 $oPrice = $oPayment->getPaymentPrice( $oBasket );
00388 $oPayment->dAddPaymentSum = $oPrice->getBruttoPrice();
00389 $oPayment->fAddPaymentSum = $oLang->formatCurrency( $oPayment->dAddPaymentSum, $oBasket->getBasketCurrency() );
00390 $oPayment->aDynValues = $oPayment->getDynValues();
00391 if ( $oPayment->oxpayments__oxchecked->value ) {
00392 $this->_sCheckedId = $oPayment->getId();
00393 }
00394 }
00395 }
00396 }
00397
00403 public function getEmptyPayment()
00404 {
00405 return $this->_oEmptyPayment;
00406 }
00407
00413 public function getPaymentError()
00414 {
00415 return $this->_sPaymentError;
00416 }
00417
00423 public function getPaymentErrorText()
00424 {
00425 return $this->_sPaymentErrorText;
00426 }
00427
00433 public function getDynValue()
00434 {
00435 if ( $this->_aDynValue === null ) {
00436 $this->_aDynValue = false;
00437
00438
00439 if ( ( $aDynValue = oxSession::getVar( 'dynvalue' ) ) ) {
00440 $this->_aDynValue = $aDynValue;
00441 } else {
00442 $this->_aDynValue = oxConfig::getParameter( "dynvalue");
00443 }
00444
00445
00446
00447 $aPaymentList = $this->getPaymentList();
00448 if ( isset( $aPaymentList['oxiddebitnote'] ) ) {
00449 $this->_assignDebitNoteParams();
00450 }
00451 }
00452 return $this->_aDynValue;
00453 }
00454
00461 protected function _assignDebitNoteParams()
00462 {
00463
00464 $oUserPayment = oxNew( 'oxuserpayment');
00465
00466 if ( $oUserPayment->getPaymentByPaymentType( $this->getUser(), 'oxiddebitnote' ) ) {
00467 $aAddPaymentData = oxUtils::getInstance()->assignValuesFromText( $oUserPayment->oxuserpayments__oxvalue->value );
00468
00469
00470 foreach ( $aAddPaymentData as $oData ) {
00471 if ( !isset( $this->_aDynValue[$oData->name] ) ||
00472 ( isset( $this->_aDynValue[$oData->name] ) && !$this->_aDynValue[$oData->name] ) ) {
00473 $this->_aDynValue[$oData->name] = $oData->value;
00474 }
00475 }
00476 }
00477 }
00478
00485 public function getCheckedPaymentId()
00486 {
00487 if ( $this->_sCheckedPaymentId === null ) {
00488 if ( ( $sPaymentID = oxConfig::getParameter( 'paymentid' ) ) ) {
00489 $sCheckedId = $sPaymentID;
00490 } elseif ( ( $sSelectedPaymentID = oxSession::getVar( '_selected_paymentid' ) ) ) {
00491 $sCheckedId = $sSelectedPaymentID;
00492 } else {
00493
00494 if ( $oUser = $this->getUser()) {
00495 $oOrder = oxNew('oxorder');
00496 if ( ( $sLastPaymentId = $oOrder->getLastUserPaymentType( $oUser->getId()) ) ) {
00497 $sCheckedId = $sLastPaymentId;
00498 }
00499 }
00500 }
00501
00502
00503 if ( !$sCheckedId && $this->_sCheckedId ) {
00504 $sCheckedId = $this->_sCheckedId;
00505 }
00506
00507
00508 $oPaymentList = $this->getPaymentList();
00509 if ( isset( $oPaymentList ) && $oPaymentList && !isset( $oPaymentList[$sCheckedId] ) ) {
00510 end($oPaymentList);
00511 $sCheckedId = key( $oPaymentList );
00512 }
00513 $this->_sCheckedPaymentId = $sCheckedId;
00514 }
00515
00516 return $this->_sCheckedPaymentId;
00517 }
00518
00524 public function getPaymentCnt()
00525 {
00526 if ( $this->_iPaymentCnt === null ) {
00527 $this->_iPaymentCnt = false;
00528
00529 if ($oPaymentList = $this->getPaymentList()) {
00530 $this->_iPaymentCnt = count($oPaymentList);
00531 }
00532 }
00533 return $this->_iPaymentCnt;
00534 }
00535
00541 public function getCreditYears()
00542 {
00543 if ( $this->_aCreditYears === null ) {
00544 $this->_aCreditYears = false;
00545
00546 $this->_aCreditYears = range( date('Y'), date('Y') + 10 );
00547 }
00548 return $this->_aCreditYears;
00549 }
00550
00561 protected function _filterDynData()
00562 {
00563
00564 if (oxConfig::getInstance()->getConfigParam("blStoreCreditCardInfo"))
00565
00566 return;
00567
00568 $aDynData = $this->getSession()->getVar("dynvalue");
00569
00570 if ($aDynData) {
00571 $aDynData["kktype"] = null;
00572 $aDynData["kknumber"] = null;
00573 $aDynData["kkname"] = null;
00574 $aDynData["kkmonth"] = null;
00575 $aDynData["kkyear"] = null;
00576 $aDynData["kkpruef"] = null;
00577 $this->getSession()->setVar("dynvalue", $aDynData);
00578 }
00579
00580
00581 unset($_REQUEST["dynvalue"]["kktype"]);
00582 unset($_REQUEST["dynvalue"]["kknumber"]);
00583 unset($_REQUEST["dynvalue"]["kkname"]);
00584 unset($_REQUEST["dynvalue"]["kkmonth"]);
00585 unset($_REQUEST["dynvalue"]["kkyear"]);
00586 unset($_REQUEST["dynvalue"]["kkpruef"]);
00587
00588 unset($_POST["dynvalue"]["kktype"]);
00589 unset($_POST["dynvalue"]["kknumber"]);
00590 unset($_POST["dynvalue"]["kkname"]);
00591 unset($_POST["dynvalue"]["kkmonth"]);
00592 unset($_POST["dynvalue"]["kkyear"]);
00593 unset($_POST["dynvalue"]["kkpruef"]);
00594
00595 unset($_GET["dynvalue"]["kktype"]);
00596 unset($_GET["dynvalue"]["kknumber"]);
00597 unset($_GET["dynvalue"]["kkname"]);
00598 unset($_GET["dynvalue"]["kkmonth"]);
00599 unset($_GET["dynvalue"]["kkyear"]);
00600 unset($_GET["dynvalue"]["kkpruef"]);
00601
00602 }
00603
00604 }