Ltc_Komfortkasse - Version 1.4.3.1

Version Notes

Bugfix for reading orders/refunds with payment methods that have been deleted

Download this release

Release Info

Developer Komfortkasse
Extension Ltc_Komfortkasse
Version 1.4.3.1
Comparing to
See all releases


Code changes from version 1.4.3 to 1.4.3.1

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.3';
12
  const MAXLEN_SSL = 117;
13
  const LEN_MCRYPT = 16;
14
 
@@ -21,11 +21,11 @@ class Komfortkasse
21
  public static function readorders()
22
  {
23
  Komfortkasse::read(false);
24
-
25
  }
26
 
27
  // end readorders()
28
-
29
 
30
  /**
31
  * Read refunds.
@@ -35,17 +35,17 @@ class Komfortkasse
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)
@@ -53,15 +53,15 @@ class Komfortkasse
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) {
@@ -69,11 +69,11 @@ class Komfortkasse
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 = '';
@@ -87,15 +87,15 @@ class Komfortkasse
87
  $order = Komfortkasse_Order::getOrder($id);
88
  $order['type'] = self::getOrderType($order['payment_method']);
89
  }
90
-
91
  if (!$order) {
92
  continue;
93
  }
94
-
95
  $o = $o . http_build_query($order);
96
  $o = $o . "\n";
97
  }
98
-
99
  $cry = Komfortkasse::kkencrypt($o);
100
  if ($cry === false) {
101
  Komfortkasse::output(Komfortkasse::kkcrypterror());
@@ -107,7 +107,7 @@ class Komfortkasse
107
  }
108
 
109
  // end read()
110
-
111
 
112
  /**
113
  * Test.
@@ -117,15 +117,15 @@ class Komfortkasse
117
  public static function test()
118
  {
119
  $dec = Komfortkasse::kkdecrypt(Komfortkasse_Config::getRequestParameter('test'));
120
-
121
  $enc = Komfortkasse::kkencrypt($dec);
122
-
123
  Komfortkasse::output($enc);
124
-
125
  }
126
 
127
  // end test()
128
-
129
 
130
  /**
131
  * Init.
@@ -135,7 +135,7 @@ class Komfortkasse
135
  public static function init()
136
  {
137
  Komfortkasse::output('connection:connectionsuccess|');
138
-
139
  Komfortkasse::output('accesskey:');
140
  // Set access code.
141
  $hashed = md5(Komfortkasse_Config::getRequestParameter('accesscode'));
@@ -144,15 +144,15 @@ class Komfortkasse
144
  Komfortkasse::output('Access Code already set! Shop ' . $current . ', given (hash) ' . $hashed);
145
  return;
146
  }
147
-
148
  if ($hashed != Komfortkasse_Config::getRequestParameter('accesscode_hash')) {
149
  Komfortkasse::output('MD5 Hashes do not match! Shop ' . $hashed . ' given ' . Komfortkasse_Config::getRequestParameter('accesscode_hash'));
150
  return;
151
  }
152
-
153
  Komfortkasse_Config::setConfig(Komfortkasse_Config::accesscode, $hashed);
154
  Komfortkasse::output('accesskeysuccess|');
155
-
156
  Komfortkasse::output('apikey:');
157
  // Set API key.
158
  $apikey = Komfortkasse_Config::getRequestParameter('apikey');
@@ -160,21 +160,21 @@ class Komfortkasse
160
  Komfortkasse::output('API Key already set! Shop ' . Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) . ', given ' . $apikey);
161
  return;
162
  }
163
-
164
  Komfortkasse_Config::setConfig(Komfortkasse_Config::apikey, $apikey);
165
  Komfortkasse::output('apikeysuccess|');
166
-
167
  Komfortkasse::output('encryption:');
168
  $encryptionstring = null;
169
  // Look for openssl encryption.
170
  if (extension_loaded('openssl') === true) {
171
-
172
  // Look for public&privatekey encryption.
173
  $kpriv = Komfortkasse_Config::getRequestParameter('privateKey');
174
  $kpub = Komfortkasse_Config::getRequestParameter('publicKey');
175
  Komfortkasse_Config::setConfig(Komfortkasse_Config::privatekey, $kpriv);
176
  Komfortkasse_Config::setConfig(Komfortkasse_Config::publickey, $kpub);
177
-
178
  // Try with rsa.
179
  $crypttest = Komfortkasse_Config::getRequestParameter('testSSLEnc');
180
  $decrypt = Komfortkasse::kkdecrypt($crypttest, 'openssl');
@@ -183,14 +183,14 @@ class Komfortkasse
183
  Komfortkasse_Config::setConfig(Komfortkasse_Config::encryption, 'openssl');
184
  }
185
  }
186
-
187
  if (!$encryptionstring && extension_loaded('mcrypt') === true) {
188
  // Look for mcrypt encryption.
189
  $sec = Komfortkasse_Config::getRequestParameter('mCryptSecretKey');
190
  $iv = Komfortkasse_Config::getRequestParameter('mCryptIV');
191
  Komfortkasse_Config::setConfig(Komfortkasse_Config::privatekey, $sec);
192
  Komfortkasse_Config::setConfig(Komfortkasse_Config::publickey, $iv);
193
-
194
  // Try with mcrypt.
195
  $crypttest = Komfortkasse_Config::getRequestParameter('testMCryptEnc');
196
  $decrypt = Komfortkasse::kkdecrypt($crypttest, 'mcrypt');
@@ -199,7 +199,7 @@ class Komfortkasse
199
  Komfortkasse_Config::setConfig(Komfortkasse_Config::encryption, 'mcrypt');
200
  }
201
  }
202
-
203
  // Fallback: base64.
204
  if (!$encryptionstring) {
205
  // Try with base64 encoding.
@@ -210,13 +210,13 @@ class Komfortkasse
210
  Komfortkasse_Config::setConfig(Komfortkasse_Config::encryption, 'base64');
211
  }
212
  }
213
-
214
  if (!$encryptionstring) {
215
  $encryptionstring = 'ERROR:no encryption possible|';
216
  }
217
-
218
  Komfortkasse::output($encryptionstring);
219
-
220
  Komfortkasse::output('decryptiontest:');
221
  $decrypt = Komfortkasse::kkdecrypt($crypttest, Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption));
222
  if ($decrypt === 'Can you hear me?') {
@@ -224,7 +224,7 @@ class Komfortkasse
224
  } else {
225
  Komfortkasse::output(Komfortkasse::kkcrypterror());
226
  }
227
-
228
  Komfortkasse::output('|encryptiontest:');
229
  $encrypt = Komfortkasse::kkencrypt('Yes, I see you!', Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption));
230
  if ($encrypt !== false) {
@@ -232,11 +232,11 @@ class Komfortkasse
232
  } else {
233
  Komfortkasse::output(Komfortkasse::kkcrypterror());
234
  }
235
-
236
  }
237
 
238
  // end init()
239
-
240
 
241
  /**
242
  * Update orders.
@@ -246,11 +246,11 @@ class Komfortkasse
246
  public static function updateorders()
247
  {
248
  Komfortkasse::update(false);
249
-
250
  }
251
 
252
  // end updateorders()
253
-
254
 
255
  /**
256
  * Update refunds.
@@ -260,17 +260,17 @@ class Komfortkasse
260
  public static function updaterefunds()
261
  {
262
  Komfortkasse::update(true);
263
-
264
  }
265
 
266
  // end updaterefunds()
267
-
268
 
269
  /**
270
  * Update refunds or order.
271
  *
272
  * @param bool $refunds if refunds should be updated.
273
- *
274
  * @return void
275
  */
276
  public static function update($refunds)
@@ -278,18 +278,18 @@ class Komfortkasse
278
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_update)) {
279
  return;
280
  }
281
-
282
  if (Komfortkasse::check() === false) {
283
  return;
284
  }
285
-
286
  $param = Komfortkasse_Config::getRequestParameter('o');
287
  $param = Komfortkasse::kkdecrypt($param);
288
-
289
  if ($refunds === false) {
290
  $openids = Komfortkasse_Order::getOpenIDs();
291
  }
292
-
293
  $o = '';
294
  $lines = explode("\n", $param);
295
  foreach ($lines as $line) {
@@ -301,17 +301,17 @@ class Komfortkasse
301
  } else {
302
  $status = null;
303
  }
304
-
305
  if ($count > 2) {
306
  $callbackid = trim($col [2]);
307
  } else {
308
  $callbackid = null;
309
  }
310
-
311
  if (empty($id) === true || empty($status) === true) {
312
  continue;
313
  }
314
-
315
  if ($refunds === true) {
316
  Komfortkasse_Order::updateRefund($id, $status, $callbackid);
317
  } else {
@@ -319,46 +319,46 @@ class Komfortkasse
319
  if ($id != $order ['number']) {
320
  continue;
321
  }
322
-
323
  $newstatus = Komfortkasse::getNewStatus($status, $order);
324
  if (empty($newstatus) === true) {
325
  continue;
326
  }
327
-
328
  // only update if order status update is necessary (dont update if order has been updated manually)
329
  if ($order['status'] == $newstatus) {
330
  $o = $o . Komfortkasse::kk_csv($id);
331
  continue;
332
  }
333
-
334
  // dont update if order is no longer relevant (will be marked as DISAPPEARED later on)
335
  if (in_array($order ['number'], $openids) === false) {
336
  continue;
337
  }
338
-
339
  Komfortkasse_Order::updateOrder($order, $newstatus, $callbackid);
340
  }
341
-
342
  $o = $o . Komfortkasse::kk_csv($id);
343
  } // end foreach
344
-
345
  $cry = Komfortkasse::kkencrypt($o);
346
  if ($cry === false) {
347
  Komfortkasse::output(Komfortkasse::kkcrypterror());
348
  } else {
349
  Komfortkasse::output($cry);
350
  }
351
-
352
  }
353
 
354
  // end update()
355
-
356
 
357
  /**
358
- * Noify order.
359
  *
360
  * @param unknown $id Order ID
361
- *
362
  * @return void
363
  */
364
  public static function notifyorder($id)
@@ -366,35 +366,36 @@ class Komfortkasse
366
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export)) {
367
  return;
368
  }
369
-
370
  // See if order is relevant.
371
  $openids = Komfortkasse_Order::getOpenIDs();
372
  if (in_array($id, $openids) === false) {
373
  return;
374
  }
375
-
376
  $order = Komfortkasse_Order::getOrder($id);
377
  $order['type'] = self::getOrderType($order['payment_method']);
378
-
379
  $queryRaw = http_build_query($order);
380
-
381
  $queryEnc = Komfortkasse::kkencrypt($queryRaw);
382
-
383
- $query = http_build_query(array ('q' => $queryEnc,'hash' => Komfortkasse_Config::getConfig(Komfortkasse_Config::accesscode),'key' => Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey)
384
  ));
385
-
386
- $contextData = array ('method' => 'POST','timeout' => 2,'header' => "Connection: close\r\n" . 'Content-Length: ' . strlen($query) . "\r\n",'content' => $query
387
  );
388
-
389
- $context = stream_context_create(array ('http' => $contextData
390
  ));
391
-
392
  // Development: http://localhost:8080/kkos01/api...
393
  $result = @file_get_contents('http://api.komfortkasse.eu/api/shop/neworder.jsf', false, $context);
 
394
  }
395
 
396
  // end notifyorder()
397
-
398
 
399
  /**
400
  * Info.
@@ -406,36 +407,36 @@ class Komfortkasse
406
  if (Komfortkasse::check() === false) {
407
  return;
408
  }
409
-
410
  $version = Komfortkasse_Config::getVersion();
411
-
412
  $o = '';
413
  $o = $o . Komfortkasse::kk_csv($version);
414
  $o = $o . Komfortkasse::kk_csv(Komfortkasse::PLUGIN_VER);
415
-
416
  $cry = Komfortkasse::kkencrypt($o);
417
  if ($cry === false) {
418
  Komfortkasse::output(Komfortkasse::kkcrypterror());
419
  } else {
420
  Komfortkasse::output($cry);
421
  }
422
-
423
  }
424
 
425
  // end info()
426
-
427
 
428
  /**
429
  * Retrieve new status.
430
  *
431
  * @param unknown $status Status
432
- *
433
  * @return mixed
434
  */
435
  protected static function getNewStatus($status, $order)
436
  {
437
  $orderType = self::getOrderType($order ['payment_method']);
438
-
439
  switch ($orderType) {
440
  case 'PREPAYMENT' :
441
  switch ($status) {
@@ -444,7 +445,7 @@ class Komfortkasse
444
  case 'CANCELLED' :
445
  return Komfortkasse_Config::getConfig(Komfortkasse_Config::status_cancelled, $order);
446
  }
447
-
448
  return null;
449
  case 'INVOICE' :
450
  switch ($status) {
@@ -466,7 +467,7 @@ class Komfortkasse
466
  }
467
 
468
  // end getNewStatus()
469
-
470
 
471
  /**
472
  * Check.
@@ -476,17 +477,17 @@ class Komfortkasse
476
  public static function check()
477
  {
478
  $ac = Komfortkasse_Config::getRequestParameter('accesscode');
479
-
480
  if (!$ac || md5($ac) !== Komfortkasse_Config::getConfig(Komfortkasse_Config::accesscode)) {
481
  return false;
482
  } else {
483
  return true;
484
  }
485
-
486
  }
487
 
488
  // end check()
489
-
490
 
491
  /**
492
  * Encrypt.
@@ -494,7 +495,7 @@ class Komfortkasse
494
  * @param string $s String to encrypt
495
  * @param string $encryption encryption method
496
  * @param string $keystring key string
497
- *
498
  * @return mixed
499
  *
500
  */
@@ -509,7 +510,7 @@ class Komfortkasse
509
  if ($s === '') {
510
  return '';
511
  }
512
-
513
  switch ($encryption) {
514
  case 'openssl' :
515
  return Komfortkasse::kkencrypt_openssl($s, $keystring);
@@ -518,11 +519,11 @@ class Komfortkasse
518
  case 'base64' :
519
  return Komfortkasse::kkencrypt_base64($s);
520
  }
521
-
522
  }
523
 
524
  // end kkencrypt()
525
-
526
 
527
  /**
528
  * Decrypt.
@@ -531,7 +532,7 @@ class Komfortkasse
531
  * @param string $s String to decrypt
532
  * @param string $encryption encryption method
533
  * @param string $keystring key string
534
- *
535
  * @return Ambigous <boolean, string>|string
536
  */
537
  protected static function kkdecrypt($s, $encryption = null, $keystring = null)
@@ -545,7 +546,7 @@ class Komfortkasse
545
  if ($s === '') {
546
  return '';
547
  }
548
-
549
  switch ($encryption) {
550
  case 'openssl' :
551
  return Komfortkasse::kkdecrypt_openssl($s, $keystring);
@@ -554,17 +555,17 @@ class Komfortkasse
554
  case 'base64' :
555
  return Komfortkasse::kkdecrypt_base64($s);
556
  }
557
-
558
  }
559
 
560
  // end kkdecrypt()
561
-
562
 
563
  /**
564
  * Show encryption/decryption error.
565
  *
566
  * @param string $encryption encryption method
567
- *
568
  * @return mixed
569
  */
570
  protected static function kkcrypterror($encryption)
@@ -572,54 +573,54 @@ class Komfortkasse
572
  if (!$encryption) {
573
  $encryption = Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption);
574
  }
575
-
576
  switch ($encryption) {
577
  case 'openssl' :
578
  return str_replace(':', ';', openssl_error_string());
579
  }
580
-
581
  }
582
 
583
  // end kkcrypterror()
584
-
585
 
586
  /**
587
  * Encrypt with base 64.
588
  *
589
  * @param string $s String to encrypt
590
- *
591
  * @return string decrypted string
592
  */
593
  protected static function kkencrypt_base64($s)
594
  {
595
  return Komfortkasse::mybase64_encode($s);
596
-
597
  }
598
 
599
  // end kkencrypt_base64()
600
-
601
 
602
  /**
603
  * Decrypt with base 64.
604
  *
605
  * @param string $s String to decrypt
606
- *
607
  * @return string decrypted string
608
  */
609
  protected static function kkdecrypt_base64($s)
610
  {
611
  return Komfortkasse::mybase64_decode($s);
612
-
613
  }
614
 
615
  // end kkdecrypt_base64()
616
-
617
 
618
  /**
619
  * Encrypt with mcrypt.
620
  *
621
  * @param string $s String to encrypt
622
- *
623
  * @return string decrypted string
624
  */
625
  protected static function kkencrypt_mcrypt($s)
@@ -628,75 +629,75 @@ class Komfortkasse
628
  $iv = Komfortkasse_Config::getConfig(Komfortkasse_Config::publickey);
629
  $td = mcrypt_module_open('rijndael-128', ' ', 'cbc', $iv);
630
  $init = mcrypt_generic_init($td, $key, $iv);
631
-
632
  $padlen = ((strlen($s) + Komfortkasse::LEN_MCRYPT) % Komfortkasse::LEN_MCRYPT);
633
  $s = str_pad($s, (strlen($s) + $padlen), ' ');
634
  $encrypted = mcrypt_generic($td, $s);
635
-
636
  mcrypt_generic_deinit($td);
637
  mcrypt_module_close($td);
638
-
639
  return Komfortkasse::mybase64_encode($encrypted);
640
-
641
  }
642
 
643
  // end kkencrypt_mcrypt()
644
-
645
 
646
  /**
647
  * Encrypt with open ssl.
648
  *
649
  * @param string $s String to encrypt
650
  * @param string $keystring Key string
651
- *
652
  * @return string decrypted string
653
  */
654
  protected static function kkencrypt_openssl($s, $keystring)
655
  {
656
  $ret = '';
657
-
658
  $pubkey = "-----BEGIN PUBLIC KEY-----\n" . chunk_split($keystring, 64, "\n") . "-----END PUBLIC KEY-----\n";
659
  $key = openssl_get_publickey($pubkey);
660
  if ($key === false) {
661
  return false;
662
  }
663
-
664
  do {
665
  $current = substr($s, 0, Komfortkasse::MAXLEN_SSL);
666
  $s = substr($s, Komfortkasse::MAXLEN_SSL);
667
  if (openssl_public_encrypt($current, $encrypted, $key) === false) {
668
  return false;
669
  }
670
-
671
  $ret = $ret . "\n" . Komfortkasse::mybase64_encode($encrypted);
672
  } while ( $s );
673
-
674
  openssl_free_key($key);
675
  return $ret;
676
-
677
  }
678
 
679
  // end kkencrypt_openssl()
680
-
681
 
682
  /**
683
  * Decrypt with open ssl.
684
  *
685
  * @param string $s String to decrypt
686
  * @param string $keystring Key string
687
- *
688
  * @return string decrypted string
689
  */
690
  protected static function kkdecrypt_openssl($s, $keystring)
691
  {
692
  $ret = '';
693
-
694
  $privkey = "-----BEGIN RSA PRIVATE KEY-----\n" . chunk_split($keystring, 64, "\n") . "-----END RSA PRIVATE KEY-----\n";
695
  $key = openssl_get_privatekey($privkey);
696
  if ($key === false) {
697
  return false;
698
  }
699
-
700
  $parts = explode("\n", $s);
701
  foreach ($parts as $part) {
702
  if ($part) {
@@ -706,20 +707,20 @@ class Komfortkasse
706
  $ret = $ret . $decrypted;
707
  }
708
  }
709
-
710
  openssl_free_key($key);
711
  return $ret;
712
-
713
  }
714
 
715
  // end kkdecrypt_openssl()
716
-
717
 
718
  /**
719
  * Decrypt with mcrypt.
720
  *
721
  * @param string $s String to decrypt
722
- *
723
  * @return string decrypted string
724
  */
725
  protected static function kkdecrypt_mcrypt($s)
@@ -728,9 +729,9 @@ class Komfortkasse
728
  $iv = Komfortkasse_Config::getConfig(Komfortkasse_Config::publickey);
729
  $td = mcrypt_module_open('rijndael-128', ' ', 'cbc', $iv);
730
  $init = mcrypt_generic_init($td, $key, $iv);
731
-
732
  $ret = '';
733
-
734
  $parts = explode("\n", $s);
735
  foreach ($parts as $part) {
736
  if ($part) {
@@ -738,31 +739,31 @@ class Komfortkasse
738
  $ret = $ret . trim($decrypted);
739
  }
740
  }
741
-
742
  mcrypt_generic_deinit($td);
743
  mcrypt_module_close($td);
744
  return $ret;
745
-
746
  }
747
 
748
  // end kkdecrypt_mcrypt()
749
-
750
 
751
  /**
752
  * Output CSV.
753
  *
754
  * @param string $s String to output
755
- *
756
  * @return string CSV
757
  */
758
  protected static function kk_csv($s)
759
  {
760
  return '"' . str_replace('"', '', str_replace(';', ',', utf8_encode($s))) . '";';
761
-
762
  }
763
 
764
  // end kk_csv()
765
-
766
 
767
  /**
768
  * Output
@@ -772,41 +773,41 @@ class Komfortkasse
772
  protected static function output($s)
773
  {
774
  echo $s;
775
-
776
  }
777
 
778
  // end output()
779
-
780
 
781
  /**
782
  * Count
783
  *
784
  * @param array $array Arrays
785
- *
786
  * @return int count
787
  */
788
  protected static function mycount($array)
789
  {
790
  return count($array);
791
-
792
  }
793
 
794
  // end mycount()
795
  protected static function mybase64_decode($s)
796
  {
797
  return base64_decode($s);
798
-
799
  }
800
 
801
  // end mybase64_decode()
802
  protected static function mybase64_encode($s)
803
  {
804
  return base64_encode($s);
805
-
806
  }
807
 
808
  // end mybase64_encode()
809
-
810
  private static function getOrderType($payment_method) {
811
  $paycodes = preg_split('/,/', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods));
812
  if (in_array($payment_method, $paycodes))
@@ -819,24 +820,24 @@ class Komfortkasse
819
  return 'COD';
820
  return '';
821
  }
822
-
823
  public static function readinvoicepdf() {
824
  Komfortkasse_Order::getInvoicePdfPrepare();
825
-
826
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export)) {
827
  return;
828
  }
829
-
830
  if (Komfortkasse::check() === false) {
831
  return;
832
  }
833
-
834
  $invoiceNumber = Komfortkasse_Config::getRequestParameter('o');
835
  $invoiceNumber = Komfortkasse::kkdecrypt($invoiceNumber);
836
  $orderNumber = Komfortkasse_Config::getRequestParameter('order_id');
837
  $orderNumber = Komfortkasse::kkdecrypt($orderNumber);
838
-
839
  return Komfortkasse_Order::getInvoicePdf($invoiceNumber, $orderNumber);
840
-
841
  }
842
  }
8
  */
9
  class Komfortkasse
10
  {
11
+ const PLUGIN_VER = '1.4.3.1';
12
  const MAXLEN_SSL = 117;
13
  const LEN_MCRYPT = 16;
14
 
21
  public static function readorders()
22
  {
23
  Komfortkasse::read(false);
24
+
25
  }
26
 
27
  // end readorders()
28
+
29
 
30
  /**
31
  * Read refunds.
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)
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) {
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 = '';
87
  $order = Komfortkasse_Order::getOrder($id);
88
  $order['type'] = self::getOrderType($order['payment_method']);
89
  }
90
+
91
  if (!$order) {
92
  continue;
93
  }
94
+
95
  $o = $o . http_build_query($order);
96
  $o = $o . "\n";
97
  }
98
+
99
  $cry = Komfortkasse::kkencrypt($o);
100
  if ($cry === false) {
101
  Komfortkasse::output(Komfortkasse::kkcrypterror());
107
  }
108
 
109
  // end read()
110
+
111
 
112
  /**
113
  * Test.
117
  public static function test()
118
  {
119
  $dec = Komfortkasse::kkdecrypt(Komfortkasse_Config::getRequestParameter('test'));
120
+
121
  $enc = Komfortkasse::kkencrypt($dec);
122
+
123
  Komfortkasse::output($enc);
124
+
125
  }
126
 
127
  // end test()
128
+
129
 
130
  /**
131
  * Init.
135
  public static function init()
136
  {
137
  Komfortkasse::output('connection:connectionsuccess|');
138
+
139
  Komfortkasse::output('accesskey:');
140
  // Set access code.
141
  $hashed = md5(Komfortkasse_Config::getRequestParameter('accesscode'));
144
  Komfortkasse::output('Access Code already set! Shop ' . $current . ', given (hash) ' . $hashed);
145
  return;
146
  }
147
+
148
  if ($hashed != Komfortkasse_Config::getRequestParameter('accesscode_hash')) {
149
  Komfortkasse::output('MD5 Hashes do not match! Shop ' . $hashed . ' given ' . Komfortkasse_Config::getRequestParameter('accesscode_hash'));
150
  return;
151
  }
152
+
153
  Komfortkasse_Config::setConfig(Komfortkasse_Config::accesscode, $hashed);
154
  Komfortkasse::output('accesskeysuccess|');
155
+
156
  Komfortkasse::output('apikey:');
157
  // Set API key.
158
  $apikey = Komfortkasse_Config::getRequestParameter('apikey');
160
  Komfortkasse::output('API Key already set! Shop ' . Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) . ', given ' . $apikey);
161
  return;
162
  }
163
+
164
  Komfortkasse_Config::setConfig(Komfortkasse_Config::apikey, $apikey);
165
  Komfortkasse::output('apikeysuccess|');
166
+
167
  Komfortkasse::output('encryption:');
168
  $encryptionstring = null;
169
  // Look for openssl encryption.
170
  if (extension_loaded('openssl') === true) {
171
+
172
  // Look for public&privatekey encryption.
173
  $kpriv = Komfortkasse_Config::getRequestParameter('privateKey');
174
  $kpub = Komfortkasse_Config::getRequestParameter('publicKey');
175
  Komfortkasse_Config::setConfig(Komfortkasse_Config::privatekey, $kpriv);
176
  Komfortkasse_Config::setConfig(Komfortkasse_Config::publickey, $kpub);
177
+
178
  // Try with rsa.
179
  $crypttest = Komfortkasse_Config::getRequestParameter('testSSLEnc');
180
  $decrypt = Komfortkasse::kkdecrypt($crypttest, 'openssl');
183
  Komfortkasse_Config::setConfig(Komfortkasse_Config::encryption, 'openssl');
184
  }
185
  }
186
+
187
  if (!$encryptionstring && extension_loaded('mcrypt') === true) {
188
  // Look for mcrypt encryption.
189
  $sec = Komfortkasse_Config::getRequestParameter('mCryptSecretKey');
190
  $iv = Komfortkasse_Config::getRequestParameter('mCryptIV');
191
  Komfortkasse_Config::setConfig(Komfortkasse_Config::privatekey, $sec);
192
  Komfortkasse_Config::setConfig(Komfortkasse_Config::publickey, $iv);
193
+
194
  // Try with mcrypt.
195
  $crypttest = Komfortkasse_Config::getRequestParameter('testMCryptEnc');
196
  $decrypt = Komfortkasse::kkdecrypt($crypttest, 'mcrypt');
199
  Komfortkasse_Config::setConfig(Komfortkasse_Config::encryption, 'mcrypt');
200
  }
201
  }
202
+
203
  // Fallback: base64.
204
  if (!$encryptionstring) {
205
  // Try with base64 encoding.
210
  Komfortkasse_Config::setConfig(Komfortkasse_Config::encryption, 'base64');
211
  }
212
  }
213
+
214
  if (!$encryptionstring) {
215
  $encryptionstring = 'ERROR:no encryption possible|';
216
  }
217
+
218
  Komfortkasse::output($encryptionstring);
219
+
220
  Komfortkasse::output('decryptiontest:');
221
  $decrypt = Komfortkasse::kkdecrypt($crypttest, Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption));
222
  if ($decrypt === 'Can you hear me?') {
224
  } else {
225
  Komfortkasse::output(Komfortkasse::kkcrypterror());
226
  }
227
+
228
  Komfortkasse::output('|encryptiontest:');
229
  $encrypt = Komfortkasse::kkencrypt('Yes, I see you!', Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption));
230
  if ($encrypt !== false) {
232
  } else {
233
  Komfortkasse::output(Komfortkasse::kkcrypterror());
234
  }
235
+
236
  }
237
 
238
  // end init()
239
+
240
 
241
  /**
242
  * Update orders.
246
  public static function updateorders()
247
  {
248
  Komfortkasse::update(false);
249
+
250
  }
251
 
252
  // end updateorders()
253
+
254
 
255
  /**
256
  * Update refunds.
260
  public static function updaterefunds()
261
  {
262
  Komfortkasse::update(true);
263
+
264
  }
265
 
266
  // end updaterefunds()
267
+
268
 
269
  /**
270
  * Update refunds or order.
271
  *
272
  * @param bool $refunds if refunds should be updated.
273
+ *
274
  * @return void
275
  */
276
  public static function update($refunds)
278
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_update)) {
279
  return;
280
  }
281
+
282
  if (Komfortkasse::check() === false) {
283
  return;
284
  }
285
+
286
  $param = Komfortkasse_Config::getRequestParameter('o');
287
  $param = Komfortkasse::kkdecrypt($param);
288
+
289
  if ($refunds === false) {
290
  $openids = Komfortkasse_Order::getOpenIDs();
291
  }
292
+
293
  $o = '';
294
  $lines = explode("\n", $param);
295
  foreach ($lines as $line) {
301
  } else {
302
  $status = null;
303
  }
304
+
305
  if ($count > 2) {
306
  $callbackid = trim($col [2]);
307
  } else {
308
  $callbackid = null;
309
  }
310
+
311
  if (empty($id) === true || empty($status) === true) {
312
  continue;
313
  }
314
+
315
  if ($refunds === true) {
316
  Komfortkasse_Order::updateRefund($id, $status, $callbackid);
317
  } else {
319
  if ($id != $order ['number']) {
320
  continue;
321
  }
322
+
323
  $newstatus = Komfortkasse::getNewStatus($status, $order);
324
  if (empty($newstatus) === true) {
325
  continue;
326
  }
327
+
328
  // only update if order status update is necessary (dont update if order has been updated manually)
329
  if ($order['status'] == $newstatus) {
330
  $o = $o . Komfortkasse::kk_csv($id);
331
  continue;
332
  }
333
+
334
  // dont update if order is no longer relevant (will be marked as DISAPPEARED later on)
335
  if (in_array($order ['number'], $openids) === false) {
336
  continue;
337
  }
338
+
339
  Komfortkasse_Order::updateOrder($order, $newstatus, $callbackid);
340
  }
341
+
342
  $o = $o . Komfortkasse::kk_csv($id);
343
  } // end foreach
344
+
345
  $cry = Komfortkasse::kkencrypt($o);
346
  if ($cry === false) {
347
  Komfortkasse::output(Komfortkasse::kkcrypterror());
348
  } else {
349
  Komfortkasse::output($cry);
350
  }
351
+
352
  }
353
 
354
  // end update()
355
+
356
 
357
  /**
358
+ * Notify order.
359
  *
360
  * @param unknown $id Order ID
361
+ *
362
  * @return void
363
  */
364
  public static function notifyorder($id)
366
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export)) {
367
  return;
368
  }
369
+
370
  // See if order is relevant.
371
  $openids = Komfortkasse_Order::getOpenIDs();
372
  if (in_array($id, $openids) === false) {
373
  return;
374
  }
375
+
376
  $order = Komfortkasse_Order::getOrder($id);
377
  $order['type'] = self::getOrderType($order['payment_method']);
378
+
379
  $queryRaw = http_build_query($order);
380
+
381
  $queryEnc = Komfortkasse::kkencrypt($queryRaw);
382
+
383
+ $query = http_build_query(array ('q' => $queryEnc,'hash' => Komfortkasse_Config::getConfig(Komfortkasse_Config::accesscode),'key' => Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey)
384
  ));
385
+
386
+ $contextData = array ('method' => 'POST','timeout' => 2,'header' => "Connection: close\r\n" . 'Content-Length: ' . strlen($query) . "\r\n",'content' => $query
387
  );
388
+
389
+ $context = stream_context_create(array ('http' => $contextData
390
  ));
391
+
392
  // Development: http://localhost:8080/kkos01/api...
393
  $result = @file_get_contents('http://api.komfortkasse.eu/api/shop/neworder.jsf', false, $context);
394
+
395
  }
396
 
397
  // end notifyorder()
398
+
399
 
400
  /**
401
  * Info.
407
  if (Komfortkasse::check() === false) {
408
  return;
409
  }
410
+
411
  $version = Komfortkasse_Config::getVersion();
412
+
413
  $o = '';
414
  $o = $o . Komfortkasse::kk_csv($version);
415
  $o = $o . Komfortkasse::kk_csv(Komfortkasse::PLUGIN_VER);
416
+
417
  $cry = Komfortkasse::kkencrypt($o);
418
  if ($cry === false) {
419
  Komfortkasse::output(Komfortkasse::kkcrypterror());
420
  } else {
421
  Komfortkasse::output($cry);
422
  }
423
+
424
  }
425
 
426
  // end info()
427
+
428
 
429
  /**
430
  * Retrieve new status.
431
  *
432
  * @param unknown $status Status
433
+ *
434
  * @return mixed
435
  */
436
  protected static function getNewStatus($status, $order)
437
  {
438
  $orderType = self::getOrderType($order ['payment_method']);
439
+
440
  switch ($orderType) {
441
  case 'PREPAYMENT' :
442
  switch ($status) {
445
  case 'CANCELLED' :
446
  return Komfortkasse_Config::getConfig(Komfortkasse_Config::status_cancelled, $order);
447
  }
448
+
449
  return null;
450
  case 'INVOICE' :
451
  switch ($status) {
467
  }
468
 
469
  // end getNewStatus()
470
+
471
 
472
  /**
473
  * Check.
477
  public static function check()
478
  {
479
  $ac = Komfortkasse_Config::getRequestParameter('accesscode');
480
+
481
  if (!$ac || md5($ac) !== Komfortkasse_Config::getConfig(Komfortkasse_Config::accesscode)) {
482
  return false;
483
  } else {
484
  return true;
485
  }
486
+
487
  }
488
 
489
  // end check()
490
+
491
 
492
  /**
493
  * Encrypt.
495
  * @param string $s String to encrypt
496
  * @param string $encryption encryption method
497
  * @param string $keystring key string
498
+ *
499
  * @return mixed
500
  *
501
  */
510
  if ($s === '') {
511
  return '';
512
  }
513
+
514
  switch ($encryption) {
515
  case 'openssl' :
516
  return Komfortkasse::kkencrypt_openssl($s, $keystring);
519
  case 'base64' :
520
  return Komfortkasse::kkencrypt_base64($s);
521
  }
522
+
523
  }
524
 
525
  // end kkencrypt()
526
+
527
 
528
  /**
529
  * Decrypt.
532
  * @param string $s String to decrypt
533
  * @param string $encryption encryption method
534
  * @param string $keystring key string
535
+ *
536
  * @return Ambigous <boolean, string>|string
537
  */
538
  protected static function kkdecrypt($s, $encryption = null, $keystring = null)
546
  if ($s === '') {
547
  return '';
548
  }
549
+
550
  switch ($encryption) {
551
  case 'openssl' :
552
  return Komfortkasse::kkdecrypt_openssl($s, $keystring);
555
  case 'base64' :
556
  return Komfortkasse::kkdecrypt_base64($s);
557
  }
558
+
559
  }
560
 
561
  // end kkdecrypt()
562
+
563
 
564
  /**
565
  * Show encryption/decryption error.
566
  *
567
  * @param string $encryption encryption method
568
+ *
569
  * @return mixed
570
  */
571
  protected static function kkcrypterror($encryption)
573
  if (!$encryption) {
574
  $encryption = Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption);
575
  }
576
+
577
  switch ($encryption) {
578
  case 'openssl' :
579
  return str_replace(':', ';', openssl_error_string());
580
  }
581
+
582
  }
583
 
584
  // end kkcrypterror()
585
+
586
 
587
  /**
588
  * Encrypt with base 64.
589
  *
590
  * @param string $s String to encrypt
591
+ *
592
  * @return string decrypted string
593
  */
594
  protected static function kkencrypt_base64($s)
595
  {
596
  return Komfortkasse::mybase64_encode($s);
597
+
598
  }
599
 
600
  // end kkencrypt_base64()
601
+
602
 
603
  /**
604
  * Decrypt with base 64.
605
  *
606
  * @param string $s String to decrypt
607
+ *
608
  * @return string decrypted string
609
  */
610
  protected static function kkdecrypt_base64($s)
611
  {
612
  return Komfortkasse::mybase64_decode($s);
613
+
614
  }
615
 
616
  // end kkdecrypt_base64()
617
+
618
 
619
  /**
620
  * Encrypt with mcrypt.
621
  *
622
  * @param string $s String to encrypt
623
+ *
624
  * @return string decrypted string
625
  */
626
  protected static function kkencrypt_mcrypt($s)
629
  $iv = Komfortkasse_Config::getConfig(Komfortkasse_Config::publickey);
630
  $td = mcrypt_module_open('rijndael-128', ' ', 'cbc', $iv);
631
  $init = mcrypt_generic_init($td, $key, $iv);
632
+
633
  $padlen = ((strlen($s) + Komfortkasse::LEN_MCRYPT) % Komfortkasse::LEN_MCRYPT);
634
  $s = str_pad($s, (strlen($s) + $padlen), ' ');
635
  $encrypted = mcrypt_generic($td, $s);
636
+
637
  mcrypt_generic_deinit($td);
638
  mcrypt_module_close($td);
639
+
640
  return Komfortkasse::mybase64_encode($encrypted);
641
+
642
  }
643
 
644
  // end kkencrypt_mcrypt()
645
+
646
 
647
  /**
648
  * Encrypt with open ssl.
649
  *
650
  * @param string $s String to encrypt
651
  * @param string $keystring Key string
652
+ *
653
  * @return string decrypted string
654
  */
655
  protected static function kkencrypt_openssl($s, $keystring)
656
  {
657
  $ret = '';
658
+
659
  $pubkey = "-----BEGIN PUBLIC KEY-----\n" . chunk_split($keystring, 64, "\n") . "-----END PUBLIC KEY-----\n";
660
  $key = openssl_get_publickey($pubkey);
661
  if ($key === false) {
662
  return false;
663
  }
664
+
665
  do {
666
  $current = substr($s, 0, Komfortkasse::MAXLEN_SSL);
667
  $s = substr($s, Komfortkasse::MAXLEN_SSL);
668
  if (openssl_public_encrypt($current, $encrypted, $key) === false) {
669
  return false;
670
  }
671
+
672
  $ret = $ret . "\n" . Komfortkasse::mybase64_encode($encrypted);
673
  } while ( $s );
674
+
675
  openssl_free_key($key);
676
  return $ret;
677
+
678
  }
679
 
680
  // end kkencrypt_openssl()
681
+
682
 
683
  /**
684
  * Decrypt with open ssl.
685
  *
686
  * @param string $s String to decrypt
687
  * @param string $keystring Key string
688
+ *
689
  * @return string decrypted string
690
  */
691
  protected static function kkdecrypt_openssl($s, $keystring)
692
  {
693
  $ret = '';
694
+
695
  $privkey = "-----BEGIN RSA PRIVATE KEY-----\n" . chunk_split($keystring, 64, "\n") . "-----END RSA PRIVATE KEY-----\n";
696
  $key = openssl_get_privatekey($privkey);
697
  if ($key === false) {
698
  return false;
699
  }
700
+
701
  $parts = explode("\n", $s);
702
  foreach ($parts as $part) {
703
  if ($part) {
707
  $ret = $ret . $decrypted;
708
  }
709
  }
710
+
711
  openssl_free_key($key);
712
  return $ret;
713
+
714
  }
715
 
716
  // end kkdecrypt_openssl()
717
+
718
 
719
  /**
720
  * Decrypt with mcrypt.
721
  *
722
  * @param string $s String to decrypt
723
+ *
724
  * @return string decrypted string
725
  */
726
  protected static function kkdecrypt_mcrypt($s)
729
  $iv = Komfortkasse_Config::getConfig(Komfortkasse_Config::publickey);
730
  $td = mcrypt_module_open('rijndael-128', ' ', 'cbc', $iv);
731
  $init = mcrypt_generic_init($td, $key, $iv);
732
+
733
  $ret = '';
734
+
735
  $parts = explode("\n", $s);
736
  foreach ($parts as $part) {
737
  if ($part) {
739
  $ret = $ret . trim($decrypted);
740
  }
741
  }
742
+
743
  mcrypt_generic_deinit($td);
744
  mcrypt_module_close($td);
745
  return $ret;
746
+
747
  }
748
 
749
  // end kkdecrypt_mcrypt()
750
+
751
 
752
  /**
753
  * Output CSV.
754
  *
755
  * @param string $s String to output
756
+ *
757
  * @return string CSV
758
  */
759
  protected static function kk_csv($s)
760
  {
761
  return '"' . str_replace('"', '', str_replace(';', ',', utf8_encode($s))) . '";';
762
+
763
  }
764
 
765
  // end kk_csv()
766
+
767
 
768
  /**
769
  * Output
773
  protected static function output($s)
774
  {
775
  echo $s;
776
+
777
  }
778
 
779
  // end output()
780
+
781
 
782
  /**
783
  * Count
784
  *
785
  * @param array $array Arrays
786
+ *
787
  * @return int count
788
  */
789
  protected static function mycount($array)
790
  {
791
  return count($array);
792
+
793
  }
794
 
795
  // end mycount()
796
  protected static function mybase64_decode($s)
797
  {
798
  return base64_decode($s);
799
+
800
  }
801
 
802
  // end mybase64_decode()
803
  protected static function mybase64_encode($s)
804
  {
805
  return base64_encode($s);
806
+
807
  }
808
 
809
  // end mybase64_encode()
810
+
811
  private static function getOrderType($payment_method) {
812
  $paycodes = preg_split('/,/', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods));
813
  if (in_array($payment_method, $paycodes))
820
  return 'COD';
821
  return '';
822
  }
823
+
824
  public static function readinvoicepdf() {
825
  Komfortkasse_Order::getInvoicePdfPrepare();
826
+
827
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export)) {
828
  return;
829
  }
830
+
831
  if (Komfortkasse::check() === false) {
832
  return;
833
  }
834
+
835
  $invoiceNumber = Komfortkasse_Config::getRequestParameter('o');
836
  $invoiceNumber = Komfortkasse::kkdecrypt($invoiceNumber);
837
  $orderNumber = Komfortkasse_Config::getRequestParameter('order_id');
838
  $orderNumber = Komfortkasse::kkdecrypt($orderNumber);
839
+
840
  return Komfortkasse_Order::getInvoicePdf($invoiceNumber, $orderNumber);
841
+
842
  }
843
  }
app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse_Order.php CHANGED
@@ -8,7 +8,7 @@
8
  * status: data type according to the shop system
9
  * delivery_ and billing_: _firstname, _lastname, _company, _street, _postcode, _city, _countrycode
10
  * products: an Array of item numbers
11
- * @version 1.4.3-Magento1
12
  */
13
  $path = Mage::getModuleDir('', 'Ltc_Komfortkasse');
14
  $order_extension = false;
@@ -27,52 +27,62 @@ class Komfortkasse_Order
27
  public static function getOpenIDs()
28
  {
29
  $ret = array ();
30
-
31
  foreach (Mage::app()->getWebsites() as $website) {
32
  foreach ($website->getGroups() as $group) {
33
  $stores = $group->getStores();
34
  foreach ($stores as $store) {
35
-
36
  $store_id = $store->getId();
37
  $store_id_order = array ();
38
  $store_id_order ['store_id'] = $store_id;
39
-
40
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export, $store_id_order)) {
41
  continue;
42
  }
43
-
44
  // PREPAYMENT
45
-
46
  $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open, $store_id_order);
47
  $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $store_id_order);
48
-
49
  if (!empty($openOrders) && !empty($paymentMethods)) {
50
  $openOrders = explode(',', $openOrders);
51
  $paymentMethods = explode(',', $paymentMethods);
52
-
53
  $salesModel = Mage::getModel('sales/order');
54
- $salesCollection = $salesModel->getCollection()->addAttributeToFilter('status', array ('in' => $openOrders
55
  ))->addFieldToFilter('store_id', $store_id);
56
-
57
  foreach ($salesCollection as $order) {
58
  try {
59
- $method = $order->getPayment()->getMethodInstance()->getCode();
60
- if (in_array($method, $paymentMethods, true) === true) {
 
 
 
 
 
61
  $orderId = $order->getIncrementId();
62
  $ret [] = $orderId;
63
  }
64
  } catch ( Exception $e ) {
65
  }
66
  }
67
-
68
  // Add all orders with unpaid invoices (in case the invoice is created before shipping).
69
  $invoiceModel = Mage::getModel('sales/order_invoice');
70
  $invoiceCollection = $invoiceModel->getCollection()->addAttributeToFilter('state', Mage_Sales_Model_Order_Invoice::STATE_OPEN)->addFieldToFilter('store_id', $store_id);
71
  foreach ($invoiceCollection as $invoice) {
72
  try {
73
  $order = $invoice->getOrder();
74
- $method = $order->getPayment()->getMethodInstance()->getCode();
75
- if (in_array($method, $paymentMethods, true) === true) {
 
 
 
 
 
76
  $orderId = $order->getIncrementId();
77
  if (in_array($orderId, $ret) === false) {
78
  $ret [] = $orderId;
@@ -82,24 +92,29 @@ class Komfortkasse_Order
82
  }
83
  }
84
  }
85
-
86
  // INVOICE
87
-
88
  $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open_invoice, $store_id_order);
89
  $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_invoice, $store_id_order);
90
-
91
  if (!empty($openOrders) && !empty($paymentMethods)) {
92
  $openOrders = explode(',', $openOrders);
93
  $paymentMethods = explode(',', $paymentMethods);
94
-
95
  $salesModel = Mage::getModel('sales/order');
96
- $salesCollection = $salesModel->getCollection()->addAttributeToFilter('status', array ('in' => $openOrders
97
  ))->addFieldToFilter('store_id', $store_id);
98
-
99
  foreach ($salesCollection as $order) {
100
  try {
101
- $method = $order->getPayment()->getMethodInstance()->getCode();
102
- if (in_array($method, $paymentMethods, true) === true) {
 
 
 
 
 
103
  $orderId = $order->getIncrementId();
104
  $ret [] = $orderId;
105
  }
@@ -107,42 +122,44 @@ class Komfortkasse_Order
107
  }
108
  }
109
  }
110
-
111
  // COD
112
-
113
  $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open_cod, $store_id_order);
114
  $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_cod, $store_id_order);
115
-
116
  if (!empty($openOrders) && !empty($paymentMethods)) {
117
  $openOrders = explode(',', $openOrders);
118
  $paymentMethods = explode(',', $paymentMethods);
119
 
120
  $salesModel = Mage::getModel('sales/order');
121
- $salesCollection = $salesModel->getCollection()->addAttributeToFilter('status', array ('in' => $openOrders
122
  ))->addFieldToFilter('store_id', $store_id);
123
-
124
  foreach ($salesCollection as $order) {
125
  try {
126
  $method = $order->getPayment()->getMethodInstance()->getCode();
127
- if (in_array($method, $paymentMethods, true) === true) {
128
- $orderId = $order->getIncrementId();
129
- $ret [] = $orderId;
130
- }
131
- } catch ( Exception $e ) {
 
 
132
  }
133
  }
134
  }
135
  }
136
  }
137
  }
138
-
139
 
140
  return $ret;
141
-
142
  }
143
-
144
  // end getOpenIDs()
145
-
146
 
147
  /**
148
  * Get refund IDS.
@@ -152,30 +169,35 @@ class Komfortkasse_Order
152
  public static function getRefundIDs()
153
  {
154
  $ret = array ();
155
-
156
  foreach (Mage::app()->getWebsites() as $website) {
157
  foreach ($website->getGroups() as $group) {
158
  $stores = $group->getStores();
159
  foreach ($stores as $store) {
160
-
161
  $store_id = $store->getId();
162
  $store_id_order = array ();
163
  $store_id_order ['store_id'] = $store_id;
164
-
165
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export, $store_id_order)) {
166
  continue;
167
  }
168
-
169
  $paymentMethods = explode(',', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $store_id_order));
170
-
171
  $cmModel = Mage::getModel("sales/order_creditmemo");
172
  $cmCollection = $cmModel->getCollection()->addFieldToFilter('store_id', $store_id);
173
-
174
  foreach ($cmCollection as $creditMemo) {
175
  if ($creditMemo->getTransactionId() == null) {
176
  $order = $creditMemo->getOrder();
 
177
  $method = $order->getPayment()->getMethodInstance()->getCode();
178
- if (in_array($method, $paymentMethods, true) === true) {
 
 
 
 
179
  $cmId = $creditMemo->getIncrementId();
180
  $ret [] = $cmId;
181
  }
@@ -184,19 +206,19 @@ class Komfortkasse_Order
184
  }
185
  }
186
  }
187
-
188
  return $ret;
189
-
190
  }
191
-
192
  // end getRefundIDs()
193
-
194
 
195
  /**
196
  * Get order.
197
  *
198
  * @param string $number order number
199
- *
200
  * @return array order
201
  */
202
  public static function getOrder($number)
@@ -205,20 +227,22 @@ class Komfortkasse_Order
205
  if (empty($number) === true || empty($order) === true || $number != $order->getIncrementId()) {
206
  return null;
207
  }
208
-
209
  $conf_general = Mage::getStoreConfig('general', $order->getStoreId());
210
-
211
  $ret = array ();
212
  $ret ['number'] = $order->getIncrementId();
213
  $ret ['status'] = $order->getStatus();
214
  $ret ['date'] = date('d.m.Y', strtotime($order->getCreatedAtStoreDate()->get(Zend_Date::DATE_MEDIUM)));
215
  $ret ['email'] = $order->getCustomerEmail();
216
  $ret ['customer_number'] = $order->getCustomerId();
217
- $ret ['payment_method'] = $order->getPayment()->getMethodInstance()->getCode();
 
 
218
  $ret ['amount'] = $order->getGrandTotal();
219
  $ret ['currency_code'] = $order->getOrderCurrencyCode();
220
  $ret ['exchange_rate'] = $order->getBaseToOrderRate();
221
-
222
  // Rechnungsnummer und -datum
223
  $invoiceColl = $order->getInvoiceCollection();
224
  if ($invoiceColl->getSize() > 0) {
@@ -230,7 +254,7 @@ class Komfortkasse_Order
230
  }
231
  }
232
  }
233
-
234
  $shippingAddress = $order->getShippingAddress();
235
  if ($shippingAddress) {
236
  $ret ['delivery_firstname'] = utf8_encode($shippingAddress->getFirstname());
@@ -241,7 +265,7 @@ class Komfortkasse_Order
241
  $ret ['delivery_city'] = utf8_encode($shippingAddress->getCity());
242
  $ret ['delivery_countrycode'] = utf8_encode($shippingAddress->getCountryId());
243
  }
244
-
245
  $billingAddress = $order->getBillingAddress();
246
  if ($billingAddress) {
247
  $ret ['language_code'] = substr($conf_general ['locale'] ['code'], 0, 2) . '-' . $billingAddress->getCountryId();
@@ -255,7 +279,7 @@ class Komfortkasse_Order
255
  } else {
256
  $ret ['language_code'] = substr($conf_general ['locale'] ['code'], 0, 2);
257
  }
258
-
259
  foreach ($order->getAllItems() as $itemId => $item) {
260
  $sku = $item->getSku();
261
  if ($sku) {
@@ -264,50 +288,50 @@ class Komfortkasse_Order
264
  $ret ['products'] [] = $item->getName();
265
  }
266
  }
267
-
268
  $ret ['store_id'] = $order->getStoreId();
269
-
270
  if ($order_extension && method_exists('Komfortkasse_Order_Extension', 'extendOrder') === true) {
271
  $ret = Komfortkasse_Order_Extension::extendOrder($order, $ret);
272
  }
273
-
274
  return $ret;
275
-
276
  }
277
-
278
  // end getOrder()
279
-
280
 
281
  /**
282
  * Get refund.
283
  *
284
  * @param string $number refund number
285
- *
286
  * @return array refund
287
  */
288
  public static function getRefund($number)
289
  {
290
  $resource = Mage::getSingleton('core/resource');
291
  $id = $resource->getConnection('core_read')->fetchOne('SELECT `entity_id` FROM `' . $resource->getTableName('sales/creditmemo') . "` WHERE `increment_id` = '" . $number . "'");
292
-
293
  $creditMemo = Mage::getModel('sales/order_creditmemo')->load($id);
294
  if (empty($number) === true || empty($creditMemo) === true || $number != $creditMemo->getIncrementId()) {
295
  return null;
296
  }
297
-
298
  $ret = array ();
299
  $ret ['number'] = $creditMemo->getOrder()->getIncrementId();
300
  // Number of the Creditmemo.
301
  $ret ['customer_number'] = $creditMemo->getIncrementId();
302
  $ret ['date'] = date('d.m.Y', strtotime($creditMemo->getCreatedAt()));
303
  $ret ['amount'] = $creditMemo->getGrandTotal();
304
-
305
  return $ret;
306
-
307
  }
308
-
309
  // end getRefund()
310
-
311
 
312
  /**
313
  * Update order.
@@ -315,7 +339,7 @@ class Komfortkasse_Order
315
  * @param array $order order
316
  * @param string $status status
317
  * @param string $callbackid callback ID
318
- *
319
  * @return void
320
  */
321
  public static function updateOrder($order, $status, $callbackid)
@@ -323,20 +347,20 @@ class Komfortkasse_Order
323
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_update, $order)) {
324
  return;
325
  }
326
-
327
  // Hint: PAID and CANCELLED are supported as of now.
328
  $order = Mage::getModel('sales/order')->loadByIncrementId($order ['number']);
329
-
330
- Mage::dispatchEvent('komfortkasse_change_order_status_before', array ('order' => $order,'status' => $status,'callbackid' => $callbackid
331
  ));
332
-
333
  $stateCollection = Mage::getModel('sales/order_status')->getCollection()->joinStates();
334
- $stateCollection->addFieldToFilter('main_table.status', array ('like' => $status
335
  ));
336
  $state = $stateCollection->getFirstItem()->getState();
337
-
338
  if ($state == 'processing' || $state == 'closed' || $state == 'complete') {
339
-
340
  // If there is already an invoice, update the invoice, not the order.
341
  $invoiceColl = $order->getInvoiceCollection();
342
  if ($invoiceColl->getSize() > 0) {
@@ -348,17 +372,17 @@ class Komfortkasse_Order
348
  } else {
349
  $payment = $order->getPayment();
350
  $payment->capture(null);
351
-
352
  if ($callbackid) {
353
  $payment->setTransactionId($callbackid);
354
  $transaction = $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
355
  }
356
  }
357
-
358
  $history = $order->addStatusHistoryComment('' . $callbackid, $status);
359
  $order->save();
360
  } else if ($state == 'canceled') {
361
-
362
  if ($callbackid) {
363
  $history = $order->addStatusHistoryComment('' . $callbackid, $status);
364
  }
@@ -368,18 +392,18 @@ class Komfortkasse_Order
368
  $order->setStatus($status);
369
  $order->save();
370
  } else {
371
-
372
  $history = $order->addStatusHistoryComment('' . $callbackid, $status);
373
  $order->save();
374
  }
375
-
376
- Mage::dispatchEvent('komfortkasse_change_order_status_after', array ('order' => $order,'status' => $status,'callbackid' => $callbackid
377
  ));
378
-
379
  }
380
-
381
  // end updateOrder()
382
-
383
 
384
  /**
385
  * Update order.
@@ -387,36 +411,36 @@ class Komfortkasse_Order
387
  * @param string $refundIncrementId Increment ID of refund
388
  * @param string $status status
389
  * @param string $callbackid callback ID
390
- *
391
  * @return void
392
  */
393
  public static function updateRefund($refundIncrementId, $status, $callbackid)
394
  {
395
  $resource = Mage::getSingleton('core/resource');
396
  $id = $resource->getConnection('core_read')->fetchOne('SELECT `entity_id` FROM `' . $resource->getTableName('sales/creditmemo') . "` WHERE `increment_id` = '" . $refundIncrementId . "'");
397
-
398
  $creditMemo = Mage::getModel('sales/order_creditmemo')->load($id);
399
-
400
  $store_id = $creditMemo->getStoreId();
401
  $store_id_order = array ();
402
  $store_id_order ['store_id'] = $store_id;
403
-
404
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_update, $store_id_order)) {
405
  return;
406
  }
407
-
408
  if ($creditMemo->getTransactionId() == null) {
409
  $creditMemo->setTransactionId($callbackid);
410
  }
411
-
412
  $history = $creditMemo->addComment($status . ' [' . $callbackid . ']', false, false);
413
-
414
  $creditMemo->save();
415
-
416
  }
417
-
418
  // end updateRefund()
419
-
420
 
421
  /**
422
  * Call an object's save method
@@ -428,13 +452,13 @@ class Komfortkasse_Order
428
  private static function mysave($object)
429
  {
430
  $object->save();
431
-
432
  }
433
 
434
 
435
  public static function getInvoicePdfPrepare()
436
  {
437
-
438
  }
439
 
440
 
@@ -442,15 +466,15 @@ class Komfortkasse_Order
442
  {
443
  if ($invoiceNumber && $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceNumber)) {
444
  $fileName = $invoiceNumber . '.pdf';
445
-
446
  $pdfGenerated = false;
447
-
448
  // try easy pdf (www.easypdfinvoice.com)
449
  if (!$pdfGenerated) {
450
  $pdfProModel = Mage::getModel('pdfpro/order_invoice');
451
  if ($pdfProModel !== false) {
452
  $invoiceData = $pdfProModel->initInvoiceData($invoice);
453
- $result = Mage::helper('pdfpro')->initPdf(array ($invoiceData
454
  ));
455
  if ($result ['success']) {
456
  $content = $result ['content'];
@@ -458,16 +482,16 @@ class Komfortkasse_Order
458
  }
459
  }
460
  }
461
-
462
  // try Magento Standard
463
  if (!$pdfGenerated) {
464
- $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array ($invoice
465
  ));
466
  $content = $pdf->render();
467
  }
468
-
469
  return $content;
470
  }
471
-
472
  }
473
  }//end class
8
  * status: data type according to the shop system
9
  * delivery_ and billing_: _firstname, _lastname, _company, _street, _postcode, _city, _countrycode
10
  * products: an Array of item numbers
11
+ * @version 1.4.3.1-Magento1
12
  */
13
  $path = Mage::getModuleDir('', 'Ltc_Komfortkasse');
14
  $order_extension = false;
27
  public static function getOpenIDs()
28
  {
29
  $ret = array ();
30
+
31
  foreach (Mage::app()->getWebsites() as $website) {
32
  foreach ($website->getGroups() as $group) {
33
  $stores = $group->getStores();
34
  foreach ($stores as $store) {
35
+
36
  $store_id = $store->getId();
37
  $store_id_order = array ();
38
  $store_id_order ['store_id'] = $store_id;
39
+
40
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export, $store_id_order)) {
41
  continue;
42
  }
43
+
44
  // PREPAYMENT
45
+
46
  $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open, $store_id_order);
47
  $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $store_id_order);
48
+
49
  if (!empty($openOrders) && !empty($paymentMethods)) {
50
  $openOrders = explode(',', $openOrders);
51
  $paymentMethods = explode(',', $paymentMethods);
52
+
53
  $salesModel = Mage::getModel('sales/order');
54
+ $salesCollection = $salesModel->getCollection()->addAttributeToFilter('status', array ('in' => $openOrders
55
  ))->addFieldToFilter('store_id', $store_id);
56
+
57
  foreach ($salesCollection as $order) {
58
  try {
59
+ try {
60
+ $method = $order->getPayment()->getMethodInstance()->getCode();
61
+ } catch (Exception $e) {
62
+ // payment method has been deleted
63
+ $method = null;
64
+ }
65
+ if ($method && in_array($method, $paymentMethods, true) === true) {
66
  $orderId = $order->getIncrementId();
67
  $ret [] = $orderId;
68
  }
69
  } catch ( Exception $e ) {
70
  }
71
  }
72
+
73
  // Add all orders with unpaid invoices (in case the invoice is created before shipping).
74
  $invoiceModel = Mage::getModel('sales/order_invoice');
75
  $invoiceCollection = $invoiceModel->getCollection()->addAttributeToFilter('state', Mage_Sales_Model_Order_Invoice::STATE_OPEN)->addFieldToFilter('store_id', $store_id);
76
  foreach ($invoiceCollection as $invoice) {
77
  try {
78
  $order = $invoice->getOrder();
79
+ try {
80
+ $method = $order->getPayment()->getMethodInstance()->getCode();
81
+ } catch (Exception $e) {
82
+ // payment method has been deleted
83
+ $method = null;
84
+ }
85
+ if ($method && in_array($method, $paymentMethods, true) === true) {
86
  $orderId = $order->getIncrementId();
87
  if (in_array($orderId, $ret) === false) {
88
  $ret [] = $orderId;
92
  }
93
  }
94
  }
95
+
96
  // INVOICE
97
+
98
  $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open_invoice, $store_id_order);
99
  $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_invoice, $store_id_order);
100
+
101
  if (!empty($openOrders) && !empty($paymentMethods)) {
102
  $openOrders = explode(',', $openOrders);
103
  $paymentMethods = explode(',', $paymentMethods);
104
+
105
  $salesModel = Mage::getModel('sales/order');
106
+ $salesCollection = $salesModel->getCollection()->addAttributeToFilter('status', array ('in' => $openOrders
107
  ))->addFieldToFilter('store_id', $store_id);
108
+
109
  foreach ($salesCollection as $order) {
110
  try {
111
+ try {
112
+ $method = $order->getPayment()->getMethodInstance()->getCode();
113
+ } catch (Exception $e) {
114
+ // payment method has been deleted
115
+ $method = null;
116
+ }
117
+ if ($method && in_array($method, $paymentMethods, true) === true) {
118
  $orderId = $order->getIncrementId();
119
  $ret [] = $orderId;
120
  }
122
  }
123
  }
124
  }
125
+
126
  // COD
127
+
128
  $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open_cod, $store_id_order);
129
  $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_cod, $store_id_order);
130
+
131
  if (!empty($openOrders) && !empty($paymentMethods)) {
132
  $openOrders = explode(',', $openOrders);
133
  $paymentMethods = explode(',', $paymentMethods);
134
 
135
  $salesModel = Mage::getModel('sales/order');
136
+ $salesCollection = $salesModel->getCollection()->addAttributeToFilter('status', array ('in' => $openOrders
137
  ))->addFieldToFilter('store_id', $store_id);
138
+
139
  foreach ($salesCollection as $order) {
140
  try {
141
  $method = $order->getPayment()->getMethodInstance()->getCode();
142
+ } catch (Exception $e) {
143
+ // payment method has been deleted
144
+ $method = null;
145
+ }
146
+ if ($method && in_array($method, $paymentMethods, true) === true) {
147
+ $orderId = $order->getIncrementId();
148
+ $ret [] = $orderId;
149
  }
150
  }
151
  }
152
  }
153
  }
154
  }
155
+
156
 
157
  return $ret;
158
+
159
  }
160
+
161
  // end getOpenIDs()
162
+
163
 
164
  /**
165
  * Get refund IDS.
169
  public static function getRefundIDs()
170
  {
171
  $ret = array ();
172
+
173
  foreach (Mage::app()->getWebsites() as $website) {
174
  foreach ($website->getGroups() as $group) {
175
  $stores = $group->getStores();
176
  foreach ($stores as $store) {
177
+
178
  $store_id = $store->getId();
179
  $store_id_order = array ();
180
  $store_id_order ['store_id'] = $store_id;
181
+
182
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export, $store_id_order)) {
183
  continue;
184
  }
185
+
186
  $paymentMethods = explode(',', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $store_id_order));
187
+
188
  $cmModel = Mage::getModel("sales/order_creditmemo");
189
  $cmCollection = $cmModel->getCollection()->addFieldToFilter('store_id', $store_id);
190
+
191
  foreach ($cmCollection as $creditMemo) {
192
  if ($creditMemo->getTransactionId() == null) {
193
  $order = $creditMemo->getOrder();
194
+ try {
195
  $method = $order->getPayment()->getMethodInstance()->getCode();
196
+ } catch (Exception $e) {
197
+ // payment method has been deleted
198
+ $method = null;
199
+ }
200
+ if ($method && in_array($method, $paymentMethods, true) === true) {
201
  $cmId = $creditMemo->getIncrementId();
202
  $ret [] = $cmId;
203
  }
206
  }
207
  }
208
  }
209
+
210
  return $ret;
211
+
212
  }
213
+
214
  // end getRefundIDs()
215
+
216
 
217
  /**
218
  * Get order.
219
  *
220
  * @param string $number order number
221
+ *
222
  * @return array order
223
  */
224
  public static function getOrder($number)
227
  if (empty($number) === true || empty($order) === true || $number != $order->getIncrementId()) {
228
  return null;
229
  }
230
+
231
  $conf_general = Mage::getStoreConfig('general', $order->getStoreId());
232
+
233
  $ret = array ();
234
  $ret ['number'] = $order->getIncrementId();
235
  $ret ['status'] = $order->getStatus();
236
  $ret ['date'] = date('d.m.Y', strtotime($order->getCreatedAtStoreDate()->get(Zend_Date::DATE_MEDIUM)));
237
  $ret ['email'] = $order->getCustomerEmail();
238
  $ret ['customer_number'] = $order->getCustomerId();
239
+ try {
240
+ $ret ['payment_method'] = $order->getPayment()->getMethodInstance()->getCode();
241
+ } catch (Exception $e) { }
242
  $ret ['amount'] = $order->getGrandTotal();
243
  $ret ['currency_code'] = $order->getOrderCurrencyCode();
244
  $ret ['exchange_rate'] = $order->getBaseToOrderRate();
245
+
246
  // Rechnungsnummer und -datum
247
  $invoiceColl = $order->getInvoiceCollection();
248
  if ($invoiceColl->getSize() > 0) {
254
  }
255
  }
256
  }
257
+
258
  $shippingAddress = $order->getShippingAddress();
259
  if ($shippingAddress) {
260
  $ret ['delivery_firstname'] = utf8_encode($shippingAddress->getFirstname());
265
  $ret ['delivery_city'] = utf8_encode($shippingAddress->getCity());
266
  $ret ['delivery_countrycode'] = utf8_encode($shippingAddress->getCountryId());
267
  }
268
+
269
  $billingAddress = $order->getBillingAddress();
270
  if ($billingAddress) {
271
  $ret ['language_code'] = substr($conf_general ['locale'] ['code'], 0, 2) . '-' . $billingAddress->getCountryId();
279
  } else {
280
  $ret ['language_code'] = substr($conf_general ['locale'] ['code'], 0, 2);
281
  }
282
+
283
  foreach ($order->getAllItems() as $itemId => $item) {
284
  $sku = $item->getSku();
285
  if ($sku) {
288
  $ret ['products'] [] = $item->getName();
289
  }
290
  }
291
+
292
  $ret ['store_id'] = $order->getStoreId();
293
+
294
  if ($order_extension && method_exists('Komfortkasse_Order_Extension', 'extendOrder') === true) {
295
  $ret = Komfortkasse_Order_Extension::extendOrder($order, $ret);
296
  }
297
+
298
  return $ret;
299
+
300
  }
301
+
302
  // end getOrder()
303
+
304
 
305
  /**
306
  * Get refund.
307
  *
308
  * @param string $number refund number
309
+ *
310
  * @return array refund
311
  */
312
  public static function getRefund($number)
313
  {
314
  $resource = Mage::getSingleton('core/resource');
315
  $id = $resource->getConnection('core_read')->fetchOne('SELECT `entity_id` FROM `' . $resource->getTableName('sales/creditmemo') . "` WHERE `increment_id` = '" . $number . "'");
316
+
317
  $creditMemo = Mage::getModel('sales/order_creditmemo')->load($id);
318
  if (empty($number) === true || empty($creditMemo) === true || $number != $creditMemo->getIncrementId()) {
319
  return null;
320
  }
321
+
322
  $ret = array ();
323
  $ret ['number'] = $creditMemo->getOrder()->getIncrementId();
324
  // Number of the Creditmemo.
325
  $ret ['customer_number'] = $creditMemo->getIncrementId();
326
  $ret ['date'] = date('d.m.Y', strtotime($creditMemo->getCreatedAt()));
327
  $ret ['amount'] = $creditMemo->getGrandTotal();
328
+
329
  return $ret;
330
+
331
  }
332
+
333
  // end getRefund()
334
+
335
 
336
  /**
337
  * Update order.
339
  * @param array $order order
340
  * @param string $status status
341
  * @param string $callbackid callback ID
342
+ *
343
  * @return void
344
  */
345
  public static function updateOrder($order, $status, $callbackid)
347
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_update, $order)) {
348
  return;
349
  }
350
+
351
  // Hint: PAID and CANCELLED are supported as of now.
352
  $order = Mage::getModel('sales/order')->loadByIncrementId($order ['number']);
353
+
354
+ Mage::dispatchEvent('komfortkasse_change_order_status_before', array ('order' => $order,'status' => $status,'callbackid' => $callbackid
355
  ));
356
+
357
  $stateCollection = Mage::getModel('sales/order_status')->getCollection()->joinStates();
358
+ $stateCollection->addFieldToFilter('main_table.status', array ('like' => $status
359
  ));
360
  $state = $stateCollection->getFirstItem()->getState();
361
+
362
  if ($state == 'processing' || $state == 'closed' || $state == 'complete') {
363
+
364
  // If there is already an invoice, update the invoice, not the order.
365
  $invoiceColl = $order->getInvoiceCollection();
366
  if ($invoiceColl->getSize() > 0) {
372
  } else {
373
  $payment = $order->getPayment();
374
  $payment->capture(null);
375
+
376
  if ($callbackid) {
377
  $payment->setTransactionId($callbackid);
378
  $transaction = $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
379
  }
380
  }
381
+
382
  $history = $order->addStatusHistoryComment('' . $callbackid, $status);
383
  $order->save();
384
  } else if ($state == 'canceled') {
385
+
386
  if ($callbackid) {
387
  $history = $order->addStatusHistoryComment('' . $callbackid, $status);
388
  }
392
  $order->setStatus($status);
393
  $order->save();
394
  } else {
395
+
396
  $history = $order->addStatusHistoryComment('' . $callbackid, $status);
397
  $order->save();
398
  }
399
+
400
+ Mage::dispatchEvent('komfortkasse_change_order_status_after', array ('order' => $order,'status' => $status,'callbackid' => $callbackid
401
  ));
402
+
403
  }
404
+
405
  // end updateOrder()
406
+
407
 
408
  /**
409
  * Update order.
411
  * @param string $refundIncrementId Increment ID of refund
412
  * @param string $status status
413
  * @param string $callbackid callback ID
414
+ *
415
  * @return void
416
  */
417
  public static function updateRefund($refundIncrementId, $status, $callbackid)
418
  {
419
  $resource = Mage::getSingleton('core/resource');
420
  $id = $resource->getConnection('core_read')->fetchOne('SELECT `entity_id` FROM `' . $resource->getTableName('sales/creditmemo') . "` WHERE `increment_id` = '" . $refundIncrementId . "'");
421
+
422
  $creditMemo = Mage::getModel('sales/order_creditmemo')->load($id);
423
+
424
  $store_id = $creditMemo->getStoreId();
425
  $store_id_order = array ();
426
  $store_id_order ['store_id'] = $store_id;
427
+
428
  if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_update, $store_id_order)) {
429
  return;
430
  }
431
+
432
  if ($creditMemo->getTransactionId() == null) {
433
  $creditMemo->setTransactionId($callbackid);
434
  }
435
+
436
  $history = $creditMemo->addComment($status . ' [' . $callbackid . ']', false, false);
437
+
438
  $creditMemo->save();
439
+
440
  }
441
+
442
  // end updateRefund()
443
+
444
 
445
  /**
446
  * Call an object's save method
452
  private static function mysave($object)
453
  {
454
  $object->save();
455
+
456
  }
457
 
458
 
459
  public static function getInvoicePdfPrepare()
460
  {
461
+
462
  }
463
 
464
 
466
  {
467
  if ($invoiceNumber && $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceNumber)) {
468
  $fileName = $invoiceNumber . '.pdf';
469
+
470
  $pdfGenerated = false;
471
+
472
  // try easy pdf (www.easypdfinvoice.com)
473
  if (!$pdfGenerated) {
474
  $pdfProModel = Mage::getModel('pdfpro/order_invoice');
475
  if ($pdfProModel !== false) {
476
  $invoiceData = $pdfProModel->initInvoiceData($invoice);
477
+ $result = Mage::helper('pdfpro')->initPdf(array ($invoiceData
478
  ));
479
  if ($result ['success']) {
480
  $content = $result ['content'];
482
  }
483
  }
484
  }
485
+
486
  // try Magento Standard
487
  if (!$pdfGenerated) {
488
+ $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array ($invoice
489
  ));
490
  $content = $pdf->render();
491
  }
492
+
493
  return $content;
494
  }
495
+
496
  }
497
  }//end class
app/code/community/Ltc/Komfortkasse/etc/config.xml CHANGED
@@ -3,7 +3,7 @@
3
  <config>
4
  <modules>
5
  <Ltc_Komfortkasse>
6
- <version>1.4.3</version>
7
  </Ltc_Komfortkasse>
8
  </modules>
9
  <global>
3
  <config>
4
  <modules>
5
  <Ltc_Komfortkasse>
6
+ <version>1.4.3.1</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.3</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>Improved calculation of due date for payment by invoice</notes>
17
  <authors><author><name>Komfortkasse</name><user>komfortkasse</user><email>integration@komfortkasse.eu</email></author></authors>
18
- <date>2016-01-18</date>
19
- <time>06:21:00</time>
20
- <contents><target name="magecommunity"><dir name="Ltc"><dir name="Komfortkasse"><dir name="Helper"><file name="Data.php" hash="ec7f9f8fb6ea400a740ed2c127eb71bc"/><file name="Komfortkasse.php" hash="d3d748358e8c11cfa8e01fae56a66497"/><file name="Komfortkasse_Config.php" hash="44cf103f0ddef60890cd6c221262b7e5"/><file name="Komfortkasse_Order.php" hash="61f498878a1a84cf5ac87673db06a5a3"/></dir><dir name="Model"><file name="Observer.php" hash="2c12ce2b930cf734d8574e69156c7da8"/></dir><dir name="controllers"><file name="MainController.php" hash="b983fe60b2bbfa3aa1d57850cc6c045b"/></dir><dir name="etc"><file name="config.xml" hash="f90dd389f25824d5fec70787371d8fd8"/><file name="system.xml" hash="c069f07b4f846e62bc5dd922c81e375b"/></dir></dir></dir><dir name="Mage"><dir name="Adminhtml"><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><file name="KomfortkasseEncryptionOptions.php" hash="fea880dd3e60c13ede05be53511a6d93"/></dir></dir></dir></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.4.3.1</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>Bugfix for reading orders/refunds with payment methods that have been deleted</notes>
17
  <authors><author><name>Komfortkasse</name><user>komfortkasse</user><email>integration@komfortkasse.eu</email></author></authors>
18
+ <date>2016-02-12</date>
19
+ <time>07:14:20</time>
20
+ <contents><target name="magecommunity"><dir name="Ltc"><dir name="Komfortkasse"><dir name="Helper"><file name="Data.php" hash="ec7f9f8fb6ea400a740ed2c127eb71bc"/><file name="Komfortkasse.php" hash="cc3e97d27237c6a1967fd78c4d6f3d13"/><file name="Komfortkasse_Config.php" hash="44cf103f0ddef60890cd6c221262b7e5"/><file name="Komfortkasse_Order.php" hash="ebb6a385e8d02cfc34c287ce15953e84"/></dir><dir name="Model"><file name="Observer.php" hash="2c12ce2b930cf734d8574e69156c7da8"/></dir><dir name="controllers"><file name="MainController.php" hash="b983fe60b2bbfa3aa1d57850cc6c045b"/></dir><dir name="etc"><file name="config.xml" hash="2a1d5ae7d86c2b89fa3c6a16fc36e84f"/><file name="system.xml" hash="c069f07b4f846e62bc5dd922c81e375b"/></dir></dir></dir><dir name="Mage"><dir name="Adminhtml"><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><file name="KomfortkasseEncryptionOptions.php" hash="fea880dd3e60c13ede05be53511a6d93"/></dir></dir></dir></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>