Ltc_Komfortkasse - Version 1.2.3

Version Notes

Improvements for invoice support

Download this release

Release Info

Developer Komfortkasse
Extension Ltc_Komfortkasse
Version 1.2.3
Comparing to
See all releases


Code changes from version 1.2.2 to 1.2.3

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