oxtsprotection.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxTsProtection extends oxSuperCfg
00008 {
00014     protected $_aAllProducts = null;
00015 
00016 
00022     protected $_dVat = null;
00023 
00029     protected $_sTsCurrencyProducts = array(
00030                                        "TS080501_500_30_EUR"   => array( "GBP" => "TS100629_500_30_GBP", "CHF" => "TS100629_500_30_CHF", "USD" => "TS080501_500_30_USD" ),
00031                                        "TS080501_1500_30_EUR"  => array( "GBP" => "TS100629_1500_30_GBP", "CHF" => "TS100629_1500_30_CHF", "USD" => "TS100629_1500_30_USD" ),
00032                                        "TS080501_2500_30_EUR"  => array( "GBP" => "TS100629_2500_30_GBP", "CHF" => "TS100629_2500_30_CHF", "USD" => "TS100629_2500_30_USD" ),
00033                                        "TS080501_5000_30_EUR"  => array( "GBP" => "TS100629_5000_30_GBP", "CHF" => "TS100629_5000_30_CHF", "USD" => "TS100629_5000_30_USD" ),
00034                                        "TS080501_10000_30_EUR" => array( "GBP" => "TS100629_1000_30_GBP", "CHF" => "TS100629_10000_30_CHF", "USD" => "TS100629_10000_30_USD" ),
00035                                        "TS080501_20000_30_EUR" => array( "GBP" => "TS100629_2000_30_GBP", "CHF" => "TS100629_20000_30_CHF", "USD" => "TS100629_20000_30_USD" )
00036                                 );
00037 
00043     public function getVat()
00044     {
00045         return $this->_dVat;
00046     }
00047 
00055     public function setVat( $dVat )
00056     {
00057         $this->_dVat = $dVat;
00058     }
00059 
00067     public function getTsProducts( $dPrice )
00068     {
00069         $aProducts = array();
00070         if ( $aTsProducts = $this->_getTsAllProducts()) {
00071             foreach ( $aTsProducts as $oProduct ) {
00072                 $aProducts[] = $oProduct;
00073                 if ( $oProduct->getAmount() > $dPrice ) {
00074                     break;
00075                 }
00076             }
00077         }
00078         return $aProducts;
00079     }
00080 
00088     public function getTsProduct( $sTsId )
00089     {
00090         $oProduct = oxNew("oxTsProduct");
00091         $oProduct->setTsId($sTsId);
00092         return $oProduct;
00093     }
00094 
00103     public function requestForTsProtection( $aValues, $sPaymentId )
00104     {
00105         $oConfig = $this->getConfig();
00106         $iLangId = (int) oxRegistry::getLang()->getBaseLanguage();
00107         $blTsTestMode = $oConfig->getConfigParam( 'tsTestMode' );
00108         $aTsUser = $oConfig->getConfigParam( 'aTsUser' );
00109         $aTsPassword = $oConfig->getConfigParam( 'aTsPassword' );
00110         $aTrustedShopIds = $oConfig->getConfigParam( 'iShopID_TrustedShops' );
00111         if ( $aTrustedShopIds && $aTrustedShopIds[$iLangId] ) {
00112             try {
00113                 if ( $blTsTestMode ) {
00114                     $sSoapUrl = $oConfig->getConfigParam( 'sTsTestProtectionUrl' );
00115                 } else {
00116                     $sSoapUrl = $oConfig->getConfigParam( 'sTsProtectionUrl' );
00117                 }
00118                 $sFunction = 'requestForProtectionV2';
00119                 $sVersion = $this->getConfig()->getVersion();
00120                 $sEdition = $this->getConfig()->getFullEdition();
00121                 $sTsPaymentId = $this->_getTsPaymentId($sPaymentId);
00122                 $tsProductId = $this->_getTsProductCurrId($aValues['tsProductId'], $aValues['currency']);
00123                 $aValues['tsId']    = $aTrustedShopIds[$iLangId];
00124                 $aValues['paymentType'] = $sTsPaymentId;
00125                 $aValues['shopSystemVersion'] = $sEdition . " " . $sVersion;
00126                 $aValues['wsUser'] = $aTsUser[$iLangId];
00127                 $aValues['wsPassword'] = $aTsPassword[$iLangId];
00128                 $aValues['orderDate'] = str_replace(" ", "T", $aValues['orderDate']);
00129                 $oSoap = new SoapClient($sSoapUrl);
00130                 $aResults = $oSoap->{$sFunction}($aValues['tsId'],$tsProductId,$aValues['amount'],$aValues['currency'],$aValues['paymentType'],
00131                 $aValues['buyerEmail'],$aValues['shopCustomerID'],$aValues['shopOrderID'],$aValues['orderDate'],$aValues['shopSystemVersion'],
00132                 $aValues['wsUser'],$aValues['wsPassword']);
00133 
00134                 if ( isset($aResults) && "" != $aResults ) {
00135                     if ( $aResults == "-10001" ) {
00136                         oxRegistry::getUtils()->logger( "NO_VALID_SHOP" );
00137                         return false;
00138                     }
00139                     if ( $aResults == "-11111" ) {
00140                         oxRegistry::getUtils()->logger( "SYSTEM_ERROR" );
00141                         return false;
00142                     }
00143                     return $aResults;
00144                 }
00145             } catch( Exception $eException ) {
00146                 oxRegistry::getUtils()->logger( "Soap-Error: " . $eException->faultstring );
00147                 return false;
00148             }
00149         }
00150         return null;
00151 
00152     }
00153 
00162     public function checkCertificate( $iTrustedShopId, $blTsTestMode )
00163     {
00164         if ( $iTrustedShopId ) {
00165             if ( $blTsTestMode == "true" ) {
00166                 $sSoapUrl = 'https://qa.trustedshops.de/ts/services/TsProtection?wsdl';
00167             } else {
00168                 $sSoapUrl = 'https://www.trustedshops.de/ts/services/TsProtection?wsdl';
00169             }
00170             $sFunction = 'checkCertificate';
00171             $aValues['tsId'] = $iTrustedShopId;
00172             $aResults = $this->executeSoap( $sSoapUrl, $sFunction, $aValues['tsId']);
00173             return $aResults;
00174         }
00175         return null;
00176 
00177     }
00178 
00188     public function executeSoap( $sSoapUrl, $sFunction, $sValues )
00189     {
00190         try {
00191             $oSoap = new SoapClient($sSoapUrl);
00192             $aResults = $oSoap->{$sFunction}($sValues);
00193             if ( isset($aResults) ) {
00194                 return $aResults;
00195             }
00196         } catch( Exception $eException ) {
00197             oxRegistry::getUtils()->logger( "Soap-Error: " . $eException->faultstring );
00198             return false;
00199         }
00200         return null;
00201 
00202     }
00203 
00211     protected function _getTsPaymentId( $sPaymentId )
00212     {
00213         $sTsPaymentId = '';
00214 
00215         $aPayment = oxNew("oxPayment");
00216         if ( $aPayment->load($sPaymentId) ) {
00217             $sTsPaymentId = $aPayment->oxpayments__oxtspaymentid->value;
00218         }
00219         return $sTsPaymentId;
00220     }
00221 
00227     protected function _getTsAllProducts()
00228     {
00229         if ($this->_aAllProducts == null) {
00230             $this->_aAllProducts = false;
00231             $oTsProduct = oxNew("oxTsProduct");
00232             if ( $aTsProducts = $oTsProduct->getAllTsProducts()) {
00233                 foreach ( $aTsProducts as $sId => $aTsProduct ) {
00234                     $oProduct = oxNew("oxTsProduct");
00235                     $oProduct->setTsId($sId);
00236                     $oProduct->setVat( $this->getVat() );
00237                     $this->_aAllProducts[] = $oProduct;
00238                 }
00239             }
00240         }
00241         return $this->_aAllProducts;
00242     }
00243 
00252     protected function _getTsProductCurrId( $sTsId, $sCurr )
00253     {
00254         $sTsCurrId = $sTsId;
00255         if ($sCurr != 'EUR') {
00256             $aTsCurrId = $this->_sTsCurrencyProducts[$sTsId];
00257             $sTsCurrId = $aTsCurrId[$sCurr];
00258         }
00259         return $sTsCurrId;
00260     }
00261 
00262 }