Ltc_Komfortkasse - Version 1.2.2

Version Notes

Support for invoice numbers

Download this release

Release Info

Developer Komfortkasse
Extension Ltc_Komfortkasse
Version 1.2.2
Comparing to
See all releases


Version 1.2.2

app/code/community/Ltc/Komfortkasse/Helper/Data.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $path = Mage::getModuleDir('', 'Ltc_Komfortkasse');
4
+ 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
+
12
+
13
+ /**
14
+ * Init.
15
+ *
16
+ * @return void
17
+ */
18
+ public function init()
19
+ {
20
+ Komfortkasse::init();
21
+
22
+ }//end init()
23
+
24
+
25
+ /**
26
+ * Test.
27
+ *
28
+ * @return void
29
+ */
30
+ public function test()
31
+ {
32
+ Komfortkasse::test();
33
+
34
+ }//end test()
35
+
36
+
37
+ /**
38
+ * Read orders.
39
+ *
40
+ * @return void
41
+ */
42
+ public function readorders()
43
+ {
44
+ Komfortkasse::readorders();
45
+
46
+ }//end readorders()
47
+
48
+
49
+ /**
50
+ * Read refunds.
51
+ *
52
+ * @return void
53
+ */
54
+ public function readrefunds()
55
+ {
56
+ Komfortkasse::readrefunds();
57
+
58
+ }//end readrefunds()
59
+
60
+
61
+ /**
62
+ * Update orders.
63
+ *
64
+ * @return void
65
+ */
66
+ public function updateorders()
67
+ {
68
+ Komfortkasse::updateorders();
69
+
70
+ }//end updateorders()
71
+
72
+
73
+ /**
74
+ * Update refunds.
75
+ *
76
+ * @return void
77
+ */
78
+ public function updaterefunds()
79
+ {
80
+ Komfortkasse::updaterefunds();
81
+
82
+ }//end updaterefunds()
83
+
84
+
85
+ /**
86
+ * Info.
87
+ *
88
+ * @return void
89
+ */
90
+ public function info()
91
+ {
92
+ Komfortkasse::info();
93
+
94
+ }//end info()
95
+
96
+ /**
97
+ * Notify order.
98
+ *
99
+ * @return void
100
+ */
101
+ public function notifyorder($id)
102
+ {
103
+ Komfortkasse::notifyorder($id);
104
+
105
+ }//end notifyorder()
106
+
107
+
108
+
109
+
110
+ }//end class
app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse.php ADDED
@@ -0,0 +1,729 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once 'Komfortkasse_Config.php';
3
+ require_once 'Komfortkasse_Order.php';
4
+
5
+ /**
6
+ * Komfortkasse
7
+ * Main Class, multi-shop
8
+ */
9
+ class Komfortkasse
10
+ {
11
+ const PLUGIN_VER = '1.2.2';
12
+ const MAXLEN_SSL = 117;
13
+ const LEN_MCRYPT = 16;
14
+
15
+
16
+ /**
17
+ * Read orders.
18
+ *
19
+ * @return void
20
+ */
21
+ public static function readorders()
22
+ {
23
+ Komfortkasse::read(false);
24
+
25
+ }//end readorders()
26
+
27
+
28
+ /**
29
+ * Read refunds.
30
+ *
31
+ * @return void
32
+ */
33
+ public static function readrefunds()
34
+ {
35
+ Komfortkasse::read(true);
36
+
37
+ }//end readrefunds()
38
+
39
+
40
+ /**
41
+ * Read orders/refunds.
42
+ *
43
+ * @param bool $refunds if refunds should be read.
44
+ *
45
+ * @return void
46
+ */
47
+ public static function read($refunds)
48
+ {
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) {
64
+ $ids = Komfortkasse_Order::getRefundIDs();
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);
79
+ // Schritt 2: details pro auftrag ausgeben.
80
+ if ($refunds === true) {
81
+ $order = Komfortkasse_Order::getRefund($id);
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?') {
214
+ Komfortkasse::output('ok');
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) {
222
+ Komfortkasse::output($encrypt);
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)
262
+ {
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 {
303
+ $order = Komfortkasse_Order::getOrder($id);
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)
342
+ {
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()
390
+ {
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);
463
+ }
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);
493
+ }
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)
518
+ {
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
+ }
app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse_Config.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Komfortkasse
5
+ * Config Class
6
+ * @version 1.2.1.8-Magento */
7
+ class Komfortkasse_Config
8
+ {
9
+ const activate_export = 'payment/komfortkasse/activate_export';
10
+ const activate_update = 'payment/komfortkasse/activate_update';
11
+ const payment_methods = 'payment/komfortkasse/payment_methods';
12
+ const status_open = 'payment/komfortkasse/status_open';
13
+ const status_paid = 'payment/komfortkasse/status_paid';
14
+ const status_cancelled = 'payment/komfortkasse/status_cancelled';
15
+ const encryption = 'payment/komfortkasse/encryption';
16
+ const accesscode = 'payment/komfortkasse/accesscode';
17
+ const apikey = 'payment/komfortkasse/apikey';
18
+ const publickey = 'payment/komfortkasse/publickey';
19
+ const privatekey = 'payment/komfortkasse/privatekey';
20
+
21
+
22
+ /**
23
+ * Set Config.
24
+ *
25
+ * @param string $constantKey Constant Key
26
+ * @param string $value Value
27
+ *
28
+ * @return void
29
+ */
30
+ public static function setConfig($constantKey, $value)
31
+ {
32
+ Mage::getConfig()->saveConfig($constantKey, $value);
33
+ Mage::getConfig()->reinit();
34
+ Mage::app()->reinitStores();
35
+
36
+ }//end setConfig()
37
+
38
+
39
+ /**
40
+ * Get Config.
41
+ *
42
+ * @param string $constantKey Constant Key
43
+ *
44
+ * @return mixed
45
+ */
46
+ public static function getConfig($constantKey)
47
+ {
48
+ $value = Mage::getStoreConfig($constantKey);
49
+
50
+ return $value;
51
+
52
+ }//end getConfig()
53
+
54
+
55
+ /**
56
+ * Get Request Parameter.
57
+ *
58
+ * @param string $key Key
59
+ *
60
+ * @return string
61
+ */
62
+ public static function getRequestParameter($key)
63
+ {
64
+ return urldecode(Mage::app()->getRequest()->getParam($key));
65
+
66
+ }//end getRequestParameter()
67
+
68
+
69
+ /**
70
+ * Get Magento Version.
71
+ *
72
+ * @return string
73
+ */
74
+ public static function getVersion()
75
+ {
76
+ return Mage::getVersion();
77
+
78
+ }//end getVersion()
79
+
80
+
81
+ }//end class
app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse_Order.php ADDED
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ /**
5
+ * Komfortkasse Order Class
6
+ * in KK, an Order is an Array providing the following members:
7
+ * number, date, email, customer_number, payment_method, amount, currency_code, exchange_rate, language_code, invoice_number
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.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
+ {
105
+ $order = Mage::getModel('sales/order')->loadByIncrementId($number);
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) {
221
+ foreach ($order->getInvoiceCollection() as $invoice) {
222
+ $invoice->pay();
223
+ $invoice->addComment($callbackid, false, false);
224
+ self::mysave($invoice);
225
+ }
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
app/code/community/Ltc/Komfortkasse/Model/Observer.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Komfortkasse
5
+ * Magento Plugin - Observer Class
6
+ *
7
+ * @version 1.2.1.8-Magento */
8
+ class Ltc_Komfortkasse_Model_Observer
9
+ {
10
+
11
+
12
+ /**
13
+ * getRegName
14
+ *
15
+ * @param Varien_Event_Observer $observer Observer
16
+ *
17
+ * @return string
18
+ */
19
+ private function getRegName(Varien_Event_Observer $observer)
20
+ {
21
+ $id = $observer->getOrder()->getIncrementId();
22
+ if ($id) {
23
+ $regName = 'komfortkasse_order_status_'.$id;
24
+ return $regName;
25
+ }
26
+
27
+ }//end getRegName()
28
+
29
+
30
+ /**
31
+ * noteNewOrder
32
+ *
33
+ * @param Varien_Event_Observer $observer Observer
34
+ *
35
+ * @return void
36
+ */
37
+ public function noteNewOrder(Varien_Event_Observer $observer)
38
+ {
39
+ $regName = self::getRegName($observer);
40
+ if ($regName) {
41
+ Mage::register($regName, '_new');
42
+ }
43
+
44
+ }//end noteNewOrder()
45
+
46
+
47
+ /**
48
+ * noteOrderStatus
49
+ *
50
+ * @param Varien_Event_Observer $observer Observer
51
+ *
52
+ * @return void
53
+ */
54
+ public function noteOrderStatus(Varien_Event_Observer $observer)
55
+ {
56
+ $regName = self::getRegName($observer);
57
+ if ($regName && !Mage::registry($regName)) {
58
+ Mage::register($regName, $observer->getOrder()->getStatus());
59
+ }
60
+
61
+ }//end noteOrderStatus()
62
+
63
+
64
+ /**
65
+ * checkOrderStatus
66
+ *
67
+ * @param Varien_Event_Observer $observer Observer
68
+ *
69
+ * @return void
70
+ */
71
+ public function checkOrderStatus(Varien_Event_Observer $observer)
72
+ {
73
+ $regName = self::getRegName($observer);
74
+ $orderStatus = Mage::registry($regName);
75
+ if ($regName && $orderStatus) {
76
+ if ($orderStatus != $observer->getOrder()->getStatus()) {
77
+ $helper = Mage::helper('Ltc_Komfortkasse');
78
+ $helper->notifyorder($observer->getOrder()->getIncrementId());
79
+ }
80
+
81
+ Mage::unregister($regName);
82
+ }
83
+
84
+ }//end checkOrderStatus()
85
+
86
+
87
+ }//end class
app/code/community/Ltc/Komfortkasse/controllers/MainController.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
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
+
app/code/community/Ltc/Komfortkasse/etc/config.xml ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!-- Komfortkasse Magento Plugin - config.xml -->
3
+ <config>
4
+ <modules>
5
+ <Ltc_Komfortkasse>
6
+ <version>1.2.2</version>
7
+ </Ltc_Komfortkasse>
8
+ </modules>
9
+ <global>
10
+ <helpers>
11
+ <Ltc_Komfortkasse>
12
+ <class>Ltc_Komfortkasse_Helper</class>
13
+ </Ltc_Komfortkasse>
14
+ </helpers>
15
+ <models>
16
+ <Ltc_Komfortkasse>
17
+ <class>Ltc_Komfortkasse_Model</class>
18
+ </Ltc_Komfortkasse>
19
+ </models>
20
+ <events>
21
+ <sales_order_place_after>
22
+ <observers>
23
+ <Ltc_Komfortkasse>
24
+ <class>Ltc_Komfortkasse/observer</class>
25
+ <method>noteNewOrder</method>
26
+ </Ltc_Komfortkasse>
27
+ </observers>
28
+ </sales_order_place_after>
29
+ <sales_order_load_after>
30
+ <observers>
31
+ <Ltc_Komfortkasse>
32
+ <class>Ltc_Komfortkasse/observer</class>
33
+ <method>noteOrderStatus</method>
34
+ </Ltc_Komfortkasse>
35
+ </observers>
36
+ </sales_order_load_after>
37
+ <sales_order_save_after>
38
+ <observers>
39
+ <Ltc_Komfortkasse>
40
+ <class>Ltc_Komfortkasse/observer</class>
41
+ <method>checkOrderStatus</method>
42
+ </Ltc_Komfortkasse>
43
+ </observers>
44
+ </sales_order_save_after>
45
+ <komfortkasse_change_order_status_before>
46
+ </komfortkasse_change_order_status_before>
47
+ <komfortkasse_change_order_status_after>
48
+ </komfortkasse_change_order_status_after>
49
+ </events>
50
+ </global>
51
+ <default>
52
+ <payment>
53
+ <komfortkasse>
54
+ <activate_export>1</activate_export>
55
+ <activate_update>1</activate_update>
56
+ <payment_methods>banktransfer</payment_methods>
57
+ <status_open>pending</status_open>
58
+ <status_paid>processing</status_paid>
59
+ <status_cancelled>canceled</status_cancelled>
60
+ </komfortkasse>
61
+ </payment>
62
+ </default>
63
+ <frontend>
64
+ <routers>
65
+ <Ltc_Komfortkasse>
66
+ <use>standard</use>
67
+ <args>
68
+ <module>Ltc_Komfortkasse</module>
69
+ <frontName>komfortkasse</frontName>
70
+ </args>
71
+ </Ltc_Komfortkasse>
72
+ </routers>
73
+ </frontend>
74
+ </config>
app/code/community/Ltc/Komfortkasse/etc/system.xml ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ Komfortkasse
4
+ Magento Plugin - system.xml
5
+ @version 1.2.1.9-Magento */ -->
6
+ <config>
7
+ <sections>
8
+ <payment>
9
+ <groups>
10
+ <komfortkasse translate="label">
11
+ <label>Komfortkasse</label>
12
+ <frontend_type>text</frontend_type>
13
+ <sort_order>900</sort_order>
14
+ <show_in_default>1</show_in_default>
15
+ <show_in_website>1</show_in_website>
16
+ <show_in_store>1</show_in_store>
17
+ <fields>
18
+ <activate_export translate="label">
19
+ <label>Export Orders</label>
20
+ <frontend_type>select</frontend_type>
21
+ <source_model>adminhtml/system_config_source_enabledisable
22
+ </source_model>
23
+ <sort_order>10</sort_order>
24
+ <show_in_default>1</show_in_default>
25
+ <show_in_website>1</show_in_website>
26
+ <show_in_store>1</show_in_store>
27
+ <comment>Activate export of orders</comment>
28
+ </activate_export>
29
+ <activate_update translate="label">
30
+ <label>Update Orders</label>
31
+ <frontend_type>select</frontend_type>
32
+ <source_model>adminhtml/system_config_source_enabledisable
33
+ </source_model>
34
+ <sort_order>20</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ <comment>Activate update of orders</comment>
39
+ </activate_update>
40
+ <payment_methods translate="label">
41
+ <label>Payment Methods</label>
42
+ <frontend_type>multiselect</frontend_type>
43
+ <source_model>adminhtml/system_config_source_payment_allmethods
44
+ </source_model>
45
+ <sort_order>30</sort_order>
46
+ <show_in_default>1</show_in_default>
47
+ <show_in_website>1</show_in_website>
48
+ <show_in_store>1</show_in_store>
49
+ <comment>All payment methods that should be exported.
50
+ </comment>
51
+ </payment_methods>
52
+ <status_open translate="label">
53
+ <label>Statuses Open</label>
54
+ <frontend_type>multiselect</frontend_type>
55
+ <source_model>adminhtml/system_config_source_order_status
56
+ </source_model>
57
+ <sort_order>40</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>1</show_in_website>
60
+ <show_in_store>1</show_in_store>
61
+ <comment>Order statuses that should be exported (open
62
+ orders)
63
+ </comment>
64
+ </status_open>
65
+ <status_paid translate="label">
66
+ <label>Status Paid</label>
67
+ <frontend_type>select</frontend_type>
68
+ <source_model>adminhtml/system_config_source_order_status
69
+ </source_model>
70
+ <sort_order>50</sort_order>
71
+ <show_in_default>1</show_in_default>
72
+ <show_in_website>1</show_in_website>
73
+ <show_in_store>1</show_in_store>
74
+ <comment>Order state that should be set when a payment has
75
+ been
76
+ received.
77
+ </comment>
78
+ </status_paid>
79
+ <status_cancelled translate="label">
80
+ <label>Status Cancelled</label>
81
+ <frontend_type>select</frontend_type>
82
+ <source_model>adminhtml/system_config_source_order_status
83
+ </source_model>
84
+ <sort_order>55</sort_order>
85
+ <show_in_default>1</show_in_default>
86
+ <show_in_website>1</show_in_website>
87
+ <show_in_store>1</show_in_store>
88
+ <comment>Order state that should be set when an order has been cancelled.
89
+ </comment>
90
+ </status_cancelled>
91
+ <encryption translate="label">
92
+ <label>Encryption</label>
93
+ <frontend_type>select</frontend_type>
94
+ <source_model>adminhtml/system_config_source_KomfortkasseEncryptionOptions
95
+ </source_model>
96
+ <sort_order>60</sort_order>
97
+ <show_in_default>1</show_in_default>
98
+ <show_in_website>1</show_in_website>
99
+ <show_in_store>1</show_in_store>
100
+ <comment>Encryption technology</comment>
101
+ </encryption>
102
+ <accesscode translate="label">
103
+ <label>Access code</label>
104
+ <frontend_type>text</frontend_type>
105
+ <sort_order>65</sort_order>
106
+ <show_in_default>1</show_in_default>
107
+ <show_in_website>1</show_in_website>
108
+ <show_in_store>1</show_in_store>
109
+ <comment>Encrypted access code. Do not change!</comment>
110
+ </accesscode>
111
+ <apikey translate="label">
112
+ <label>API key</label>
113
+ <frontend_type>text</frontend_type>
114
+ <sort_order>67</sort_order>
115
+ <show_in_default>1</show_in_default>
116
+ <show_in_website>1</show_in_website>
117
+ <show_in_store>1</show_in_store>
118
+ <comment>API key. Do not change!</comment>
119
+ </apikey>
120
+ <publickey translate="label">
121
+ <label>Secret Key 1</label>
122
+ <frontend_type>text</frontend_type>
123
+ <sort_order>70</sort_order>
124
+ <show_in_default>1</show_in_default>
125
+ <show_in_website>1</show_in_website>
126
+ <show_in_store>1</show_in_store>
127
+ <comment>Key for encrypting/decrypting data. Do not change!</comment>
128
+ </publickey>
129
+ <privatekey translate="label">
130
+ <label>Secret Key 2</label>
131
+ <frontend_type>text</frontend_type>
132
+ <sort_order>80</sort_order>
133
+ <show_in_default>1</show_in_default>
134
+ <show_in_website>1</show_in_website>
135
+ <show_in_store>1</show_in_store>
136
+ <comment>Key for encrypting/decrypting data. Do not change!</comment>
137
+ <disabled>true</disabled>
138
+ </privatekey>
139
+ </fields>
140
+ </komfortkasse>
141
+ </groups>
142
+ </payment>
143
+ </sections>
144
+ </config>
app/code/community/Mage/Adminhtml/Model/System/Config/Source/KomfortkasseEncryptionOptions.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mage_Adminhtml_Model_System_Config_Source_KomfortkasseEncryptionOptions
3
+ {
4
+
5
+ /**
6
+ * Options getter
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ return array(
13
+ array('value' => "openssl", 'label'=>Mage::helper('adminhtml')->__('OpenSSL Encryption (asynchronous)')),
14
+ array('value' => "mcrypt", 'label'=>Mage::helper('adminhtml')->__('MCrypt Encryption (synchronous)')),
15
+ array('value' => "base64", 'label'=>Mage::helper('adminhtml')->__('Base64 Encoding')),
16
+ );
17
+ }
18
+
19
+ }
app/etc/modules/Ltc_Komfortkasse.xml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ Komfortkasse
4
+ Magento Plugin - plugin xml file
5
+ -->
6
+ <config>
7
+ <modules>
8
+ <Ltc_Komfortkasse>
9
+ <active>true</active>
10
+ <codePool>community</codePool>
11
+ <version>1.2</version>
12
+ </Ltc_Komfortkasse>
13
+ </modules>
14
+ </config>
package.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>
8
+ <extends/>
9
+ <summary>Automatischer Zahlungsabgleich von Vorkasse-Zahlungen mit Komfortkasse</summary>
10
+ <description>Mit Komfortkasse werden Bank&#xFC;berweisungen vom Bankkonto abgerufen und automatisch den offenen Bestellungen zugeordnet. Die Zuordnung erfolgt vollautomatisch im Hintergrund und ist fehlertolerant, d.h. es k&#xF6;nnen auch Bestellungen zugeordnet werden wenn der Name nicht &#xFC;bereinstimmt, die Bestellnummer nicht angegeben wurde oder der Betrag abweicht.&#xD;
11
+ &#xD;
12
+ Zus&#xE4;tzlich k&#xF6;nnen automatische Zahlungserinnerungen versendet werden und R&#xFC;ckbuchungen direkt, ohne Einstieg ins Online-Banking, durchgef&#xFC;hrt werden. &#xD;
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>