oxtsprotection.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxtsprotection extends oxSuperCfg
00007 {
00013     protected $_aProducts = null;
00014     
00020     protected $_aProductIds = null;
00021 
00027     protected $_aProductNettPrices = null;
00028 
00034     protected $_aProductAmounts = null;
00035 
00041     protected $_sTsProtectProducts = array( "TS080501_500_30_EUR"   => array( "netto" => "0.82", "amount" => "500" ),
00042                                        "TS080501_1500_30_EUR"  => array( "netto" => "2.47", "amount" => "1500" ),
00043                                        "TS080501_2500_30_EUR"  => array( "netto" => "4.12", "amount" => "2500" ),
00044                                        "TS080501_5000_30_EUR"  => array( "netto" => "8.24", "amount" => "5000" ),
00045                                        "TS080501_10000_30_EUR" => array( "netto" => "16.47", "amount" => "10000" ),
00046                                        "TS080501_20000_30_EUR" => array( "netto" => "32.94", "amount" => "20000" )
00047                                 );
00048 
00054     protected $_sTsCurrencyProducts = array( "TS080501_500_30_EUR"   => array( "GBP" => "TS100629_500_30_GBP", "CHF" => "TS100629_1500_30_GBP", "USD" => "TS080501_500_30_USD" ),
00055                                        "TS080501_1500_30_EUR"  => array( "GBP" => "TS100629_1500_30_GBP", "CHF" => "TS100629_1500_30_CHF", "USD" => "TS100629_1500_30_USD" ),
00056                                        "TS080501_2500_30_EUR"  => array( "GBP" => "TS100629_2500_30_GBP", "CHF" => "TS100629_2500_30_CHF", "USD" => "TS100629_2500_30_USD" ),
00057                                        "TS080501_5000_30_EUR"  => array( "GBP" => "TS100629_5000_30_GBP", "CHF" => "TS100629_5000_30_CHF", "USD" => "TS100629_5000_30_USD" ),
00058                                        "TS080501_10000_30_EUR" => array( "GBP" => "TS100629_1000_30_GBP", "CHF" => "TS100629_10000_30_CHF", "USD" => "TS100629_10000_30_USD" ),
00059                                        "TS080501_20000_30_EUR" => array( "GBP" => "TS100629_2000_30_GBP", "CHF" => "TS100629_20000_30_CHF", "USD" => "TS100629_20000_30_USD" )
00060                                 );
00061 
00067     public function __construct()
00068     {
00069         $this->_aProductIds        = $this->_getTsProductIds();
00070         $this->_aProductNettPrices = $this->_getProductNettPrices();
00071         $this->_aProductAmounts    = $this->_getProductAmounts();
00072     }
00073 
00081     public function getTsProducts( $dPrice )
00082     {
00083         $oProduct = $this->getProduct( 0 );
00084         $aTsProducts = array($oProduct);
00085         for ($i=0; $i<count($this->_aProductIds); $i++ ) {
00086             if ( $this->_aProductAmounts[$i] < $dPrice ) {
00087                 $oProduct = $this->getProduct( $i+1 );
00088                 $aTsProducts[] = $oProduct;
00089             } else {
00090                 $i = count($this->_aProductIds);
00091             }
00092         }
00093         return $aTsProducts;
00094     }
00095 
00103     public function getTsProduct( $sTsId )
00104     {
00105         $sKey = array_search( $sTsId, $this->_aProductIds );
00106         $oProduct = $this->getProduct( $sKey );
00107         return $oProduct;
00108     }
00109 
00117     public function getProduct( $sKey )
00118     {
00119         $oConfig  = $this->getConfig();
00120         $dVat     = $oConfig->getConfigParam( 'dDefaultVAT' );
00121         $dPrice   = oxPrice::netto2Brutto($this->_aProductNettPrices[$sKey], $dVat);
00122         $oProduct = new oxStdClass();
00123         $oProduct->oPrice = oxNew( 'oxPrice' );
00124         $oProduct->oPrice->setPrice( $dPrice );
00125         if ( $oConfig->getConfigParam( 'blCalcVATForPayCharge' ) ) {
00126             $oProduct->oPrice->setVat( $dVat );
00127         }
00128         $oProduct->sTsId = $this->_aProductIds[$sKey];
00129         $oProduct->iAmount = $this->_aProductAmounts[$sKey];
00130         $oProduct->fPrice = $oProduct->oPrice->getBruttoPrice();
00131         return $oProduct;
00132     }
00133 
00142     public function requestForTsProtection( $aValues, $sPaymentId )
00143     {
00144         $oConfig = $this->getConfig();
00145         $iLangId = (int) oxLang::getInstance()->getBaseLanguage();
00146         $blTsTestMode = $oConfig->getConfigParam( 'tsTestMode' );
00147         $aTsUser = $oConfig->getConfigParam( 'aTsUser' );
00148         $aTsPassword = $oConfig->getConfigParam( 'aTsPassword' );
00149         $aTrustedShopIds = $oConfig->getConfigParam( 'iShopID_TrustedShops' );
00150         if ( $aTrustedShopIds && $aTrustedShopIds[$iLangId] ) {
00151             try {
00152                 if ( $blTsTestMode ) {
00153                     $sSoapUrl = $oConfig->getConfigParam( 'sTsTestProtectionUrl' );
00154                 } else {
00155                     $sSoapUrl = $oConfig->getConfigParam( 'sTsProtectionUrl' );
00156                 }
00157                 $sFunction = 'requestForProtectionV2';
00158                 $sVersion = $this->getConfig()->getVersion();
00159                 $sEdition = $this->getConfig()->getFullEdition();
00160                 $sTsPaymentId = $this->_getTsPaymentId($sPaymentId);
00161                 $tsProductId = $this->_getTsProductCurrId($aValues['tsProductId'], $aValues['currency']);
00162                 $aValues['tsId']    = $aTrustedShopIds[$iLangId];
00163                 $aValues['paymentType'] = $sTsPaymentId;
00164                 $aValues['shopSystemVersion'] = $sEdition . " " . $sVersion;
00165                 $aValues['wsUser'] = $aTsUser[$iLangId];
00166                 $aValues['wsPassword'] = $aTsPassword[$iLangId];
00167                 $aValues['orderDate'] = str_replace(" ", "T", $aValues['orderDate']);
00168                 $oSoap = new SoapClient($sSoapUrl);
00169                 $aResults = $oSoap->{$sFunction}($aValues['tsId'],$tsProductId,$aValues['amount'],$aValues['currency'],$aValues['paymentType'],
00170                 $aValues['buyerEmail'],$aValues['shopCustomerID'],$aValues['shopOrderID'],$aValues['orderDate'],$aValues['shopSystemVersion'],
00171                 $aValues['wsUser'],$aValues['wsPassword']);
00172 
00173                 if ( isset($aResults) && "" != $aResults ) {
00174                     if ( $aResults == "-10001" ) {
00175                         oxUtils::getInstance()->logger( "NO_VALID_SHOP" );
00176                         return false;
00177                     }
00178                     if ( $aResults == "-11111" ) {
00179                         oxUtils::getInstance()->logger( "SYSTEM_ERROR" );
00180                         return false;
00181                     }
00182                     return $aResults;
00183                 }
00184             } catch( Exception $eException ) {
00185                 oxUtils::getInstance()->logger( "Soap-Error: " . $eException->faultstring );
00186                 return false;
00187             }
00188         }
00189         return null;
00190 
00191     }
00192 
00201     public function checkCertificate( $iTrustedShopId, $blTsTestMode )
00202     {
00203         if ( $iTrustedShopId ) {
00204             try {
00205                 if ( $blTsTestMode ) {
00206                     $sSoapUrl = 'https://qa.trustedshops.de/ts/services/TsProtection?wsdl';
00207                 } else {
00208                     $sSoapUrl = 'https://www.trustedshops.de/ts/services/TsProtection?wsdl';
00209                 }
00210                 $sFunction = 'checkCertificate';
00211                 $aValues['tsId']    = $iTrustedShopId;
00212                 $oSoap = new SoapClient($sSoapUrl);
00213                 $aResults = $oSoap->{$sFunction}($aValues['tsId']);
00214                 if ( isset($aResults) ) {
00215                     return $aResults;
00216                 }
00217             } catch( Exception $eException ) {
00218                 oxUtils::getInstance()->logger( "Soap-Error: " . $eException->faultstring );
00219                 return false;
00220             }
00221         }
00222         return null;
00223 
00224     }
00225 
00233     protected function _getTsPaymentId( $sPaymentId )
00234     {
00235         $aPayment = oxNew("oxpayment");
00236         if ( $aPayment->load($sPaymentId) ) {
00237             $sTsPaymentId = $aPayment->oxpayments__oxtspaymentid->value;
00238         }
00239         return $sTsPaymentId;
00240     }
00241 
00247     protected function _getTsProductIds()
00248     {
00249         if ($this->_aProductIds == null) {
00250             $this->_aProductIds = false;
00251             if ( $aTsProducts = $this->_getTsProducts()) {
00252                 $this->_aProductIds = array_keys($aTsProducts);
00253             }
00254         }
00255         return $this->_aProductIds;
00256     }
00257 
00263     protected function _getProductNettPrices()
00264     {
00265         if ($this->_aProductNettPrices == null) {
00266             $this->_aProductNettPrices = false;
00267             if ( $aTsProducts = $this->_getTsProducts()) {
00268                 $this->_aProductNettPrices = array();
00269                 foreach ( $aTsProducts as $aTsProduct ) {
00270                     $this->_aProductNettPrices[] = $aTsProduct['netto'];
00271                 }
00272             }
00273         }
00274         return $this->_aProductNettPrices;
00275     }
00276 
00282     protected function _getProductAmounts()
00283     {
00284         if ($this->_aProductAmounts == null) {
00285             $this->_aProductAmounts = false;
00286             if ( $aTsProducts = $this->_getTsProducts()) {
00287                 $this->_aProductAmounts = array();
00288                 foreach ( $aTsProducts as $aTsProduct ) {
00289                     $this->_aProductAmounts[] = $aTsProduct['amount'];
00290                 }
00291             }
00292         }
00293         return $this->_aProductAmounts;
00294     }
00295 
00301     protected function _getTsProducts()
00302     {
00303         if ($this->_aProducts == null) {
00304             $this->_aProducts = false;
00305             if ( $aTsProducts = $this->_sTsProtectProducts) {
00306                 $this->_aProducts = $aTsProducts;
00307             }
00308         }
00309         return $this->_aProducts;
00310     }
00311 
00320     protected function _getTsProductCurrId( $sTsId, $sCurr )
00321     {
00322         $sTsCurrId = $sTsId;
00323         if ($sCurr != 'EUR') {
00324             $aTsCurrId = $this->_sTsCurrencyProducts[$sTsId];
00325             $sTsCurrId = $aTsCurrId[$sCurr];
00326         }
00327         return $sTsCurrId;
00328     }
00329 
00330 }