Ltc_Komfortkasse - Version 1.6.0

Version Notes

improvements for multi shop environments

Download this release

Release Info

Developer Komfortkasse
Extension Ltc_Komfortkasse
Version 1.6.0
Comparing to
See all releases


Code changes from version 1.4.4.17 to 1.6.0

app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse.php CHANGED
@@ -8,7 +8,7 @@ require_once 'Komfortkasse_Order.php';
8
  */
9
  class Komfortkasse
10
  {
11
- const PLUGIN_VER = '1.4.4.17';
12
  const MAXLEN_SSL = 117;
13
  const LEN_MCRYPT = 16;
14
 
@@ -50,6 +50,7 @@ class Komfortkasse
50
  */
51
  public static function read($refunds)
52
  {
 
53
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export)) {
54
  return;
55
  }
@@ -68,6 +69,7 @@ class Komfortkasse
68
  $ids = Komfortkasse_Order::getRefundIDs();
69
  } else {
70
  $ids = Komfortkasse_Order::getOpenIDs();
 
71
  }
72
 
73
  foreach ($ids as $id) {
@@ -168,6 +170,7 @@ class Komfortkasse
168
  Komfortkasse::output('encryption:');
169
  $encryptionstring = null;
170
  // Look for openssl encryption.
 
171
  if (extension_loaded('openssl') === true) {
172
 
173
  // Look for public&privatekey encryption.
@@ -293,8 +296,10 @@ class Komfortkasse
293
 
294
  $o = '';
295
  $lines = explode("\n", $param);
 
296
  foreach ($lines as $line) {
297
  $col = explode(';', $line);
 
298
  $count = Komfortkasse::mycount($col);
299
  $id = trim($col [0]);
300
  if ($count > 1) {
@@ -316,6 +321,7 @@ class Komfortkasse
316
  if ($refunds === true) {
317
  Komfortkasse_Order::updateRefund($id, $status, $callbackid);
318
  } else {
 
319
  $order = Komfortkasse_Order::getOrder($id);
320
  if ($id != $order ['number']) {
321
  continue;
@@ -371,7 +377,7 @@ class Komfortkasse
371
  return false;
372
  }
373
 
374
- return in_array($order['status'], explode(',', $status));
375
  }
376
 
377
  /**
@@ -390,6 +396,9 @@ class Komfortkasse
390
  $order = Komfortkasse_Order::getOrder($id);
391
  $order['type'] = self::getOrderType($order);
392
 
 
 
 
393
  // See if order is relevant.
394
  if (!self::isOpen($order)) {
395
  return;
@@ -399,7 +408,7 @@ class Komfortkasse
399
 
400
  $queryEnc = Komfortkasse::kkencrypt($queryRaw);
401
 
402
- $query = http_build_query(array ('q' => $queryEnc,'hash' => Komfortkasse_Config::getConfig(Komfortkasse_Config::accesscode),'key' => Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey)
403
  ));
404
 
405
  $contextData = array ('method' => 'POST','timeout' => 2,'header' => "Connection: close\r\n" . 'Content-Length: ' . strlen($query) . "\r\n",'content' => $query
@@ -454,6 +463,7 @@ class Komfortkasse
454
  */
455
  protected static function getNewStatus($status, $order)
456
  {
 
457
  $orderType = self::getOrderType($order);
458
 
459
  switch ($orderType) {
@@ -829,14 +839,13 @@ class Komfortkasse
829
 
830
  public static function getOrderType($order) {
831
  $payment_method = $order['payment_method'];
832
-
833
- $paycodes = preg_split('/,/', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $order));
834
  if (in_array($payment_method, $paycodes))
835
  return 'PREPAYMENT';
836
- $paycodes = preg_split('/,/', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_invoice, $order));
837
  if (in_array($payment_method, $paycodes))
838
  return 'INVOICE';
839
- $paycodes = preg_split('/,/', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_cod, $order));
840
  if (in_array($payment_method, $paycodes))
841
  return 'COD';
842
  return '';
8
  */
9
  class Komfortkasse
10
  {
11
+ const PLUGIN_VER = '1.6.0';
12
  const MAXLEN_SSL = 117;
13
  const LEN_MCRYPT = 16;
14
 
50
  */
51
  public static function read($refunds)
52
  {
53
+
54
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export)) {
55
  return;
56
  }
69
  $ids = Komfortkasse_Order::getRefundIDs();
70
  } else {
71
  $ids = Komfortkasse_Order::getOpenIDs();
72
+
73
  }
74
 
75
  foreach ($ids as $id) {
170
  Komfortkasse::output('encryption:');
171
  $encryptionstring = null;
172
  // Look for openssl encryption.
173
+
174
  if (extension_loaded('openssl') === true) {
175
 
176
  // Look for public&privatekey encryption.
296
 
297
  $o = '';
298
  $lines = explode("\n", $param);
299
+
300
  foreach ($lines as $line) {
301
  $col = explode(';', $line);
302
+
303
  $count = Komfortkasse::mycount($col);
304
  $id = trim($col [0]);
305
  if ($count > 1) {
321
  if ($refunds === true) {
322
  Komfortkasse_Order::updateRefund($id, $status, $callbackid);
323
  } else {
324
+
325
  $order = Komfortkasse_Order::getOrder($id);
326
  if ($id != $order ['number']) {
327
  continue;
377
  return false;
378
  }
379
 
380
+ return in_array($order['status'], explode(',', trim(str_replace('"', '', $status))));
381
  }
382
 
383
  /**
396
  $order = Komfortkasse_Order::getOrder($id);
397
  $order['type'] = self::getOrderType($order);
398
 
399
+ if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export, $order)) {
400
+ return;
401
+ }
402
  // See if order is relevant.
403
  if (!self::isOpen($order)) {
404
  return;
408
 
409
  $queryEnc = Komfortkasse::kkencrypt($queryRaw);
410
 
411
+ $query = http_build_query(array ('q' => $queryEnc,'hash' => Komfortkasse_Config::getConfig(Komfortkasse_Config::accesscode, $order),'key' => Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey, $order)
412
  ));
413
 
414
  $contextData = array ('method' => 'POST','timeout' => 2,'header' => "Connection: close\r\n" . 'Content-Length: ' . strlen($query) . "\r\n",'content' => $query
463
  */
464
  protected static function getNewStatus($status, $order)
465
  {
466
+
467
  $orderType = self::getOrderType($order);
468
 
469
  switch ($orderType) {
839
 
840
  public static function getOrderType($order) {
841
  $payment_method = $order['payment_method'];
842
+ $paycodes = preg_split('/,/', trim(str_replace('"','',Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $order))));
 
843
  if (in_array($payment_method, $paycodes))
844
  return 'PREPAYMENT';
845
+ $paycodes = preg_split('/,/', trim(str_replace('"','',Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_invoice, $order))));
846
  if (in_array($payment_method, $paycodes))
847
  return 'INVOICE';
848
+ $paycodes = preg_split('/,/', trim(str_replace('"','',Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_cod, $order))));
849
  if (in_array($payment_method, $paycodes))
850
  return 'COD';
851
  return '';
app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse.php.bak ADDED
@@ -0,0 +1,864 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Komfortkasse_Config.php';
3
+ require_once 'Komfortkasse_Order.php';
4
+
5
+ /**
6
+ * Komfortkasse
7
+ * Main Class, multi-shop
8
+ */
9
+ class Komfortkasse
10
+ {
11
+ const PLUGIN_VER = '1.4.5';
12
+ const MAXLEN_SSL = 117;
13
+ const LEN_MCRYPT = 16;
14
+
15
+
16
+ /**
17
+ * Read orders.
18
+ *
19
+ * @return void
20
+ */
21
+ public static function readorders()
22
+ {
23
+ Komfortkasse::read(false);
24
+
25
+ }
26
+
27
+ // end readorders()
28
+
29
+
30
+ /**
31
+ * Read refunds.
32
+ *
33
+ * @return void
34
+ */
35
+ public static function readrefunds()
36
+ {
37
+ Komfortkasse::read(true);
38
+
39
+ }
40
+
41
+ // end readrefunds()
42
+
43
+
44
+ /**
45
+ * Read orders/refunds.
46
+ *
47
+ * @param bool $refunds if refunds should be read.
48
+ *
49
+ * @return void
50
+ */
51
+ public static function read($refunds)
52
+ {
53
+ if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export)) {
54
+ return;
55
+ }
56
+
57
+ if (Komfortkasse::check() === false) {
58
+ return;
59
+ }
60
+
61
+ // Schritt 1: alle IDs ausgeben.
62
+ $param = Komfortkasse_Config::getRequestParameter('o');
63
+ $param = Komfortkasse::kkdecrypt($param);
64
+
65
+ if ($param === 'all') {
66
+ $o = '';
67
+ if ($refunds === true) {
68
+ $ids = Komfortkasse_Order::getRefundIDs();
69
+ } else {
70
+ $ids = Komfortkasse_Order::getOpenIDs();
71
+ }
72
+
73
+ foreach ($ids as $id) {
74
+ $o = $o . Komfortkasse::kk_csv($id);
75
+ }
76
+
77
+ Komfortkasse::output(Komfortkasse::kkencrypt($o));
78
+ } else {
79
+ $o = '';
80
+ $ex = explode(';', $param);
81
+ foreach ($ex as $id) {
82
+ $id = trim($id);
83
+ // Schritt 2: details pro auftrag ausgeben.
84
+ if ($refunds === true) {
85
+ $order = Komfortkasse_Order::getRefund($id);
86
+ } else {
87
+ $order = Komfortkasse_Order::getOrder($id);
88
+ if ($order['payment_method'])
89
+ $order['type'] = self::getOrderType($order);
90
+ }
91
+
92
+ if (!$order) {
93
+ continue;
94
+ }
95
+
96
+ $o = $o . http_build_query($order);
97
+ $o = $o . "\n";
98
+ }
99
+
100
+ $cry = Komfortkasse::kkencrypt($o);
101
+ if ($cry === false) {
102
+ Komfortkasse::output(Komfortkasse::kkcrypterror());
103
+ } else {
104
+ Komfortkasse::output($cry);
105
+ }
106
+ }
107
+ // end if
108
+ }
109
+
110
+ // end read()
111
+
112
+
113
+ /**
114
+ * Test.
115
+ *
116
+ * @return void
117
+ */
118
+ public static function test()
119
+ {
120
+ $dec = Komfortkasse::kkdecrypt(Komfortkasse_Config::getRequestParameter('test'));
121
+
122
+ $enc = Komfortkasse::kkencrypt($dec);
123
+
124
+ Komfortkasse::output($enc);
125
+
126
+ }
127
+
128
+ // end test()
129
+
130
+
131
+ /**
132
+ * Init.
133
+ *
134
+ * @return void
135
+ */
136
+ public static function init()
137
+ {
138
+ Komfortkasse::output('connection:connectionsuccess|');
139
+
140
+ Komfortkasse::output('accesskey:');
141
+ // Set access code.
142
+ $hashed = md5(Komfortkasse_Config::getRequestParameter('accesscode'));
143
+ $current = Komfortkasse_Config::getConfig(Komfortkasse_Config::accesscode);
144
+ if ($current != '' && $current !== 'undefined' && $current != $hashed) {
145
+ Komfortkasse::output('Access Code already set! Shop ' . $current . ', given (hash) ' . $hashed);
146
+ return;
147
+ }
148
+
149
+ if ($hashed != Komfortkasse_Config::getRequestParameter('accesscode_hash')) {
150
+ Komfortkasse::output('MD5 Hashes do not match! Shop ' . $hashed . ' given ' . Komfortkasse_Config::getRequestParameter('accesscode_hash'));
151
+ return;
152
+ }
153
+
154
+ Komfortkasse_Config::setConfig(Komfortkasse_Config::accesscode, $hashed);
155
+ Komfortkasse::output('accesskeysuccess|');
156
+
157
+ Komfortkasse::output('apikey:');
158
+ // Set API key.
159
+ $apikey = Komfortkasse_Config::getRequestParameter('apikey');
160
+ if (Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) != '' && Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) !== 'undefined' && Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) !== $apikey) {
161
+ Komfortkasse::output('API Key already set! Shop ' . Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) . ', given ' . $apikey);
162
+ return;
163
+ }
164
+
165
+ Komfortkasse_Config::setConfig(Komfortkasse_Config::apikey, $apikey);
166
+ Komfortkasse::output('apikeysuccess|');
167
+
168
+ Komfortkasse::output('encryption:');
169
+ $encryptionstring = null;
170
+ // Look for openssl encryption.
171
+ if (extension_loaded('openssl') === true) {
172
+
173
+ // Look for public&privatekey encryption.
174
+ $kpriv = Komfortkasse_Config::getRequestParameter('privateKey');
175
+ $kpub = Komfortkasse_Config::getRequestParameter('publicKey');
176
+ Komfortkasse_Config::setConfig(Komfortkasse_Config::privatekey, $kpriv);
177
+ Komfortkasse_Config::setConfig(Komfortkasse_Config::publickey, $kpub);
178
+
179
+ // Try with rsa.
180
+ $crypttest = Komfortkasse_Config::getRequestParameter('testSSLEnc');
181
+ $decrypt = Komfortkasse::kkdecrypt($crypttest, 'openssl');
182
+ if ($decrypt === 'Can you hear me?') {
183
+ $encryptionstring = 'openssl#' . OPENSSL_VERSION_TEXT . '#' . OPENSSL_VERSION_NUMBER . '|';
184
+ Komfortkasse_Config::setConfig(Komfortkasse_Config::encryption, 'openssl');
185
+ }
186
+ }
187
+
188
+ if (!$encryptionstring && extension_loaded('mcrypt') === true) {
189
+ // Look for mcrypt encryption.
190
+ $sec = Komfortkasse_Config::getRequestParameter('mCryptSecretKey');
191
+ $iv = Komfortkasse_Config::getRequestParameter('mCryptIV');
192
+ Komfortkasse_Config::setConfig(Komfortkasse_Config::privatekey, $sec);
193
+ Komfortkasse_Config::setConfig(Komfortkasse_Config::publickey, $iv);
194
+
195
+ // Try with mcrypt.
196
+ $crypttest = Komfortkasse_Config::getRequestParameter('testMCryptEnc');
197
+ $decrypt = Komfortkasse::kkdecrypt($crypttest, 'mcrypt');
198
+ if ($decrypt === 'Can you hear me?') {
199
+ $encryptionstring = 'mcrypt|';
200
+ Komfortkasse_Config::setConfig(Komfortkasse_Config::encryption, 'mcrypt');
201
+ }
202
+ }
203
+
204
+ // Fallback: base64.
205
+ if (!$encryptionstring) {
206
+ // Try with base64 encoding.
207
+ $crypttest = Komfortkasse_Config::getRequestParameter('testBase64Enc');
208
+ $decrypt = Komfortkasse::kkdecrypt($crypttest, 'base64');
209
+ if ($decrypt === 'Can you hear me?') {
210
+ $encryptionstring = 'base64|';
211
+ Komfortkasse_Config::setConfig(Komfortkasse_Config::encryption, 'base64');
212
+ }
213
+ }
214
+
215
+ if (!$encryptionstring) {
216
+ $encryptionstring = 'ERROR:no encryption possible|';
217
+ }
218
+
219
+ Komfortkasse::output($encryptionstring);
220
+
221
+ Komfortkasse::output('decryptiontest:');
222
+ $decrypt = Komfortkasse::kkdecrypt($crypttest, Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption));
223
+ if ($decrypt === 'Can you hear me?') {
224
+ Komfortkasse::output('ok');
225
+ } else {
226
+ Komfortkasse::output(Komfortkasse::kkcrypterror());
227
+ }
228
+
229
+ Komfortkasse::output('|encryptiontest:');
230
+ $encrypt = Komfortkasse::kkencrypt('Yes, I see you!', Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption));
231
+ if ($encrypt !== false) {
232
+ Komfortkasse::output($encrypt);
233
+ } else {
234
+ Komfortkasse::output(Komfortkasse::kkcrypterror());
235
+ }
236
+
237
+ }
238
+
239
+ // end init()
240
+
241
+
242
+ /**
243
+ * Update orders.
244
+ *
245
+ * @return void
246
+ */
247
+ public static function updateorders()
248
+ {
249
+ Komfortkasse::update(false);
250
+
251
+ }
252
+
253
+ // end updateorders()
254
+
255
+
256
+ /**
257
+ * Update refunds.
258
+ *
259
+ * @return void
260
+ */
261
+ public static function updaterefunds()
262
+ {
263
+ Komfortkasse::update(true);
264
+
265
+ }
266
+
267
+ // end updaterefunds()
268
+
269
+
270
+ /**
271
+ * Update refunds or order.
272
+ *
273
+ * @param bool $refunds if refunds should be updated.
274
+ *
275
+ * @return void
276
+ */
277
+ public static function update($refunds)
278
+ {
279
+ if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_update)) {
280
+ return;
281
+ }
282
+
283
+ if (Komfortkasse::check() === false) {
284
+ return;
285
+ }
286
+
287
+ $param = Komfortkasse_Config::getRequestParameter('o');
288
+ $param = Komfortkasse::kkdecrypt($param);
289
+
290
+ if ($refunds === false) {
291
+ $openids = Komfortkasse_Order::getOpenIDs();
292
+ }
293
+
294
+ $o = '';
295
+ $lines = explode("\n", $param);
296
+ foreach ($lines as $line) {
297
+ $col = explode(';', $line);
298
+ $count = Komfortkasse::mycount($col);
299
+ $id = trim($col [0]);
300
+ if ($count > 1) {
301
+ $status = trim($col [1]);
302
+ } else {
303
+ $status = null;
304
+ }
305
+
306
+ if ($count > 2) {
307
+ $callbackid = trim($col [2]);
308
+ } else {
309
+ $callbackid = null;
310
+ }
311
+
312
+ if (empty($id) === true || empty($status) === true) {
313
+ continue;
314
+ }
315
+
316
+ if ($refunds === true) {
317
+ Komfortkasse_Order::updateRefund($id, $status, $callbackid);
318
+ } else {
319
+ $order = Komfortkasse_Order::getOrder($id);
320
+ if ($id != $order ['number']) {
321
+ continue;
322
+ }
323
+
324
+ $newstatus = Komfortkasse::getNewStatus($status, $order);
325
+ if (empty($newstatus) === true) {
326
+ continue;
327
+ }
328
+
329
+ // only update if order status update is necessary (dont update if order has been updated manually)
330
+ if ($order['status'] == $newstatus) {
331
+ $o = $o . Komfortkasse::kk_csv($id);
332
+ continue;
333
+ }
334
+
335
+ // dont update if order is no longer relevant (will be marked as DISAPPEARED later on)
336
+ if (in_array($order ['number'], $openids) === false) {
337
+ continue;
338
+ }
339
+
340
+ Komfortkasse_Order::updateOrder($order, $newstatus, $callbackid);
341
+ }
342
+
343
+ $o = $o . Komfortkasse::kk_csv($id);
344
+ } // end foreach
345
+
346
+ $cry = Komfortkasse::kkencrypt($o);
347
+ if ($cry === false) {
348
+ Komfortkasse::output(Komfortkasse::kkcrypterror());
349
+ } else {
350
+ Komfortkasse::output($cry);
351
+ }
352
+
353
+ }
354
+
355
+ // end update()
356
+
357
+ private static function isOpen($order)
358
+ {
359
+ $status = '';
360
+ switch ($order ['type']) {
361
+ case 'PREPAYMENT' :
362
+ $status = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open, $order);
363
+ break;
364
+ case 'INVOICE' :
365
+ $status = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open_invoice, $order);
366
+ break;
367
+ case 'COD' :
368
+ $status = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open_cod, $order);
369
+ break;
370
+ default:
371
+ return false;
372
+ }
373
+
374
+ return in_array($order['status'], explode(',', $status));
375
+ }
376
+
377
+ /**
378
+ * Notify order.
379
+ *
380
+ * @param unknown $id Order ID
381
+ *
382
+ * @return void
383
+ */
384
+ public static function notifyorder($id)
385
+ {
386
+ if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export)) {
387
+ return;
388
+ }
389
+
390
+ $order = Komfortkasse_Order::getOrder($id);
391
+ $order['type'] = self::getOrderType($order);
392
+
393
+ // See if order is relevant.
394
+ if (!self::isOpen($order)) {
395
+ return;
396
+ }
397
+
398
+ $queryRaw = http_build_query($order);
399
+
400
+ $queryEnc = Komfortkasse::kkencrypt($queryRaw);
401
+
402
+ $query = http_build_query(array ('q' => $queryEnc,'hash' => Komfortkasse_Config::getConfig(Komfortkasse_Config::accesscode, $order),'key' => Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey)
403
+ ));
404
+
405
+ $contextData = array ('method' => 'POST','timeout' => 2,'header' => "Connection: close\r\n" . 'Content-Length: ' . strlen($query) . "\r\n",'content' => $query
406
+ );
407
+
408
+ $context = stream_context_create(array ('http' => $contextData
409
+ ));
410
+
411
+ // Development: http://localhost:8080/kkos01/api...
412
+ $result = @file_get_contents('http://api.komfortkasse.eu/api/shop/neworder.jsf', false, $context);
413
+
414
+ }
415
+
416
+ // end notifyorder()
417
+
418
+
419
+ /**
420
+ * Info.
421
+ *
422
+ * @return void
423
+ */
424
+ public static function info()
425
+ {
426
+ if (Komfortkasse::check() === false) {
427
+ return;
428
+ }
429
+
430
+ $version = Komfortkasse_Config::getVersion();
431
+
432
+ $o = '';
433
+ $o = $o . Komfortkasse::kk_csv($version);
434
+ $o = $o . Komfortkasse::kk_csv(Komfortkasse::PLUGIN_VER);
435
+
436
+ $cry = Komfortkasse::kkencrypt($o);
437
+ if ($cry === false) {
438
+ Komfortkasse::output(Komfortkasse::kkcrypterror());
439
+ } else {
440
+ Komfortkasse::output($cry);
441
+ }
442
+
443
+ }
444
+
445
+ // end info()
446
+
447
+
448
+ /**
449
+ * Retrieve new status.
450
+ *
451
+ * @param unknown $status Status
452
+ *
453
+ * @return mixed
454
+ */
455
+ protected static function getNewStatus($status, $order)
456
+ {
457
+ $orderType = self::getOrderType($order);
458
+
459
+ switch ($orderType) {
460
+ case 'PREPAYMENT' :
461
+ switch ($status) {
462
+ case 'PAID' :
463
+ return Komfortkasse_Config::getConfig(Komfortkasse_Config::status_paid, $order);
464
+ case 'CANCELLED' :
465
+ return Komfortkasse_Config::getConfig(Komfortkasse_Config::status_cancelled, $order);
466
+ }
467
+ return null;
468
+ case 'INVOICE' :
469
+ switch ($status) {
470
+ case 'PAID' :
471
+ return Komfortkasse_Config::getConfig(Komfortkasse_Config::status_paid_invoice, $order);
472
+ case 'CANCELLED' :
473
+ return Komfortkasse_Config::getConfig(Komfortkasse_Config::status_cancelled_invoice, $order);
474
+ }
475
+ return null;
476
+ case 'COD' :
477
+ switch ($status) {
478
+ case 'PAID' :
479
+ return Komfortkasse_Config::getConfig(Komfortkasse_Config::status_paid_cod, $order);
480
+ case 'CANCELLED' :
481
+ return Komfortkasse_Config::getConfig(Komfortkasse_Config::status_cancelled_cod, $order);
482
+ }
483
+ return null;
484
+ }
485
+
486
+ }
487
+
488
+ // end getNewStatus()
489
+
490
+
491
+ /**
492
+ * Check.
493
+ *
494
+ * @return boolean
495
+ */
496
+ public static function check()
497
+ {
498
+ $ac = Komfortkasse_Config::getRequestParameter('accesscode');
499
+
500
+ if (!$ac || md5($ac) !== Komfortkasse_Config::getConfig(Komfortkasse_Config::accesscode)) {
501
+ return false;
502
+ } else {
503
+ return true;
504
+ }
505
+
506
+ }
507
+
508
+ // end check()
509
+
510
+
511
+ /**
512
+ * Encrypt.
513
+ *
514
+ * @param string $s String to encrypt
515
+ * @param string $encryption encryption method
516
+ * @param string $keystring key string
517
+ *
518
+ * @return mixed
519
+ *
520
+ */
521
+ protected static function kkencrypt($s, $encryption = null, $keystring = null)
522
+ {
523
+ if (!$encryption) {
524
+ $encryption = Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption);
525
+ }
526
+ if (!$keystring) {
527
+ $keystring = Komfortkasse_Config::getConfig(Komfortkasse_Config::publickey);
528
+ }
529
+ if ($s === '') {
530
+ return '';
531
+ }
532
+
533
+ switch ($encryption) {
534
+ case 'openssl' :
535
+ return Komfortkasse::kkencrypt_openssl($s, $keystring);
536
+ case 'mcrypt' :
537
+ return Komfortkasse::kkencrypt_mcrypt($s);
538
+ case 'base64' :
539
+ return Komfortkasse::kkencrypt_base64($s);
540
+ }
541
+
542
+ }
543
+
544
+ // end kkencrypt()
545
+
546
+
547
+ /**
548
+ * Decrypt.
549
+ *
550
+ *
551
+ * @param string $s String to decrypt
552
+ * @param string $encryption encryption method
553
+ * @param string $keystring key string
554
+ *
555
+ * @return Ambigous <boolean, string>|string
556
+ */
557
+ protected static function kkdecrypt($s, $encryption = null, $keystring = null)
558
+ {
559
+ if (!$encryption) {
560
+ $encryption = Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption);
561
+ }
562
+ if (!$keystring) {
563
+ $keystring = Komfortkasse_Config::getConfig(Komfortkasse_Config::privatekey);
564
+ }
565
+ if ($s === '') {
566
+ return '';
567
+ }
568
+
569
+ switch ($encryption) {
570
+ case 'openssl' :
571
+ return Komfortkasse::kkdecrypt_openssl($s, $keystring);
572
+ case 'mcrypt' :
573
+ return Komfortkasse::kkdecrypt_mcrypt($s);
574
+ case 'base64' :
575
+ return Komfortkasse::kkdecrypt_base64($s);
576
+ }
577
+
578
+ }
579
+
580
+ // end kkdecrypt()
581
+
582
+
583
+ /**
584
+ * Show encryption/decryption error.
585
+ *
586
+ * @param string $encryption encryption method
587
+ *
588
+ * @return mixed
589
+ */
590
+ protected static function kkcrypterror($encryption)
591
+ {
592
+ if (!$encryption) {
593
+ $encryption = Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption);
594
+ }
595
+
596
+ switch ($encryption) {
597
+ case 'openssl' :
598
+ return str_replace(':', ';', openssl_error_string());
599
+ }
600
+
601
+ }
602
+
603
+ // end kkcrypterror()
604
+
605
+
606
+ /**
607
+ * Encrypt with base 64.
608
+ *
609
+ * @param string $s String to encrypt
610
+ *
611
+ * @return string decrypted string
612
+ */
613
+ protected static function kkencrypt_base64($s)
614
+ {
615
+ return Komfortkasse::mybase64_encode($s);
616
+
617
+ }
618
+
619
+ // end kkencrypt_base64()
620
+
621
+
622
+ /**
623
+ * Decrypt with base 64.
624
+ *
625
+ * @param string $s String to decrypt
626
+ *
627
+ * @return string decrypted string
628
+ */
629
+ protected static function kkdecrypt_base64($s)
630
+ {
631
+ return Komfortkasse::mybase64_decode($s);
632
+
633
+ }
634
+
635
+ // end kkdecrypt_base64()
636
+
637
+
638
+ /**
639
+ * Encrypt with mcrypt.
640
+ *
641
+ * @param string $s String to encrypt
642
+ *
643
+ * @return string decrypted string
644
+ */
645
+ protected static function kkencrypt_mcrypt($s)
646
+ {
647
+ $key = Komfortkasse_Config::getConfig(Komfortkasse_Config::privatekey);
648
+ $iv = Komfortkasse_Config::getConfig(Komfortkasse_Config::publickey);
649
+ $td = mcrypt_module_open('rijndael-128', ' ', 'cbc', $iv);
650
+ $init = mcrypt_generic_init($td, $key, $iv);
651
+
652
+ $padlen = ((strlen($s) + Komfortkasse::LEN_MCRYPT) % Komfortkasse::LEN_MCRYPT);
653
+ $s = str_pad($s, (strlen($s) + $padlen), ' ');
654
+ $encrypted = mcrypt_generic($td, $s);
655
+
656
+ mcrypt_generic_deinit($td);
657
+ mcrypt_module_close($td);
658
+
659
+ return Komfortkasse::mybase64_encode($encrypted);
660
+
661
+ }
662
+
663
+ // end kkencrypt_mcrypt()
664
+
665
+
666
+ /**
667
+ * Encrypt with open ssl.
668
+ *
669
+ * @param string $s String to encrypt
670
+ * @param string $keystring Key string
671
+ *
672
+ * @return string decrypted string
673
+ */
674
+ protected static function kkencrypt_openssl($s, $keystring)
675
+ {
676
+ $ret = '';
677
+
678
+ $pubkey = "-----BEGIN PUBLIC KEY-----\n" . chunk_split($keystring, 64, "\n") . "-----END PUBLIC KEY-----\n";
679
+ $key = openssl_get_publickey($pubkey);
680
+ if ($key === false) {
681
+ return false;
682
+ }
683
+
684
+ do {
685
+ $current = substr($s, 0, Komfortkasse::MAXLEN_SSL);
686
+ $s = substr($s, Komfortkasse::MAXLEN_SSL);
687
+ if (openssl_public_encrypt($current, $encrypted, $key) === false) {
688
+ return false;
689
+ }
690
+
691
+ $ret = $ret . "\n" . Komfortkasse::mybase64_encode($encrypted);
692
+ } while ( $s );
693
+
694
+ openssl_free_key($key);
695
+ return $ret;
696
+
697
+ }
698
+
699
+ // end kkencrypt_openssl()
700
+
701
+
702
+ /**
703
+ * Decrypt with open ssl.
704
+ *
705
+ * @param string $s String to decrypt
706
+ * @param string $keystring Key string
707
+ *
708
+ * @return string decrypted string
709
+ */
710
+ protected static function kkdecrypt_openssl($s, $keystring)
711
+ {
712
+ $ret = '';
713
+
714
+ $privkey = "-----BEGIN RSA PRIVATE KEY-----\n" . chunk_split($keystring, 64, "\n") . "-----END RSA PRIVATE KEY-----\n";
715
+ $key = openssl_get_privatekey($privkey);
716
+ if ($key === false) {
717
+ return false;
718
+ }
719
+
720
+ $parts = explode("\n", $s);
721
+ foreach ($parts as $part) {
722
+ if ($part) {
723
+ if (openssl_private_decrypt(Komfortkasse::mybase64_decode($part), $decrypted, $key) === false) {
724
+ return false;
725
+ }
726
+ $ret = $ret . $decrypted;
727
+ }
728
+ }
729
+
730
+ openssl_free_key($key);
731
+ return $ret;
732
+
733
+ }
734
+
735
+ // end kkdecrypt_openssl()
736
+
737
+
738
+ /**
739
+ * Decrypt with mcrypt.
740
+ *
741
+ * @param string $s String to decrypt
742
+ *
743
+ * @return string decrypted string
744
+ */
745
+ protected static function kkdecrypt_mcrypt($s)
746
+ {
747
+ $key = Komfortkasse_Config::getConfig(Komfortkasse_Config::privatekey);
748
+ $iv = Komfortkasse_Config::getConfig(Komfortkasse_Config::publickey);
749
+ $td = mcrypt_module_open('rijndael-128', ' ', 'cbc', $iv);
750
+ $init = mcrypt_generic_init($td, $key, $iv);
751
+
752
+ $ret = '';
753
+
754
+ $parts = explode("\n", $s);
755
+ foreach ($parts as $part) {
756
+ if ($part) {
757
+ $decrypted = mdecrypt_generic($td, Komfortkasse::mybase64_decode($part));
758
+ $ret = $ret . trim($decrypted);
759
+ }
760
+ }
761
+
762
+ mcrypt_generic_deinit($td);
763
+ mcrypt_module_close($td);
764
+ return $ret;
765
+
766
+ }
767
+
768
+ // end kkdecrypt_mcrypt()
769
+
770
+
771
+ /**
772
+ * Output CSV.
773
+ *
774
+ * @param string $s String to output
775
+ *
776
+ * @return string CSV
777
+ */
778
+ protected static function kk_csv($s)
779
+ {
780
+ return '"' . str_replace('"', '', str_replace(';', ',', utf8_encode($s))) . '";';
781
+
782
+ }
783
+
784
+ // end kk_csv()
785
+
786
+
787
+ /**
788
+ * Output
789
+ *
790
+ * @param mixed $s Data to output
791
+ */
792
+ protected static function output($s)
793
+ {
794
+ echo $s;
795
+
796
+ }
797
+
798
+ // end output()
799
+
800
+
801
+ /**
802
+ * Count
803
+ *
804
+ * @param array $array Arrays
805
+ *
806
+ * @return int count
807
+ */
808
+ protected static function mycount($array)
809
+ {
810
+ return count($array);
811
+
812
+ }
813
+
814
+ // end mycount()
815
+ protected static function mybase64_decode($s)
816
+ {
817
+ return base64_decode($s);
818
+
819
+ }
820
+
821
+ // end mybase64_decode()
822
+ protected static function mybase64_encode($s)
823
+ {
824
+ return base64_encode($s);
825
+
826
+ }
827
+
828
+ // end mybase64_encode()
829
+
830
+ public static function getOrderType($order) {
831
+ $payment_method = $order['payment_method'];
832
+
833
+ $paycodes = preg_split('/,/', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $order));
834
+ if (in_array($payment_method, $paycodes))
835
+ return 'PREPAYMENT';
836
+ $paycodes = preg_split('/,/', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_invoice, $order));
837
+ if (in_array($payment_method, $paycodes))
838
+ return 'INVOICE';
839
+ $paycodes = preg_split('/,/', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_cod, $order));
840
+ if (in_array($payment_method, $paycodes))
841
+ return 'COD';
842
+ return '';
843
+ }
844
+
845
+ public static function readinvoicepdf() {
846
+ Komfortkasse_Order::getInvoicePdfPrepare();
847
+
848
+ if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export)) {
849
+ return;
850
+ }
851
+
852
+ if (Komfortkasse::check() === false) {
853
+ return;
854
+ }
855
+
856
+ $invoiceNumber = Komfortkasse_Config::getRequestParameter('o');
857
+ $invoiceNumber = Komfortkasse::kkdecrypt($invoiceNumber);
858
+ $orderNumber = Komfortkasse_Config::getRequestParameter('order_id');
859
+ $orderNumber = Komfortkasse::kkdecrypt($orderNumber);
860
+
861
+ return Komfortkasse_Order::getInvoicePdf($invoiceNumber, $orderNumber);
862
+
863
+ }
864
+ }
app/code/community/Ltc/Komfortkasse/etc/config.xml CHANGED
@@ -3,7 +3,7 @@
3
  <config>
4
  <modules>
5
  <Ltc_Komfortkasse>
6
- <version>1.4.4.17</version>
7
  </Ltc_Komfortkasse>
8
  </modules>
9
  <global>
3
  <config>
4
  <modules>
5
  <Ltc_Komfortkasse>
6
+ <version>1.6.0</version>
7
  </Ltc_Komfortkasse>
8
  </modules>
9
  <global>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Ltc_Komfortkasse</name>
4
- <version>1.4.4.17</version>
5
  <stability>stable</stability>
6
  <license uri="http://creativecommons.org/licenses/by-nd/4.0/">CC BY-ND 4.0</license>
7
  <channel>community</channel>
@@ -13,11 +13,11 @@ Zus&#xE4;tzlich k&#xF6;nnen automatische Zahlungserinnerungen versendet werden u
13
  &#xD;
14
  Es ist eine Anmeldung auf www.komfortkasse.eu erforderlich (kostenloses Paket verf&#xFC;gbar).&#xD;
15
  </description>
16
- <notes>bugfixes and improvements</notes>
17
  <authors><author><name>Komfortkasse</name><user>komfortkasse</user><email>integration@komfortkasse.eu</email></author></authors>
18
- <date>2016-10-12</date>
19
- <time>13:56:07</time>
20
- <contents><target name="magecommunity"><dir name="Ltc"><dir name="Komfortkasse"><dir name="Helper"><file name="Data.php" hash="42f1d168bb70725128e15daf305802ba"/><file name="Komfortkasse.php" hash="39f2b2cbf66a97f205c91cbf5c8313a0"/><file name="Komfortkasse_Config.php" hash="991250ec3cdbc9b7b79ab38888e3a022"/><file name="Komfortkasse_Order.php" hash="0242154acde6609cbd1ff9a8966955c9"/></dir><dir name="Model"><file name="Encryptionoptions.php" hash="1fbe2ffc43cc3c1489688d20f4c8af11"/><file name="Observer.php" hash="5b616b6d3651df44f8297c732dc478bb"/></dir><dir name="controllers"><file name="MainController.php" hash="b983fe60b2bbfa3aa1d57850cc6c045b"/></dir><dir name="etc"><file name="config.xml" hash="5bc85e56b68cf682f6464257badbc554"/><file name="system.xml" hash="4477e69044c79edab2b70691b0236bd8"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ltc_Komfortkasse.xml" hash="433066ef75047d9468dcea87888283d2"/></dir></target></contents>
21
  <compatible/>
22
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
23
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Ltc_Komfortkasse</name>
4
+ <version>1.6.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://creativecommons.org/licenses/by-nd/4.0/">CC BY-ND 4.0</license>
7
  <channel>community</channel>
13
  &#xD;
14
  Es ist eine Anmeldung auf www.komfortkasse.eu erforderlich (kostenloses Paket verf&#xFC;gbar).&#xD;
15
  </description>
16
+ <notes>improvements for multi shop environments</notes>
17
  <authors><author><name>Komfortkasse</name><user>komfortkasse</user><email>integration@komfortkasse.eu</email></author></authors>
18
+ <date>2016-10-14</date>
19
+ <time>12:45:07</time>
20
+ <contents><target name="magecommunity"><dir name="Ltc"><dir name="Komfortkasse"><dir name="Helper"><file name="Data.php" hash="42f1d168bb70725128e15daf305802ba"/><file name="Komfortkasse.php" hash="7544f683fcbb44ca148c0a05603d64ba"/><file name="Komfortkasse.php.bak" hash="2a8cd73b832172bbbed17f2c062f7e4a"/><file name="Komfortkasse_Config.php" hash="991250ec3cdbc9b7b79ab38888e3a022"/><file name="Komfortkasse_Order.php" hash="0242154acde6609cbd1ff9a8966955c9"/></dir><dir name="Model"><file name="Encryptionoptions.php" hash="1fbe2ffc43cc3c1489688d20f4c8af11"/><file name="Observer.php" hash="5b616b6d3651df44f8297c732dc478bb"/></dir><dir name="controllers"><file name="MainController.php" hash="b983fe60b2bbfa3aa1d57850cc6c045b"/></dir><dir name="etc"><file name="config.xml" hash="043f6e954c78677e655fcbc0b43223ce"/><file name="system.xml" hash="4477e69044c79edab2b70691b0236bd8"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ltc_Komfortkasse.xml" hash="433066ef75047d9468dcea87888283d2"/></dir></target></contents>
21
  <compatible/>
22
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
23
  </package>