OXID eShop CE  4.10.5
 All Classes Namespaces Files Functions Variables Pages
oxtsprotection.php
Go to the documentation of this file.
1 <?php
2 
9 {
11  private $blTsTestMode = false;
12 
18  protected $_aAllProducts = null;
19 
20 
26  protected $_dVat = null;
27 
33  protected $_sTsCurrencyProducts = array(
34  "TS080501_500_30_EUR" => array("GBP" => "TS100629_500_30_GBP", "CHF" => "TS100629_500_30_CHF", "USD" => "TS080501_500_30_USD"),
35  "TS080501_1500_30_EUR" => array("GBP" => "TS100629_1500_30_GBP", "CHF" => "TS100629_1500_30_CHF", "USD" => "TS100629_1500_30_USD"),
36  "TS080501_2500_30_EUR" => array("GBP" => "TS100629_2500_30_GBP", "CHF" => "TS100629_2500_30_CHF", "USD" => "TS100629_2500_30_USD"),
37  "TS080501_5000_30_EUR" => array("GBP" => "TS100629_5000_30_GBP", "CHF" => "TS100629_5000_30_CHF", "USD" => "TS100629_5000_30_USD"),
38  "TS080501_10000_30_EUR" => array("GBP" => "TS100629_1000_30_GBP", "CHF" => "TS100629_10000_30_CHF", "USD" => "TS100629_10000_30_USD"),
39  "TS080501_20000_30_EUR" => array("GBP" => "TS100629_2000_30_GBP", "CHF" => "TS100629_20000_30_CHF", "USD" => "TS100629_20000_30_USD")
40  );
41 
47  public function getVat()
48  {
49  return $this->_dVat;
50  }
51 
57  public function setVat($dVat)
58  {
59  $this->_dVat = $dVat;
60  }
61 
69  public function getTsProducts($dPrice)
70  {
71  $aProducts = array();
72  if ($aTsProducts = $this->_getTsAllProducts()) {
73  foreach ($aTsProducts as $oProduct) {
74  $aProducts[] = $oProduct;
75  if ($oProduct->getAmount() > $dPrice) {
76  break;
77  }
78  }
79  }
80 
81  return $aProducts;
82  }
83 
91  public function getTsProduct($sTsId)
92  {
93  $oProduct = oxNew("oxTsProduct");
94  $oProduct->setTsId($sTsId);
95 
96  return $oProduct;
97  }
98 
107  public function requestForTsProtection($aValues, $sPaymentId)
108  {
109  $oConfig = $this->getConfig();
110  $iLangId = (int) oxRegistry::getLang()->getBaseLanguage();
111  $blTsTestMode = $oConfig->getConfigParam('tsTestMode');
112  $aTsUser = $oConfig->getConfigParam('aTsUser');
113  $aTsPassword = $oConfig->getConfigParam('aTsPassword');
114  $aTrustedShopIds = $oConfig->getConfigParam('iShopID_TrustedShops');
115  if ($aTrustedShopIds && $aTrustedShopIds[$iLangId]) {
116  try {
117  if ($blTsTestMode) {
118  $sSoapUrl = $oConfig->getConfigParam('sTsTestProtectionUrl');
119  } else {
120  $sSoapUrl = $oConfig->getConfigParam('sTsProtectionUrl');
121  }
122  $sFunction = 'requestForProtectionV2';
123  $sVersion = $this->getConfig()->getVersion();
124  $sEdition = $this->getConfig()->getFullEdition();
125  $sTsPaymentId = $this->_getTsPaymentId($sPaymentId);
126  $tsProductId = $this->_getTsProductCurrId($aValues['tsProductId'], $aValues['currency']);
127  $aValues['tsId'] = $aTrustedShopIds[$iLangId];
128  $aValues['paymentType'] = $sTsPaymentId;
129  $aValues['shopSystemVersion'] = $sEdition . " " . $sVersion;
130  $aValues['wsUser'] = $aTsUser[$iLangId];
131  $aValues['wsPassword'] = $aTsPassword[$iLangId];
132  $aValues['orderDate'] = str_replace(" ", "T", $aValues['orderDate']);
133  $oSoap = new SoapClient($sSoapUrl);
134  $aResults = $oSoap->{$sFunction}(
135  $aValues['tsId'], $tsProductId, $aValues['amount'], $aValues['currency'], $aValues['paymentType'],
136  $aValues['buyerEmail'], $aValues['shopCustomerID'], $aValues['shopOrderID'], $aValues['orderDate'], $aValues['shopSystemVersion'],
137  $aValues['wsUser'], $aValues['wsPassword']
138  );
139 
140  if (isset($aResults) && "" != $aResults) {
141  if ($aResults == "-10001") {
142  oxRegistry::getUtils()->logger("NO_VALID_SHOP");
143 
144  return false;
145  }
146  if ($aResults == "-11111") {
147  oxRegistry::getUtils()->logger("SYSTEM_ERROR");
148 
149  return false;
150  }
151 
152  return $aResults;
153  }
154  } catch (Exception $eException) {
155  oxRegistry::getUtils()->logger("Soap-Error: " . $eException->faultstring);
156 
157  return false;
158  }
159  }
160 
161  return null;
162  }
163 
172  public function checkCertificate($iTrustedShopId, $blTsTestMode)
173  {
174  if ($iTrustedShopId) {
175  if ($blTsTestMode == "true") {
176  $this->blTsTestMode = $blTsTestMode;
177 
178  $sSoapUrl = 'https://qa.trustedshops.de/ts/services/TsProtection?wsdl';
179  } else {
180  $sSoapUrl = 'https://www.trustedshops.de/ts/services/TsProtection?wsdl';
181  }
182  $sFunction = 'checkCertificate';
183  $aValues['tsId'] = $iTrustedShopId;
184  $aResults = $this->executeSoap($sSoapUrl, $sFunction, $aValues['tsId']);
185 
186  return $aResults;
187  }
188 
189  return null;
190  }
191 
201  public function executeSoap($sSoapUrl, $sFunction, $sValues)
202  {
203  $soapParameters = null;
204  if ($this->blTsTestMode) {
205  $soapParameters = $this->setNotCheckSSL();
206  }
207 
208  try {
209  $oSoap = new SoapClient($sSoapUrl, $soapParameters);
210  $aResults = $oSoap->{$sFunction}($sValues);
211  if (isset($aResults)) {
212  return $aResults;
213  }
214  } catch (Exception $eException) {
215  oxRegistry::getUtils()->logger("Soap-Error: " . $eException->faultstring);
216 
217  return false;
218  }
219 
220  return null;
221 
222  }
223 
231  protected function _getTsPaymentId($sPaymentId)
232  {
233  $sTsPaymentId = '';
234 
235  $aPayment = oxNew("oxPayment");
236  if ($aPayment->load($sPaymentId)) {
237  $sTsPaymentId = $aPayment->oxpayments__oxtspaymentid->value;
238  }
239 
240  return $sTsPaymentId;
241  }
242 
248  protected function _getTsAllProducts()
249  {
250  if ($this->_aAllProducts == null) {
251  $this->_aAllProducts = false;
252  $oTsProduct = oxNew("oxTsProduct");
253  if ($aTsProducts = $oTsProduct->getAllTsProducts()) {
254  foreach ($aTsProducts as $sId => $aTsProduct) {
255  $oProduct = oxNew("oxTsProduct");
256  $oProduct->setTsId($sId);
257  $oProduct->setVat($this->getVat());
258  $this->_aAllProducts[] = $oProduct;
259  }
260  }
261  }
262 
263  return $this->_aAllProducts;
264  }
265 
274  protected function _getTsProductCurrId($sTsId, $sCurr)
275  {
276  $sTsCurrId = $sTsId;
277  if ($sCurr != 'EUR') {
278  $aTsCurrId = $this->_sTsCurrencyProducts[$sTsId];
279  $sTsCurrId = $aTsCurrId[$sCurr];
280  }
281 
282  return $sTsCurrId;
283  }
284 
291  private function setNotCheckSSL()
292  {
293  $context = stream_context_create(
294  array(
295  'ssl' => array(
296  // set some SSL/TLS specific options
297  'verify_peer' => false,
298  'verify_peer_name' => false,
299  'allow_self_signed' => true
300  )
301  )
302  );
303 
304  return array('stream_context' => $context);
305  }
306 }