Go to the documentation of this file.00001 <?php
00002
00006 class oxtsprotection extends oxSuperCfg
00007 {
00013 protected $_aAllProducts = null;
00014
00020 protected $_sTsCurrencyProducts = array( "TS080501_500_30_EUR" => array( "GBP" => "TS100629_500_30_GBP", "CHF" => "TS100629_1500_30_GBP", "USD" => "TS080501_500_30_USD" ),
00021 "TS080501_1500_30_EUR" => array( "GBP" => "TS100629_1500_30_GBP", "CHF" => "TS100629_1500_30_CHF", "USD" => "TS100629_1500_30_USD" ),
00022 "TS080501_2500_30_EUR" => array( "GBP" => "TS100629_2500_30_GBP", "CHF" => "TS100629_2500_30_CHF", "USD" => "TS100629_2500_30_USD" ),
00023 "TS080501_5000_30_EUR" => array( "GBP" => "TS100629_5000_30_GBP", "CHF" => "TS100629_5000_30_CHF", "USD" => "TS100629_5000_30_USD" ),
00024 "TS080501_10000_30_EUR" => array( "GBP" => "TS100629_1000_30_GBP", "CHF" => "TS100629_10000_30_CHF", "USD" => "TS100629_10000_30_USD" ),
00025 "TS080501_20000_30_EUR" => array( "GBP" => "TS100629_2000_30_GBP", "CHF" => "TS100629_20000_30_CHF", "USD" => "TS100629_20000_30_USD" )
00026 );
00027
00035 public function getTsProducts( $dPrice )
00036 {
00037 $aProducts = array();
00038 if ( $aTsProducts = $this->_getTsAllProducts()) {
00039 foreach ( $aTsProducts as $oProduct ) {
00040 $aProducts[] = $oProduct;
00041 if ( $oProduct->getAmount() > $dPrice ) {
00042 break;
00043 }
00044 }
00045 }
00046 return $aProducts;
00047 }
00048
00056 public function getTsProduct( $sTsId )
00057 {
00058 $oProduct = oxNew("oxtsproduct");
00059 $oProduct->setTsId($sTsId);
00060 return $oProduct;
00061 }
00062
00071 public function requestForTsProtection( $aValues, $sPaymentId )
00072 {
00073 $oConfig = $this->getConfig();
00074 $iLangId = (int) oxLang::getInstance()->getBaseLanguage();
00075 $blTsTestMode = $oConfig->getConfigParam( 'tsTestMode' );
00076 $aTsUser = $oConfig->getConfigParam( 'aTsUser' );
00077 $aTsPassword = $oConfig->getConfigParam( 'aTsPassword' );
00078 $aTrustedShopIds = $oConfig->getConfigParam( 'iShopID_TrustedShops' );
00079 if ( $aTrustedShopIds && $aTrustedShopIds[$iLangId] ) {
00080 try {
00081 if ( $blTsTestMode ) {
00082 $sSoapUrl = $oConfig->getConfigParam( 'sTsTestProtectionUrl' );
00083 } else {
00084 $sSoapUrl = $oConfig->getConfigParam( 'sTsProtectionUrl' );
00085 }
00086 $sFunction = 'requestForProtectionV2';
00087 $sVersion = $this->getConfig()->getVersion();
00088 $sEdition = $this->getConfig()->getFullEdition();
00089 $sTsPaymentId = $this->_getTsPaymentId($sPaymentId);
00090 $tsProductId = $this->_getTsProductCurrId($aValues['tsProductId'], $aValues['currency']);
00091 $aValues['tsId'] = $aTrustedShopIds[$iLangId];
00092 $aValues['paymentType'] = $sTsPaymentId;
00093 $aValues['shopSystemVersion'] = $sEdition . " " . $sVersion;
00094 $aValues['wsUser'] = $aTsUser[$iLangId];
00095 $aValues['wsPassword'] = $aTsPassword[$iLangId];
00096 $aValues['orderDate'] = str_replace(" ", "T", $aValues['orderDate']);
00097 $oSoap = new SoapClient($sSoapUrl);
00098 $aResults = $oSoap->{$sFunction}($aValues['tsId'],$tsProductId,$aValues['amount'],$aValues['currency'],$aValues['paymentType'],
00099 $aValues['buyerEmail'],$aValues['shopCustomerID'],$aValues['shopOrderID'],$aValues['orderDate'],$aValues['shopSystemVersion'],
00100 $aValues['wsUser'],$aValues['wsPassword']);
00101
00102 if ( isset($aResults) && "" != $aResults ) {
00103 if ( $aResults == "-10001" ) {
00104 oxUtils::getInstance()->logger( "NO_VALID_SHOP" );
00105 return false;
00106 }
00107 if ( $aResults == "-11111" ) {
00108 oxUtils::getInstance()->logger( "SYSTEM_ERROR" );
00109 return false;
00110 }
00111 return $aResults;
00112 }
00113 } catch( Exception $eException ) {
00114 oxUtils::getInstance()->logger( "Soap-Error: " . $eException->faultstring );
00115 return false;
00116 }
00117 }
00118 return null;
00119
00120 }
00121
00130 public function checkCertificate( $iTrustedShopId, $blTsTestMode )
00131 {
00132 if ( $iTrustedShopId ) {
00133 if ( $blTsTestMode == "true" ) {
00134 $sSoapUrl = 'https://qa.trustedshops.de/ts/services/TsProtection?wsdl';
00135 } else {
00136 $sSoapUrl = 'https://www.trustedshops.de/ts/services/TsProtection?wsdl';
00137 }
00138 $sFunction = 'checkCertificate';
00139 $aValues['tsId'] = $iTrustedShopId;
00140 $aResults = $this->executeSoap( $sSoapUrl, $sFunction, $aValues['tsId']);
00141 return $aResults;
00142 }
00143 return null;
00144
00145 }
00146
00156 public function executeSoap( $sSoapUrl, $sFunction, $sValues )
00157 {
00158 try {
00159 $oSoap = new SoapClient($sSoapUrl);
00160 $aResults = $oSoap->{$sFunction}($sValues);
00161 if ( isset($aResults) ) {
00162 return $aResults;
00163 }
00164 } catch( Exception $eException ) {
00165 oxUtils::getInstance()->logger( "Soap-Error: " . $eException->faultstring );
00166 return false;
00167 }
00168 return null;
00169
00170 }
00171
00179 protected function _getTsPaymentId( $sPaymentId )
00180 {
00181 $aPayment = oxNew("oxpayment");
00182 if ( $aPayment->load($sPaymentId) ) {
00183 $sTsPaymentId = $aPayment->oxpayments__oxtspaymentid->value;
00184 }
00185 return $sTsPaymentId;
00186 }
00187
00193 protected function _getTsAllProducts()
00194 {
00195 if ($this->_aAllProducts == null) {
00196 $this->_aAllProducts = false;
00197 $oTsProduct = oxNew("oxtsproduct");
00198 if ( $aTsProducts = $oTsProduct->getAllTsProducts()) {
00199 foreach ( $aTsProducts as $sId => $aTsProduct ) {
00200 $oProduct = oxNew("oxtsproduct");
00201 $oProduct->setTsId($sId);
00202 $this->_aAllProducts[] = $oProduct;
00203 }
00204 }
00205 }
00206 return $this->_aAllProducts;
00207 }
00208
00217 protected function _getTsProductCurrId( $sTsId, $sCurr )
00218 {
00219 $sTsCurrId = $sTsId;
00220 if ($sCurr != 'EUR') {
00221 $aTsCurrId = $this->_sTsCurrencyProducts[$sTsId];
00222 $sTsCurrId = $aTsCurrId[$sCurr];
00223 }
00224 return $sTsCurrId;
00225 }
00226
00227 }