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