OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
oxtsprotection.php
Go to the documentation of this file.
1 <?php
2 
8 {
14  protected $_aAllProducts = null;
15 
16 
22  protected $_dVat = null;
23 
29  protected $_sTsCurrencyProducts = array(
30  "TS080501_500_30_EUR" => array( "GBP" => "TS100629_500_30_GBP", "CHF" => "TS100629_500_30_CHF", "USD" => "TS080501_500_30_USD" ),
31  "TS080501_1500_30_EUR" => array( "GBP" => "TS100629_1500_30_GBP", "CHF" => "TS100629_1500_30_CHF", "USD" => "TS100629_1500_30_USD" ),
32  "TS080501_2500_30_EUR" => array( "GBP" => "TS100629_2500_30_GBP", "CHF" => "TS100629_2500_30_CHF", "USD" => "TS100629_2500_30_USD" ),
33  "TS080501_5000_30_EUR" => array( "GBP" => "TS100629_5000_30_GBP", "CHF" => "TS100629_5000_30_CHF", "USD" => "TS100629_5000_30_USD" ),
34  "TS080501_10000_30_EUR" => array( "GBP" => "TS100629_1000_30_GBP", "CHF" => "TS100629_10000_30_CHF", "USD" => "TS100629_10000_30_USD" ),
35  "TS080501_20000_30_EUR" => array( "GBP" => "TS100629_2000_30_GBP", "CHF" => "TS100629_20000_30_CHF", "USD" => "TS100629_20000_30_USD" )
36  );
37 
43  public function getVat()
44  {
45  return $this->_dVat;
46  }
47 
55  public function setVat( $dVat )
56  {
57  $this->_dVat = $dVat;
58  }
59 
67  public function getTsProducts( $dPrice )
68  {
69  $aProducts = array();
70  if ( $aTsProducts = $this->_getTsAllProducts()) {
71  foreach ( $aTsProducts as $oProduct ) {
72  $aProducts[] = $oProduct;
73  if ( $oProduct->getAmount() > $dPrice ) {
74  break;
75  }
76  }
77  }
78  return $aProducts;
79  }
80 
88  public function getTsProduct( $sTsId )
89  {
90  $oProduct = oxNew("oxTsProduct");
91  $oProduct->setTsId($sTsId);
92  return $oProduct;
93  }
94 
103  public function requestForTsProtection( $aValues, $sPaymentId )
104  {
105  $oConfig = $this->getConfig();
106  $iLangId = (int) oxRegistry::getLang()->getBaseLanguage();
107  $blTsTestMode = $oConfig->getConfigParam( 'tsTestMode' );
108  $aTsUser = $oConfig->getConfigParam( 'aTsUser' );
109  $aTsPassword = $oConfig->getConfigParam( 'aTsPassword' );
110  $aTrustedShopIds = $oConfig->getConfigParam( 'iShopID_TrustedShops' );
111  if ( $aTrustedShopIds && $aTrustedShopIds[$iLangId] ) {
112  try {
113  if ( $blTsTestMode ) {
114  $sSoapUrl = $oConfig->getConfigParam( 'sTsTestProtectionUrl' );
115  } else {
116  $sSoapUrl = $oConfig->getConfigParam( 'sTsProtectionUrl' );
117  }
118  $sFunction = 'requestForProtectionV2';
119  $sVersion = $this->getConfig()->getVersion();
120  $sEdition = $this->getConfig()->getFullEdition();
121  $sTsPaymentId = $this->_getTsPaymentId($sPaymentId);
122  $tsProductId = $this->_getTsProductCurrId($aValues['tsProductId'], $aValues['currency']);
123  $aValues['tsId'] = $aTrustedShopIds[$iLangId];
124  $aValues['paymentType'] = $sTsPaymentId;
125  $aValues['shopSystemVersion'] = $sEdition . " " . $sVersion;
126  $aValues['wsUser'] = $aTsUser[$iLangId];
127  $aValues['wsPassword'] = $aTsPassword[$iLangId];
128  $aValues['orderDate'] = str_replace(" ", "T", $aValues['orderDate']);
129  $oSoap = new SoapClient($sSoapUrl);
130  $aResults = $oSoap->{$sFunction}($aValues['tsId'],$tsProductId,$aValues['amount'],$aValues['currency'],$aValues['paymentType'],
131  $aValues['buyerEmail'],$aValues['shopCustomerID'],$aValues['shopOrderID'],$aValues['orderDate'],$aValues['shopSystemVersion'],
132  $aValues['wsUser'],$aValues['wsPassword']);
133 
134  if ( isset($aResults) && "" != $aResults ) {
135  if ( $aResults == "-10001" ) {
136  oxRegistry::getUtils()->logger( "NO_VALID_SHOP" );
137  return false;
138  }
139  if ( $aResults == "-11111" ) {
140  oxRegistry::getUtils()->logger( "SYSTEM_ERROR" );
141  return false;
142  }
143  return $aResults;
144  }
145  } catch( Exception $eException ) {
146  oxRegistry::getUtils()->logger( "Soap-Error: " . $eException->faultstring );
147  return false;
148  }
149  }
150  return null;
151 
152  }
153 
162  public function checkCertificate( $iTrustedShopId, $blTsTestMode )
163  {
164  if ( $iTrustedShopId ) {
165  if ( $blTsTestMode == "true" ) {
166  $sSoapUrl = 'https://qa.trustedshops.de/ts/services/TsProtection?wsdl';
167  } else {
168  $sSoapUrl = 'https://www.trustedshops.de/ts/services/TsProtection?wsdl';
169  }
170  $sFunction = 'checkCertificate';
171  $aValues['tsId'] = $iTrustedShopId;
172  $aResults = $this->executeSoap( $sSoapUrl, $sFunction, $aValues['tsId']);
173  return $aResults;
174  }
175  return null;
176 
177  }
178 
188  public function executeSoap( $sSoapUrl, $sFunction, $sValues )
189  {
190  try {
191  $oSoap = new SoapClient($sSoapUrl);
192  $aResults = $oSoap->{$sFunction}($sValues);
193  if ( isset($aResults) ) {
194  return $aResults;
195  }
196  } catch( Exception $eException ) {
197  oxRegistry::getUtils()->logger( "Soap-Error: " . $eException->faultstring );
198  return false;
199  }
200  return null;
201 
202  }
203 
211  protected function _getTsPaymentId( $sPaymentId )
212  {
213  $sTsPaymentId = '';
214 
215  $aPayment = oxNew("oxPayment");
216  if ( $aPayment->load($sPaymentId) ) {
217  $sTsPaymentId = $aPayment->oxpayments__oxtspaymentid->value;
218  }
219  return $sTsPaymentId;
220  }
221 
227  protected function _getTsAllProducts()
228  {
229  if ($this->_aAllProducts == null) {
230  $this->_aAllProducts = false;
231  $oTsProduct = oxNew("oxTsProduct");
232  if ( $aTsProducts = $oTsProduct->getAllTsProducts()) {
233  foreach ( $aTsProducts as $sId => $aTsProduct ) {
234  $oProduct = oxNew("oxTsProduct");
235  $oProduct->setTsId($sId);
236  $oProduct->setVat( $this->getVat() );
237  $this->_aAllProducts[] = $oProduct;
238  }
239  }
240  }
241  return $this->_aAllProducts;
242  }
243 
252  protected function _getTsProductCurrId( $sTsId, $sCurr )
253  {
254  $sTsCurrId = $sTsId;
255  if ($sCurr != 'EUR') {
256  $aTsCurrId = $this->_sTsCurrencyProducts[$sTsId];
257  $sTsCurrId = $aTsCurrId[$sCurr];
258  }
259  return $sTsCurrId;
260  }
261 
262 }