00001 <?php
00002
00006 require_once oxConfig::getInstance()->getConfigParam( 'sCoreDir' ) . "ccval/ccval.php";
00007
00013 class Payment extends oxUBase
00014 {
00019 protected $_oPaymentList = null;
00020
00025 protected $_iPaymentCnt = null;
00026
00031 protected $_aAllSets = null;
00032
00037 protected $_iAllSetsCnt = null;
00038
00043 protected $_oEmptyPayment = null;
00044
00049 protected $_sPaymentError = null;
00050
00055 protected $_sPaymentErrorText = null;
00056
00061 protected $_aDynValue = null;
00062
00067 protected $_sCheckedId = null;
00068
00073 protected $_sCheckedPaymentId = null;
00074
00079 protected $_aCreditYears = null;
00080
00085 protected $_sThisTemplate = 'payment.tpl';
00086
00091 protected $_blIsOrderStep = true;
00092
00098 public function init()
00099 {
00100 parent::init();
00101
00102 if ( ( $soxAddressId = oxConfig::getParameter( 'oxaddressid' ) ) ) {
00103 oxSession::setVar( 'deladdrid', $soxAddressId );
00104 }
00105 }
00106
00123 public function render()
00124 {
00125 parent::render();
00126
00127 $myConfig = $this->getConfig();
00128
00129
00130
00131
00132
00133 $blAlreadyRedirected = oxConfig::getParameter( 'sslredirect' ) == 'forced';
00134
00135 if ( $myConfig->getCurrentShopURL() != $myConfig->getSSLShopURL() && !$blAlreadyRedirected && !oxConfig::getParameter('fnc') ) {
00136 $sPayError = oxConfig::getParameter( 'payerror' )?'payerror='.oxConfig::getParameter( 'payerror' ):'';
00137 $sPayErrorText = oxConfig::getParameter('payerrortext')?'payerrortext='.oxConfig::getParameter( 'payerrortext' ):'';
00138 $sRedirectURL = $myConfig->getShopSecureHomeURL().'sslredirect=forced&cl=payment&'.$sPayError."&".$sPayErrorText;
00139 oxUtils::getInstance()->redirect( $sRedirectURL );
00140 }
00141
00142
00143 $oUser = $this->getUser();
00144 if ( !$oUser ) {
00145 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() );
00146 }
00147
00148
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 $this->_sPaymentError = -2;
00198 }
00199 } else {
00200 $this->_sPaymentError = -2;
00201 }
00202 }
00203
00209 protected function _unsetPaymentErrors()
00210 {
00211 $iPayError = oxConfig::getParameter( 'payerror' );
00212 $iPayErrorText = oxConfig::getParameter( 'payerrortext' );
00213
00214 if ( $iPayError ) {
00215 oxSession::deleteVar( 'payerror' );
00216 $this->_sPaymentError = $iPayError;
00217
00218 }
00219 if ( $iPayErrorText ) {
00220 oxSession::deleteVar( 'payerrortext' );
00221 $this->_sPaymentErrorText = $iPayErrorText;
00222
00223 }
00224 }
00225
00232 public function changeshipping()
00233 {
00234 $mySession = $this->getSession();
00235
00236 oxSession::setVar( 'sShipSet', oxConfig::getParameter( 'sShipSet' ) );
00237 $oBasket = $mySession->getBasket();
00238 $oBasket->setShipping( null );
00239 $oBasket->onUpdate();
00240 }
00241
00255 public function validatePayment()
00256 {
00257 $myConfig = $this->getConfig();
00258 $mySession = $this->getSession();
00259
00260
00261
00262 $oUser = $this->getUser();
00263 if ( !$oUser ) {
00264 oxSession::setVar( 'payerror', 2 );
00265 return;
00266 }
00267
00268 if (! ($sShipSetId = oxConfig::getParameter( 'sShipSet' ))) {
00269 $sShipSetId = oxSession::getVar('sShipSet');
00270 }
00271 $sPaymentId = oxConfig::getParameter( 'paymentid' );
00272 $aDynvalue = oxConfig::getParameter( 'dynvalue' );
00273
00274
00275 if ( !$myConfig->getConfigParam( 'blOtherCountryOrder' ) && $sPaymentId == 'oxempty' ) {
00276 $sPaymentId = '';
00277 }
00278
00279
00280 if ( !$sPaymentId ) {
00281 oxSession::setVar( 'payerror', 1 );
00282 return;
00283 }
00284
00285 $oBasket = $mySession->getBasket();
00286 $oBasket->setPayment(null);
00287 $oPayment = oxNew( 'oxpayment' );
00288 $oPayment->load( $sPaymentId );
00289
00290 $blOK = $oPayment->isValidPayment( $aDynvalue, $myConfig->getShopId(), $oUser, $oBasket->getPrice()->getBruttoPrice(), $sShipSetId );
00291
00292 if ( $blOK ) {
00293 oxSession::setVar( 'paymentid', $sPaymentId );
00294 oxSession::setVar( 'dynvalue', $aDynvalue );
00295 oxSession::deleteVar( '_selected_paymentid' );
00296 return 'order';
00297 } else {
00298 oxSession::setVar( 'payerror', 1 );
00299
00300
00301 oxSession::deleteVar( 'paymentid' );
00302 oxSession::setVar( '_selected_paymentid', $sPaymentId );
00303 return;
00304 }
00305 }
00306
00312 public function getPaymentList()
00313 {
00314 if ( $this->_oPaymentList === null ) {
00315 $this->_oPaymentList = false;
00316
00317 $sActShipSet = oxConfig::getParameter( 'sShipSet' );
00318 $oBasket = $this->getSession()->getBasket();
00319
00320
00321 list( $aAllSets, $sActShipSet, $aPaymentList ) = oxDeliverySetList::getInstance()->getDeliverySetData( $sActShipSet, $this->getUser(), $oBasket );
00322
00323 oxSession::setVar( 'sShipSet', $sActShipSet );
00324
00325 $this->_setDeprecatedValues( $aPaymentList, $oBasket );
00326 $this->_oPaymentList = $aPaymentList;
00327 $this->_aAllSets = $aAllSets;
00328
00329 }
00330 return $this->_oPaymentList;
00331 }
00332
00338 public function getAllSets()
00339 {
00340 if ( $this->_aAllSets === null ) {
00341 $this->_aAllSets = false;
00342
00343 if ($this->getPaymentList()) {
00344 return $this->_aAllSets;
00345 }
00346 }
00347 return $this->_aAllSets;
00348 }
00349
00355 public function getAllSetsCnt()
00356 {
00357 if ( $this->_iAllSetsCnt === null ) {
00358 $this->_iAllSetsCnt = 0;
00359
00360 if ($this->getPaymentList()) {
00361 $this->_iAllSetsCnt = count($this->_aAllSets);
00362 }
00363 }
00364 return $this->_iAllSetsCnt;
00365 }
00366
00375 protected function _setDeprecatedValues( & $aPaymentList, $oBasket = null )
00376 {
00377 if ( is_array($aPaymentList) ) {
00378 foreach ( $aPaymentList as $oPayment ) {
00379 $oPrice = $oPayment->getPaymentPrice( $oBasket );
00380 $oPayment->dAddPaymentSum = $oPrice->getBruttoPrice();
00381 $oPayment->fAddPaymentSum = oxLang::getInstance()->formatCurrency( $oPayment->dAddPaymentSum, $oBasket->getBasketCurrency() );
00382 $oPayment->aDynValues = $oPayment->getDynValues();
00383 if ( $oPayment->oxpayments__oxchecked->value ) {
00384 $this->_sCheckedId = $oPayment->getId();
00385 }
00386 }
00387 }
00388 }
00389
00395 public function getEmptyPayment()
00396 {
00397 return $this->_oEmptyPayment;
00398 }
00399
00405 public function getPaymentError()
00406 {
00407 return $this->_sPaymentError;
00408 }
00409
00415 public function getPaymentErrorText()
00416 {
00417 return $this->_sPaymentErrorText;
00418 }
00419
00425 public function getDynValue()
00426 {
00427 if ( $this->_aDynValue === null ) {
00428 $this->_aDynValue = false;
00429
00430
00431 if ( ( $aDynValue = oxSession::getVar( 'dynvalue' ) ) ) {
00432 $this->_aDynValue = $aDynValue;
00433 } else {
00434 $this->_aDynValue = oxConfig::getParameter( "dynvalue");
00435 }
00436
00437
00438
00439 $aPaymentList = $this->getPaymentList();
00440 if ( isset( $aPaymentList['oxiddebitnote'] ) ) {
00441 $this->_assignDebitNoteParams();
00442 }
00443 }
00444 return $this->_aDynValue;
00445 }
00446
00453 protected function _assignDebitNoteParams()
00454 {
00455
00456 $oUserPayment = oxNew( 'oxuserpayment');
00457
00458 if ( $oUserPayment->getPaymentByPaymentType( $this->getUser(), 'oxiddebitnote' ) ) {
00459 $aAddPaymentData = oxUtils::getInstance()->assignValuesFromText( $oUserPayment->oxuserpayments__oxvalue->value );
00460
00461
00462 foreach ( $aAddPaymentData as $oData ) {
00463 if ( !isset( $this->_aDynValue[$oData->name] ) ||
00464 ( isset( $this->_aDynValue[$oData->name] ) && !$this->_aDynValue[$oData->name] ) ) {
00465 $this->_aDynValue[$oData->name] = $oData->value;
00466 }
00467 }
00468 }
00469 }
00470
00477 public function getCheckedPaymentId()
00478 {
00479 if ( $this->_sCheckedPaymentId === null ) {
00480 if ( ( $sPaymentID = oxConfig::getParameter( 'paymentid' ) ) ) {
00481 $sCheckedId = $sPaymentID;
00482 } elseif ( ( $sSelectedPaymentID = oxSession::getVar( '_selected_paymentid' ) ) ) {
00483 $sCheckedId = $sSelectedPaymentID;
00484 } else {
00485
00486 if ( $oUser = $this->getUser()) {
00487 $oOrder = oxNew('oxorder');
00488 if ( ( $sLastPaymentId = $oOrder->getLastUserPaymentType( $oUser->getId()) ) ) {
00489 $sCheckedId = $sLastPaymentId;
00490 }
00491 }
00492 }
00493
00494
00495 if ( !$sCheckedId && $this->_sCheckedId ) {
00496 $sCheckedId = $this->_sCheckedId;
00497 }
00498
00499
00500 $oPaymentList = $this->getPaymentList();
00501 if ( isset( $oPaymentList ) && !isset( $oPaymentList[$sCheckedId] ) ) {
00502 end($oPaymentList);
00503 $sCheckedId = key( $oPaymentList );
00504 }
00505 $this->_sCheckedPaymentId = $sCheckedId;
00506 }
00507
00508 return $this->_sCheckedPaymentId;
00509 }
00510
00516 public function getPaymentCnt()
00517 {
00518 if ( $this->_iPaymentCnt === null ) {
00519 $this->_iPaymentCnt = false;
00520
00521 if ($oPaymentList = $this->getPaymentList()) {
00522 $this->_iPaymentCnt = count($oPaymentList);
00523 }
00524 }
00525 return $this->_iPaymentCnt;
00526 }
00527
00533 public function getCreditYears()
00534 {
00535 if ( $this->_aCreditYears === null ) {
00536 $this->_aCreditYears = false;
00537
00538 $this->_aCreditYears = range( date('Y'), date('Y') + 10 );
00539 }
00540 return $this->_aCreditYears;
00541 }
00542
00543 }