OXID eShop CE  4.9.5
 All Classes Files Functions Variables Pages
oxtsprotection.php
Go to the documentation of this file.
1 <?php
2 
8 {
9 
15  protected $_aAllProducts = null;
16 
17 
23  protected $_dVat = null;
24 
30  protected $_sTsCurrencyProducts = array(
31  "TS080501_500_30_EUR" => array("GBP" => "TS100629_500_30_GBP", "CHF" => "TS100629_500_30_CHF", "USD" => "TS080501_500_30_USD"),
32  "TS080501_1500_30_EUR" => array("GBP" => "TS100629_1500_30_GBP", "CHF" => "TS100629_1500_30_CHF", "USD" => "TS100629_1500_30_USD"),
33  "TS080501_2500_30_EUR" => array("GBP" => "TS100629_2500_30_GBP", "CHF" => "TS100629_2500_30_CHF", "USD" => "TS100629_2500_30_USD"),
34  "TS080501_5000_30_EUR" => array("GBP" => "TS100629_5000_30_GBP", "CHF" => "TS100629_5000_30_CHF", "USD" => "TS100629_5000_30_USD"),
35  "TS080501_10000_30_EUR" => array("GBP" => "TS100629_1000_30_GBP", "CHF" => "TS100629_10000_30_CHF", "USD" => "TS100629_10000_30_USD"),
36  "TS080501_20000_30_EUR" => array("GBP" => "TS100629_2000_30_GBP", "CHF" => "TS100629_20000_30_CHF", "USD" => "TS100629_20000_30_USD")
37  );
38 
44  public function getVat()
45  {
46  return $this->_dVat;
47  }
48 
54  public function setVat($dVat)
55  {
56  $this->_dVat = $dVat;
57  }
58 
66  public function getTsProducts($dPrice)
67  {
68  $aProducts = array();
69  if ($aTsProducts = $this->_getTsAllProducts()) {
70  foreach ($aTsProducts as $oProduct) {
71  $aProducts[] = $oProduct;
72  if ($oProduct->getAmount() > $dPrice) {
73  break;
74  }
75  }
76  }
77 
78  return $aProducts;
79  }
80 
88  public function getTsProduct($sTsId)
89  {
90  $oProduct = oxNew("oxTsProduct");
91  $oProduct->setTsId($sTsId);
92 
93  return $oProduct;
94  }
95 
104  public function requestForTsProtection($aValues, $sPaymentId)
105  {
106  $oConfig = $this->getConfig();
107  $iLangId = (int) oxRegistry::getLang()->getBaseLanguage();
108  $blTsTestMode = $oConfig->getConfigParam('tsTestMode');
109  $aTsUser = $oConfig->getConfigParam('aTsUser');
110  $aTsPassword = $oConfig->getConfigParam('aTsPassword');
111  $aTrustedShopIds = $oConfig->getConfigParam('iShopID_TrustedShops');
112  if ($aTrustedShopIds && $aTrustedShopIds[$iLangId]) {
113  try {
114  if ($blTsTestMode) {
115  $sSoapUrl = $oConfig->getConfigParam('sTsTestProtectionUrl');
116  } else {
117  $sSoapUrl = $oConfig->getConfigParam('sTsProtectionUrl');
118  }
119  $sFunction = 'requestForProtectionV2';
120  $sVersion = $this->getConfig()->getVersion();
121  $sEdition = $this->getConfig()->getFullEdition();
122  $sTsPaymentId = $this->_getTsPaymentId($sPaymentId);
123  $tsProductId = $this->_getTsProductCurrId($aValues['tsProductId'], $aValues['currency']);
124  $aValues['tsId'] = $aTrustedShopIds[$iLangId];
125  $aValues['paymentType'] = $sTsPaymentId;
126  $aValues['shopSystemVersion'] = $sEdition . " " . $sVersion;
127  $aValues['wsUser'] = $aTsUser[$iLangId];
128  $aValues['wsPassword'] = $aTsPassword[$iLangId];
129  $aValues['orderDate'] = str_replace(" ", "T", $aValues['orderDate']);
130  $oSoap = new SoapClient($sSoapUrl);
131  $aResults = $oSoap->{$sFunction}(
132  $aValues['tsId'], $tsProductId, $aValues['amount'], $aValues['currency'], $aValues['paymentType'],
133  $aValues['buyerEmail'], $aValues['shopCustomerID'], $aValues['shopOrderID'], $aValues['orderDate'], $aValues['shopSystemVersion'],
134  $aValues['wsUser'], $aValues['wsPassword']
135  );
136 
137  if (isset($aResults) && "" != $aResults) {
138  if ($aResults == "-10001") {
139  oxRegistry::getUtils()->logger("NO_VALID_SHOP");
140 
141  return false;
142  }
143  if ($aResults == "-11111") {
144  oxRegistry::getUtils()->logger("SYSTEM_ERROR");
145 
146  return false;
147  }
148 
149  return $aResults;
150  }
151  } catch (Exception $eException) {
152  oxRegistry::getUtils()->logger("Soap-Error: " . $eException->faultstring);
153 
154  return false;
155  }
156  }
157 
158  return null;
159 
160  }
161 
170  public function checkCertificate($iTrustedShopId, $blTsTestMode)
171  {
172  if ($iTrustedShopId) {
173  if ($blTsTestMode == "true") {
174  $sSoapUrl = 'https://qa.trustedshops.de/ts/services/TsProtection?wsdl';
175  } else {
176  $sSoapUrl = 'https://www.trustedshops.de/ts/services/TsProtection?wsdl';
177  }
178  $sFunction = 'checkCertificate';
179  $aValues['tsId'] = $iTrustedShopId;
180  $aResults = $this->executeSoap($sSoapUrl, $sFunction, $aValues['tsId']);
181 
182  return $aResults;
183  }
184 
185  return null;
186 
187  }
188 
198  public function executeSoap($sSoapUrl, $sFunction, $sValues)
199  {
200  try {
201  $oSoap = new SoapClient($sSoapUrl);
202  $aResults = $oSoap->{$sFunction}($sValues);
203  if (isset($aResults)) {
204  return $aResults;
205  }
206  } catch (Exception $eException) {
207  oxRegistry::getUtils()->logger("Soap-Error: " . $eException->faultstring);
208 
209  return false;
210  }
211 
212  return null;
213 
214  }
215 
223  protected function _getTsPaymentId($sPaymentId)
224  {
225  $sTsPaymentId = '';
226 
227  $aPayment = oxNew("oxPayment");
228  if ($aPayment->load($sPaymentId)) {
229  $sTsPaymentId = $aPayment->oxpayments__oxtspaymentid->value;
230  }
231 
232  return $sTsPaymentId;
233  }
234 
240  protected function _getTsAllProducts()
241  {
242  if ($this->_aAllProducts == null) {
243  $this->_aAllProducts = false;
244  $oTsProduct = oxNew("oxTsProduct");
245  if ($aTsProducts = $oTsProduct->getAllTsProducts()) {
246  foreach ($aTsProducts as $sId => $aTsProduct) {
247  $oProduct = oxNew("oxTsProduct");
248  $oProduct->setTsId($sId);
249  $oProduct->setVat($this->getVat());
250  $this->_aAllProducts[] = $oProduct;
251  }
252  }
253  }
254 
255  return $this->_aAllProducts;
256  }
257 
266  protected function _getTsProductCurrId($sTsId, $sCurr)
267  {
268  $sTsCurrId = $sTsId;
269  if ($sCurr != 'EUR') {
270  $aTsCurrId = $this->_sTsCurrencyProducts[$sTsId];
271  $sTsCurrId = $aTsCurrId[$sCurr];
272  }
273 
274  return $sTsCurrId;
275  }
276 }