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 parent::init();
00100
00101 if ( ( $soxAddressId = oxConfig::getParameter( 'oxaddressid' ) ) ) {
00102 oxSession::setVar( 'deladdrid', $soxAddressId );
00103 }
00104 }
00105
00122 public function render()
00123 {
00124 parent::render();
00125
00126 $myConfig = $this->getConfig();
00127
00128
00129
00130
00131
00132 $blAlreadyRedirected = oxConfig::getParameter( 'sslredirect' ) == 'forced';
00133
00134 if ( $myConfig->getCurrentShopURL() != $myConfig->getSSLShopURL() && !$blAlreadyRedirected && !oxConfig::getParameter('fnc') ) {
00135 $sPayError = oxConfig::getParameter( 'payerror' )?'payerror='.oxConfig::getParameter( 'payerror' ):'';
00136 $sPayErrorText = oxConfig::getParameter('payerrortext')?'payerrortext='.oxConfig::getParameter( 'payerrortext' ):'';
00137 $sRedirectURL = $myConfig->getShopSecureHomeURL().'sslredirect=forced&cl=payment&'.$sPayError."&".$sPayErrorText;
00138 oxUtils::getInstance()->redirect( $sRedirectURL );
00139 }
00140
00141
00142
00143 $oUser = $this->getUser();
00144 $oBasket = $this->getSession()->getBasket();
00145 if ( !$oBasket || !$oUser || ( $oBasket && !$oBasket->getProductsCount() ) ) {
00146 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() );
00147 }
00148
00149
00150 $this->_aViewData[ 'payments' ] = $this->getPaymentList();
00151
00152
00153 $this->_aViewData['allShipsetsCnt'] = $this->getAllSetsCnt();
00154 $this->_aViewData['allShipsets'] = $this->getAllSets();
00155
00156 if ( !$this->getAllSetsCnt() ) {
00157
00158 $this->_setDefaultEmptyPayment();
00159 oxSession::setVar( 'sShipSet', null );
00160 }
00161
00162 $this->_unsetPaymentErrors();
00163
00164 $this->_aViewData['oxemptypayment'] = $this->getEmptyPayment();
00165 $this->_aViewData['payerror'] = $this->getPaymentError();
00166 $this->_aViewData['payerrortext'] = $this->getPaymentErrorText();
00167
00168 $this->_aViewData['dynvalue'] = $this->getDynValue();
00169
00170
00171 $this->_aViewData['defpaymentid'] = $this->getCheckedPaymentId();
00172 $this->_aViewData['paymencnt'] = $this->getPaymentCnt();
00173
00174
00175 $this->_aViewData['creditYears'] = $this->getCreditYears();
00176
00177 return $this->_sThisTemplate;
00178 }
00179
00187 protected function _setDefaultEmptyPayment()
00188 {
00189
00190 if ( $this->getConfig()->getConfigParam( 'blOtherCountryOrder' ) ) {
00191 $oPayment = oxNew( 'oxpayment' );
00192 if ( $oPayment->load( 'oxempty' ) ) {
00193 $this->_oEmptyPayment = $oPayment;
00194 } else {
00195 $this->_sPaymentError = -2;
00196 }
00197 } else {
00198 $this->_sPaymentError = -2;
00199 }
00200 }
00201
00207 protected function _unsetPaymentErrors()
00208 {
00209 $iPayError = oxConfig::getParameter( 'payerror' );
00210 $iPayErrorText = oxConfig::getParameter( 'payerrortext' );
00211
00212 if ( $iPayError ) {
00213 oxSession::deleteVar( 'payerror' );
00214 $this->_sPaymentError = $iPayError;
00215
00216 }
00217 if ( $iPayErrorText ) {
00218 oxSession::deleteVar( 'payerrortext' );
00219 $this->_sPaymentErrorText = $iPayErrorText;
00220
00221 }
00222 }
00223
00230 public function changeshipping()
00231 {
00232 $mySession = $this->getSession();
00233
00234 oxSession::setVar( 'sShipSet', oxConfig::getParameter( 'sShipSet' ) );
00235 $oBasket = $mySession->getBasket();
00236 $oBasket->setShipping( null );
00237 $oBasket->onUpdate();
00238 }
00239
00253 public function validatePayment()
00254 {
00255 $myConfig = $this->getConfig();
00256 $mySession = $this->getSession();
00257
00258
00259
00260 $oUser = $this->getUser();
00261 if ( !$oUser ) {
00262 oxSession::setVar( 'payerror', 2 );
00263 return;
00264 }
00265
00266 if (! ($sShipSetId = oxConfig::getParameter( 'sShipSet' ))) {
00267 $sShipSetId = oxSession::getVar('sShipSet');
00268 }
00269 $sPaymentId = oxConfig::getParameter( 'paymentid' );
00270 $aDynvalue = oxConfig::getParameter( 'dynvalue' );
00271
00272
00273 if ( !$myConfig->getConfigParam( 'blOtherCountryOrder' ) && $sPaymentId == 'oxempty' ) {
00274 $sPaymentId = '';
00275 }
00276
00277
00278 if ( !$sPaymentId ) {
00279 oxSession::setVar( 'payerror', 1 );
00280 return;
00281 }
00282
00283 $oBasket = $mySession->getBasket();
00284 $oBasket->setPayment(null);
00285 $oPayment = oxNew( 'oxpayment' );
00286 $oPayment->load( $sPaymentId );
00287
00288 $blOK = $oPayment->isValidPayment( $aDynvalue, $myConfig->getShopId(), $oUser, $oBasket->getPrice()->getBruttoPrice(), $sShipSetId );
00289
00290 if ( $blOK ) {
00291 oxSession::setVar( 'paymentid', $sPaymentId );
00292 oxSession::setVar( 'dynvalue', $aDynvalue );
00293 oxSession::deleteVar( '_selected_paymentid' );
00294 return 'order';
00295 } else {
00296 oxSession::setVar( 'payerror', 1 );
00297
00298
00299 oxSession::deleteVar( 'paymentid' );
00300 oxSession::setVar( '_selected_paymentid', $sPaymentId );
00301 return;
00302 }
00303 }
00304
00310 public function getPaymentList()
00311 {
00312 if ( $this->_oPaymentList === null ) {
00313 $this->_oPaymentList = false;
00314
00315 $sActShipSet = oxConfig::getParameter( 'sShipSet' );
00316 $oBasket = $this->getSession()->getBasket();
00317
00318
00319 list( $aAllSets, $sActShipSet, $aPaymentList ) = oxDeliverySetList::getInstance()->getDeliverySetData( $sActShipSet, $this->getUser(), $oBasket );
00320
00321 oxSession::setVar( 'sShipSet', $sActShipSet );
00322
00323 $this->_setDeprecatedValues( $aPaymentList, $oBasket );
00324 $this->_oPaymentList = $aPaymentList;
00325 $this->_aAllSets = $aAllSets;
00326
00327 }
00328 return $this->_oPaymentList;
00329 }
00330
00336 public function getAllSets()
00337 {
00338 if ( $this->_aAllSets === null ) {
00339 $this->_aAllSets = false;
00340
00341 if ($this->getPaymentList()) {
00342 return $this->_aAllSets;
00343 }
00344 }
00345 return $this->_aAllSets;
00346 }
00347
00353 public function getAllSetsCnt()
00354 {
00355 if ( $this->_iAllSetsCnt === null ) {
00356 $this->_iAllSetsCnt = 0;
00357
00358 if ($this->getPaymentList()) {
00359 $this->_iAllSetsCnt = count($this->_aAllSets);
00360 }
00361 }
00362 return $this->_iAllSetsCnt;
00363 }
00364
00373 protected function _setDeprecatedValues( & $aPaymentList, $oBasket = null )
00374 {
00375 if ( is_array($aPaymentList) ) {
00376 $oLang = oxLang::getInstance();
00377 foreach ( $aPaymentList as $oPayment ) {
00378 $oPrice = $oPayment->getPaymentPrice( $oBasket );
00379 $oPayment->dAddPaymentSum = $oPrice->getBruttoPrice();
00380 $oPayment->fAddPaymentSum = $oLang->formatCurrency( $oPayment->dAddPaymentSum, $oBasket->getBasketCurrency() );
00381 $oPayment->aDynValues = $oPayment->getDynValues();
00382 if ( $oPayment->oxpayments__oxchecked->value ) {
00383 $this->_sCheckedId = $oPayment->getId();
00384 }
00385 }
00386 }
00387 }
00388
00394 public function getEmptyPayment()
00395 {
00396 return $this->_oEmptyPayment;
00397 }
00398
00404 public function getPaymentError()
00405 {
00406 return $this->_sPaymentError;
00407 }
00408
00414 public function getPaymentErrorText()
00415 {
00416 return $this->_sPaymentErrorText;
00417 }
00418
00424 public function getDynValue()
00425 {
00426 if ( $this->_aDynValue === null ) {
00427 $this->_aDynValue = false;
00428
00429
00430 if ( ( $aDynValue = oxSession::getVar( 'dynvalue' ) ) ) {
00431 $this->_aDynValue = $aDynValue;
00432 } else {
00433 $this->_aDynValue = oxConfig::getParameter( "dynvalue");
00434 }
00435
00436
00437
00438 $aPaymentList = $this->getPaymentList();
00439 if ( isset( $aPaymentList['oxiddebitnote'] ) ) {
00440 $this->_assignDebitNoteParams();
00441 }
00442 }
00443 return $this->_aDynValue;
00444 }
00445
00452 protected function _assignDebitNoteParams()
00453 {
00454
00455 $oUserPayment = oxNew( 'oxuserpayment');
00456
00457 if ( $oUserPayment->getPaymentByPaymentType( $this->getUser(), 'oxiddebitnote' ) ) {
00458 $aAddPaymentData = oxUtils::getInstance()->assignValuesFromText( $oUserPayment->oxuserpayments__oxvalue->value );
00459
00460
00461 foreach ( $aAddPaymentData as $oData ) {
00462 if ( !isset( $this->_aDynValue[$oData->name] ) ||
00463 ( isset( $this->_aDynValue[$oData->name] ) && !$this->_aDynValue[$oData->name] ) ) {
00464 $this->_aDynValue[$oData->name] = $oData->value;
00465 }
00466 }
00467 }
00468 }
00469
00476 public function getCheckedPaymentId()
00477 {
00478 if ( $this->_sCheckedPaymentId === null ) {
00479 if ( ( $sPaymentID = oxConfig::getParameter( 'paymentid' ) ) ) {
00480 $sCheckedId = $sPaymentID;
00481 } elseif ( ( $sSelectedPaymentID = oxSession::getVar( '_selected_paymentid' ) ) ) {
00482 $sCheckedId = $sSelectedPaymentID;
00483 } else {
00484
00485 if ( $oUser = $this->getUser()) {
00486 $oOrder = oxNew('oxorder');
00487 if ( ( $sLastPaymentId = $oOrder->getLastUserPaymentType( $oUser->getId()) ) ) {
00488 $sCheckedId = $sLastPaymentId;
00489 }
00490 }
00491 }
00492
00493
00494 if ( !$sCheckedId && $this->_sCheckedId ) {
00495 $sCheckedId = $this->_sCheckedId;
00496 }
00497
00498
00499 $oPaymentList = $this->getPaymentList();
00500 if ( isset( $oPaymentList ) && !isset( $oPaymentList[$sCheckedId] ) ) {
00501 end($oPaymentList);
00502 $sCheckedId = key( $oPaymentList );
00503 }
00504 $this->_sCheckedPaymentId = $sCheckedId;
00505 }
00506
00507 return $this->_sCheckedPaymentId;
00508 }
00509
00515 public function getPaymentCnt()
00516 {
00517 if ( $this->_iPaymentCnt === null ) {
00518 $this->_iPaymentCnt = false;
00519
00520 if ($oPaymentList = $this->getPaymentList()) {
00521 $this->_iPaymentCnt = count($oPaymentList);
00522 }
00523 }
00524 return $this->_iPaymentCnt;
00525 }
00526
00532 public function getCreditYears()
00533 {
00534 if ( $this->_aCreditYears === null ) {
00535 $this->_aCreditYears = false;
00536
00537 $this->_aCreditYears = range( date('Y'), date('Y') + 10 );
00538 }
00539 return $this->_aCreditYears;
00540 }
00541
00542 }