oxtsprotection.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxTsProtection extends oxSuperCfg
00008 {
00009 
00015     protected $_aAllProducts = null;
00016 
00017 
00023     protected $_dVat = null;
00024 
00030     protected $_sTsCurrencyProducts = array(
00031         "TS080501_500_30_EUR"   => array("GBP" => "TS100629_500_30_GBP", "CHF" => "TS100629_500_30_CHF", "USD" => "TS080501_500_30_USD"),
00032         "TS080501_1500_30_EUR"  => array("GBP" => "TS100629_1500_30_GBP", "CHF" => "TS100629_1500_30_CHF", "USD" => "TS100629_1500_30_USD"),
00033         "TS080501_2500_30_EUR"  => array("GBP" => "TS100629_2500_30_GBP", "CHF" => "TS100629_2500_30_CHF", "USD" => "TS100629_2500_30_USD"),
00034         "TS080501_5000_30_EUR"  => array("GBP" => "TS100629_5000_30_GBP", "CHF" => "TS100629_5000_30_CHF", "USD" => "TS100629_5000_30_USD"),
00035         "TS080501_10000_30_EUR" => array("GBP" => "TS100629_1000_30_GBP", "CHF" => "TS100629_10000_30_CHF", "USD" => "TS100629_10000_30_USD"),
00036         "TS080501_20000_30_EUR" => array("GBP" => "TS100629_2000_30_GBP", "CHF" => "TS100629_20000_30_CHF", "USD" => "TS100629_20000_30_USD")
00037     );
00038 
00044     public function getVat()
00045     {
00046         return $this->_dVat;
00047     }
00048 
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 
00078         return $aProducts;
00079     }
00080 
00088     public function getTsProduct($sTsId)
00089     {
00090         $oProduct = oxNew("oxTsProduct");
00091         $oProduct->setTsId($sTsId);
00092 
00093         return $oProduct;
00094     }
00095 
00104     public function requestForTsProtection($aValues, $sPaymentId)
00105     {
00106         $oConfig = $this->getConfig();
00107         $iLangId = (int) oxRegistry::getLang()->getBaseLanguage();
00108         $blTsTestMode = $oConfig->getConfigParam('tsTestMode');
00109         $aTsUser = $oConfig->getConfigParam('aTsUser');
00110         $aTsPassword = $oConfig->getConfigParam('aTsPassword');
00111         $aTrustedShopIds = $oConfig->getConfigParam('iShopID_TrustedShops');
00112         if ($aTrustedShopIds && $aTrustedShopIds[$iLangId]) {
00113             try {
00114                 if ($blTsTestMode) {
00115                     $sSoapUrl = $oConfig->getConfigParam('sTsTestProtectionUrl');
00116                 } else {
00117                     $sSoapUrl = $oConfig->getConfigParam('sTsProtectionUrl');
00118                 }
00119                 $sFunction = 'requestForProtectionV2';
00120                 $sVersion = $this->getConfig()->getVersion();
00121                 $sEdition = $this->getConfig()->getFullEdition();
00122                 $sTsPaymentId = $this->_getTsPaymentId($sPaymentId);
00123                 $tsProductId = $this->_getTsProductCurrId($aValues['tsProductId'], $aValues['currency']);
00124                 $aValues['tsId'] = $aTrustedShopIds[$iLangId];
00125                 $aValues['paymentType'] = $sTsPaymentId;
00126                 $aValues['shopSystemVersion'] = $sEdition . " " . $sVersion;
00127                 $aValues['wsUser'] = $aTsUser[$iLangId];
00128                 $aValues['wsPassword'] = $aTsPassword[$iLangId];
00129                 $aValues['orderDate'] = str_replace(" ", "T", $aValues['orderDate']);
00130                 $oSoap = new SoapClient($sSoapUrl);
00131                 $aResults = $oSoap->{$sFunction}(
00132                     $aValues['tsId'], $tsProductId, $aValues['amount'], $aValues['currency'], $aValues['paymentType'],
00133                     $aValues['buyerEmail'], $aValues['shopCustomerID'], $aValues['shopOrderID'], $aValues['orderDate'], $aValues['shopSystemVersion'],
00134                     $aValues['wsUser'], $aValues['wsPassword']
00135                 );
00136 
00137                 if (isset($aResults) && "" != $aResults) {
00138                     if ($aResults == "-10001") {
00139                         oxRegistry::getUtils()->logger("NO_VALID_SHOP");
00140 
00141                         return false;
00142                     }
00143                     if ($aResults == "-11111") {
00144                         oxRegistry::getUtils()->logger("SYSTEM_ERROR");
00145 
00146                         return false;
00147                     }
00148 
00149                     return $aResults;
00150                 }
00151             } catch (Exception $eException) {
00152                 oxRegistry::getUtils()->logger("Soap-Error: " . $eException->faultstring);
00153 
00154                 return false;
00155             }
00156         }
00157 
00158         return null;
00159 
00160     }
00161 
00170     public function checkCertificate($iTrustedShopId, $blTsTestMode)
00171     {
00172         if ($iTrustedShopId) {
00173             if ($blTsTestMode == "true") {
00174                 $sSoapUrl = 'https://qa.trustedshops.de/ts/services/TsProtection?wsdl';
00175             } else {
00176                 $sSoapUrl = 'https://www.trustedshops.de/ts/services/TsProtection?wsdl';
00177             }
00178             $sFunction = 'checkCertificate';
00179             $aValues['tsId'] = $iTrustedShopId;
00180             $aResults = $this->executeSoap($sSoapUrl, $sFunction, $aValues['tsId']);
00181 
00182             return $aResults;
00183         }
00184 
00185         return null;
00186 
00187     }
00188 
00198     public function executeSoap($sSoapUrl, $sFunction, $sValues)
00199     {
00200         try {
00201             $oSoap = new SoapClient($sSoapUrl);
00202             $aResults = $oSoap->{$sFunction}($sValues);
00203             if (isset($aResults)) {
00204                 return $aResults;
00205             }
00206         } catch (Exception $eException) {
00207             oxRegistry::getUtils()->logger("Soap-Error: " . $eException->faultstring);
00208 
00209             return false;
00210         }
00211 
00212         return null;
00213 
00214     }
00215 
00223     protected function _getTsPaymentId($sPaymentId)
00224     {
00225         $sTsPaymentId = '';
00226 
00227         $aPayment = oxNew("oxPayment");
00228         if ($aPayment->load($sPaymentId)) {
00229             $sTsPaymentId = $aPayment->oxpayments__oxtspaymentid->value;
00230         }
00231 
00232         return $sTsPaymentId;
00233     }
00234 
00240     protected function _getTsAllProducts()
00241     {
00242         if ($this->_aAllProducts == null) {
00243             $this->_aAllProducts = false;
00244             $oTsProduct = oxNew("oxTsProduct");
00245             if ($aTsProducts = $oTsProduct->getAllTsProducts()) {
00246                 foreach ($aTsProducts as $sId => $aTsProduct) {
00247                     $oProduct = oxNew("oxTsProduct");
00248                     $oProduct->setTsId($sId);
00249                     $oProduct->setVat($this->getVat());
00250                     $this->_aAllProducts[] = $oProduct;
00251                 }
00252             }
00253         }
00254 
00255         return $this->_aAllProducts;
00256     }
00257 
00266     protected function _getTsProductCurrId($sTsId, $sCurr)
00267     {
00268         $sTsCurrId = $sTsId;
00269         if ($sCurr != 'EUR') {
00270             $aTsCurrId = $this->_sTsCurrencyProducts[$sTsId];
00271             $sTsCurrId = $aTsCurrId[$sCurr];
00272         }
00273 
00274         return $sTsCurrId;
00275     }
00276 }