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