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 if ( $blTsTestMode == "true" ) {
00205 $sSoapUrl = 'https://qa.trustedshops.de/ts/services/TsProtection?wsdl';
00206 } else {
00207 $sSoapUrl = 'https://www.trustedshops.de/ts/services/TsProtection?wsdl';
00208 }
00209 $sFunction = 'checkCertificate';
00210 $aValues['tsId'] = $iTrustedShopId;
00211 $aResults = $this->executeSoap( $sSoapUrl, $sFunction, $aValues['tsId']);
00212 return $aResults;
00213 }
00214 return null;
00215
00216 }
00217
00227 public function executeSoap( $sSoapUrl, $sFunction, $sValues )
00228 {
00229 try {
00230 $oSoap = new SoapClient($sSoapUrl);
00231 $aResults = $oSoap->{$sFunction}($sValues);
00232 if ( isset($aResults) ) {
00233 return $aResults;
00234 }
00235 } catch( Exception $eException ) {
00236 oxUtils::getInstance()->logger( "Soap-Error: " . $eException->faultstring );
00237 return false;
00238 }
00239 return null;
00240
00241 }
00242
00250 protected function _getTsPaymentId( $sPaymentId )
00251 {
00252 $aPayment = oxNew("oxpayment");
00253 if ( $aPayment->load($sPaymentId) ) {
00254 $sTsPaymentId = $aPayment->oxpayments__oxtspaymentid->value;
00255 }
00256 return $sTsPaymentId;
00257 }
00258
00264 protected function _getTsProductIds()
00265 {
00266 if ($this->_aProductIds == null) {
00267 $this->_aProductIds = false;
00268 if ( $aTsProducts = $this->_getTsProducts()) {
00269 $this->_aProductIds = array_keys($aTsProducts);
00270 }
00271 }
00272 return $this->_aProductIds;
00273 }
00274
00280 protected function _getProductNettPrices()
00281 {
00282 if ($this->_aProductNettPrices == null) {
00283 $this->_aProductNettPrices = false;
00284 if ( $aTsProducts = $this->_getTsProducts()) {
00285 $this->_aProductNettPrices = array();
00286 foreach ( $aTsProducts as $aTsProduct ) {
00287 $this->_aProductNettPrices[] = $aTsProduct['netto'];
00288 }
00289 }
00290 }
00291 return $this->_aProductNettPrices;
00292 }
00293
00299 protected function _getProductAmounts()
00300 {
00301 if ($this->_aProductAmounts == null) {
00302 $this->_aProductAmounts = false;
00303 if ( $aTsProducts = $this->_getTsProducts()) {
00304 $this->_aProductAmounts = array();
00305 foreach ( $aTsProducts as $aTsProduct ) {
00306 $this->_aProductAmounts[] = $aTsProduct['amount'];
00307 }
00308 }
00309 }
00310 return $this->_aProductAmounts;
00311 }
00312
00318 protected function _getTsProducts()
00319 {
00320 if ($this->_aProducts == null) {
00321 $this->_aProducts = false;
00322 if ( $aTsProducts = $this->_sTsProtectProducts) {
00323 $this->_aProducts = $aTsProducts;
00324 }
00325 }
00326 return $this->_aProducts;
00327 }
00328
00337 protected function _getTsProductCurrId( $sTsId, $sCurr )
00338 {
00339 $sTsCurrId = $sTsId;
00340 if ($sCurr != 'EUR') {
00341 $aTsCurrId = $this->_sTsCurrencyProducts[$sTsId];
00342 $sTsCurrId = $aTsCurrId[$sCurr];
00343 }
00344 return $sTsCurrId;
00345 }
00346
00347 }