updateAction()   F
last analyzed

Complexity

Conditions 18
Paths 6716

Size

Total Lines 113
Code Lines 82

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 18
eloc 82
nc 6716
nop 0
dl 0
loc 113
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
use Shopware\Bundle\AttributeBundle\Service\DataLoader;
3
use Shopware\Models\Order\Order;
4
use Shopware\Components\CSRFWhitelistAware;
5
6
/**
7
 * Klarna payment controller
8
 */
9
class Shopware_Controllers_Backend_PaymentKlarna extends Enlight_Controller_Action implements CSRFWhitelistAware
10
{
11
    /**
12
     * @var Shopware_Plugins_Frontend_SwagPaymentKlarna_Bootstrap
13
     */
14
    private $plugin;
15
16
    /**
17
     * @var Enlight_Config
18
     */
19
    private $config;
20
21
    /**
22
     * @var Shopware\Components\Model\ModelManager
23
     */
24
    private $modelManager;
25
26
    /**
27
     * @var Shopware\Models\Order\Repository
28
     */
29
    private $orderRepository;
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function preDispatch()
35
    {
36
        $this->plugin = $this->get('plugins')->Frontend()->SwagPaymentKlarna();
37
        $this->config = $this->plugin->Config();
38
        $this->modelManager = $this->get('models');
39
        $this->orderRepository = $this->modelManager->getRepository('Shopware\Models\Order\Order');
40
41
        $this->Front()->Plugins()->Json()->setRenderer();
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 View Code Duplication
    public function get($name)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        if (version_compare(Shopware::VERSION, '4.2.0', '<') && Shopware::VERSION != '___VERSION___') {
50
            if ($name == 'pluginlogger') {
51
                $name = 'log';
52
            }
53
            $name = ucfirst($name);
54
            return Shopware()->Bootstrap()->getResource($name);
55
        }
56
        return parent::get($name);
57
    }
58
59
    /**
60
     * @return \Doctrine\ORM\Query
61
     */
62
    protected function getOrderByIdQuery()
63
    {
64
        $builder = $this->orderRepository->createQueryBuilder('o');
65
        $builder->addSelect([
66
            'details',
67
            'customer',
68
            'documents',
69
            'attribute',
70
            'detailsAttribute'
71
        ]);
72
        $builder->leftJoin('o.details', 'details')
73
            ->leftJoin('details.attribute', 'detailsAttribute')
74
            ->leftJoin('o.customer', 'customer')
75
            ->leftJoin('o.documents', 'documents')
76
            ->leftJoin('o.attribute', 'attribute');
77
        $builder->where('o.id = :orderId');
78
        $query = $builder->getQuery();
79
        return $query;
80
    }
81
82
    /**
83
     * @param $orderId
84
     * @return Shopware\Models\Order\Order
85
     */
86
    protected function getOrderById($orderId)
87
    {
88
        $query = $this->getOrderByIdQuery();
89
        $query->setParameter('orderId', $orderId);
90
        return $query->getOneOrNullResult();
91
    }
92
93
    /**
94
     * @param $orderId
95
     * @return \Shopware\Models\Shop\DetachedShop
96
     * @throws Exception
97
     */
98
    protected function registerShopByOrderId($orderId)
99
    {
100
        $repository = $this->modelManager->getRepository('Shopware\Models\Shop\Shop');
101
102
        $order = $this->orderRepository->find($orderId);
103
        if ($order === null) {
104
            throw new \Exception("Order {$orderId} not found");
105
        }
106
        $shopId = $order->getLanguageIso();
107
        if ($shopId === null) {
108
            $shop = $repository->getActiveDefault();
109
        } else {
110
            $shop = $repository->getActiveById($shopId);
111
        }
112
        if ($shop === null) {
113
            throw new \Exception("Shop {$shopId} not found");
114
        }
115
        $shop->registerResources(Shopware()->Bootstrap());
116
        $this->modelManager->clear();
117
        return $shop;
118
    }
119
120
    private function getOrderPaymentStatus($statusType)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
121
    {
122
        $paymentStatus = $this->plugin->Config()->get($statusType);
123
        if (!empty($paymentStatus)) {
124
            return $this->modelManager->find('\Shopware\Models\Order\Status', $paymentStatus);
125
        } else {
126
            return null;
127
        }
128
    }
129
130
    public function activateAction()
131
    {
132
        $orderId = $this->Request()->getParam('orderId');
133
        $positions = $this->Request()->getParam('positions', []);
134
        $this->registerShopByOrderId($orderId);
135
        $order = $this->getOrderById($orderId);
136
        $service = $this->getService($order);
137
        $detailStatus = $this->modelManager->find('\Shopware\Models\Order\DetailStatus', 3);
138
        $paymentStatus = $this->getOrderPaymentStatus('activateStatusId');
139
140
        /** @var Shopware\Models\Order\Detail $position */
141
        foreach ($order->getDetails() as $position) {
142
            if (empty($positions)) {
143
                $selection = $position->getQuantity() - $position->getShipped();
144
                if (!empty($selection)) {
145
                    $position->setShipped($position->getShipped() + $selection);
146
                    $position->setStatus($detailStatus);
147
                }
148
            } elseif (!empty($positions[$position->getId()])) {
149
                $quantity = $position->getQuantity() - $position->getShipped();
150
                $selection = min($positions[$position->getId()], $quantity);
151
                if (!empty($selection)) {
152
                    $service->addArtNo($selection, $position->getArticleNumber());
153
                    $position->setShipped($position->getShipped() + $selection);
154
                    if ($selection == $quantity) {
155
                        $position->setStatus($detailStatus);
156
                    }
157
                }
158
            }
159
        }
160
161
        try {
162
            $result = $service->activate($order->getTransactionId());
163
            if (!empty($result[1])) {
164
                $last = true;
165
                foreach ($order->getDetails() as $position) {
166
                    if ((empty($positions) || !empty($positions[$position->getId()]))) {
167
                        /** @noinspection PhpUndefinedMethodInspection */
168
                        if ($position->getAttribute()->getSwagKlarnaInvoiceNumber() === null) {
169
                            /** @noinspection PhpUndefinedMethodInspection */
170
                            $position->getAttribute()->setSwagKlarnaInvoiceNumber(
171
                                $result[1]
172
                            );
173
                        }
174
                    } elseif ($position->getStatus()->getId() == 0) {
175
                        $last = false;
176
                    }
177
                }
178
                /** @noinspection PhpUndefinedMethodInspection */
179
                $order->getAttribute()->setSwagKlarnaInvoiceNumber(
180
                    $result[1]
181
                );
182
183
                if (empty($positions) || $last) {
184
                    $order->setClearedDate(new DateTime());
185
                    /** @noinspection PhpUndefinedMethodInspection */
186
                    $order->getAttribute()->setSwagKlarnaStatus(
187
                        'activate'
188
                    );
189
                    if ($paymentStatus !== null) {
190
                        $order->setPaymentStatus($paymentStatus);
191
                    }
192
                }
193
                $this->modelManager->flush();
194
                $this->View()->assign([
195
                    'success' => true,
196
                    'number' => $result[1]
197
                ]);
198
            } else {
199
                $this->View()->assign([
200
                    'success' => false,
201
                    'status' => $result[0]
202
                ]);
203
            }
204
        } catch (Exception $e) {
205
            $this->View()->assign([
206
                'success' => false,
207
                'message' => $e->getMessage()
208
            ]);
209
        }
210
    }
211
212
    public function creditAction()
213
    {
214
        $orderId = $this->Request()->getParam('orderId');
215
        $this->registerShopByOrderId($orderId);
216
        $order = $this->getOrderById($orderId);
217
218
        $service = $this->getService($order);
219
        $status = $this->modelManager->find('\Shopware\Models\Order\DetailStatus', 2);
220
221
        try {
222
            /** @noinspection PhpUndefinedMethodInspection */
223
            $invoices = [
224
                $order->getAttribute()->getSwagKlarnaInvoiceNumber()
225
            ];
226
            /** @var Shopware\Models\Order\Detail $position */
227
            foreach ($order->getDetails() as $position) {
228
                /** @noinspection PhpUndefinedMethodInspection */
229
                if ($position->getAttribute()->getSwagKlarnaInvoiceNumber() !== null) {
230
                    /** @noinspection PhpUndefinedMethodInspection */
231
                    $invoices[] = $position->getAttribute()->getSwagKlarnaInvoiceNumber();
232
                }
233
                $position->setStatus($status);
234
            }
235
            $result = [];
236
            foreach (array_unique($invoices) as $invoice) {
237
                $result[] = $service->creditInvoice($invoice);
238
            }
239
            /** @noinspection PhpUndefinedMethodInspection */
240
            $order->getAttribute()->setSwagKlarnaStatus(
241
                'credit'
242
            );
243
            $this->modelManager->flush();
244
            $this->View()->assign([
245
                'success' => !empty($result),
246
                'number' => $result
247
            ]);
248
        } catch (Exception $e) {
249
            $this->View()->assign([
250
                'success' => false,
251
                'message' => $e->getMessage()
252
            ]);
253
        }
254
    }
255
256
    public function cancelAction()
257
    {
258
        $orderId = $this->Request()->getParam('orderId');
259
        $this->registerShopByOrderId($orderId);
260
        $order = $this->getOrderById($orderId);
261
        $service = $this->getService($order);
262
        $detailStatus = $this->modelManager->find('\Shopware\Models\Order\DetailStatus', 2);
263
        $paymentStatus = $this->getOrderPaymentStatus('cancelStatusId');
264
265
        try {
266
            /** @var Shopware\Models\Order\Detail $position */
267
            foreach ($order->getDetails() as $position) {
268
                if (!$position->getStatus()->getId()) {
269
                    $position->setStatus($detailStatus);
270
                }
271
            }
272
            $result = $service->cancelReservation(
273
                $order->getTransactionId()
274
            );
275
            if ($paymentStatus !== null) {
276
                $order->setPaymentStatus($paymentStatus);
277
            }
278
            /** @noinspection PhpUndefinedMethodInspection */
279
            $order->getAttribute()->setSwagKlarnaStatus(
280
                'cancel'
281
            );
282
            $this->modelManager->flush();
283
            $this->View()->assign([
284
                'success' => $result
285
            ]);
286
        } catch (Exception $e) {
287
            $this->View()->assign([
288
                'success' => false,
289
                'message' => $e->getMessage()
290
            ]);
291
        }
292
    }
293
294
    public function refundAction()
295
    {
296
        $orderId = $this->Request()->getParam('orderId');
297
        $this->registerShopByOrderId($orderId);
298
        $order = $this->getOrderById($orderId);
299
        $service = $this->getService($order);
300
        $status = $this->modelManager->find('\Shopware\Models\Order\DetailStatus', 2);
301
        $positions = $this->Request()->getParam('positions', []);
302
303
        try {
304
            $invoices = [];
305
            /** @var Shopware\Models\Order\Detail $position */
306
            foreach ($order->getDetails() as $position) {
307
                if (!empty($positions[$position->getId()])) {
308
                    /** @noinspection PhpUndefinedMethodInspection */
309
                    $invoiceNumber = $position->getAttribute()->getSwagKlarnaInvoiceNumber();
310
                    $selection = min($positions[$position->getId()], $position->getShipped());
311
                    if ($invoiceNumber !== null && !empty($selection)) {
312
                        $invoices[$invoiceNumber][$position->getArticleNumber()] = $selection;
313
                        $position->setStatus($status);
314
                        $position->setShipped($position->getShipped() - $selection);
315
                    }
316
                }
317
            }
318
            $result = [];
319
            foreach ($invoices as $invoiceNumber => $articles) {
320
                foreach ($articles as $articleNumber => $quantity) {
321
                    $service->addArtNo($quantity, $articleNumber);
322
                }
323
                $result[] = $service->creditPart($invoiceNumber);
324
            }
325
            $this->modelManager->flush();
326
            $this->View()->assign([
327
                'success' => true,
328
                'number' => $result
329
            ]);
330
        } catch (Exception $e) {
331
            $this->View()->assign([
332
                'success' => false,
333
                'message' => $e->getMessage()
334
            ]);
335
        }
336
    }
337
338
    public function updateAction()
339
    {
340
        $orderId = $this->Request()->getParam('orderId');
341
        $this->registerShopByOrderId($orderId);
342
        $order = $this->getOrderById($orderId);
343
        $orderAmount = 0;
344
        $orderAmountNet = 0;
345
346
        $service = $this->getService($order);
347
        $status = $this->modelManager->find('\Shopware\Models\Order\DetailStatus', 0);
348
        $positions = $this->Request()->getParam('positions', []);
349
        if (is_string($positions)) {
350
            $positions = json_decode($positions, true);
351
        }
352
        $newPositions = [];
353
354
        try {
355
            if ($order->getInvoiceShipping() > 0) {
356
                $invoiceShippingNet = $order->getInvoiceShippingNet();
357
                $taxRate = round(($order->getInvoiceShipping() - $invoiceShippingNet) / $invoiceShippingNet * 100, 2);
358
                $service->addArticle(
359
                    1,
360
                    'SHIPPING',
361
                    'Shipping Fee',
362
                    $order->getInvoiceShipping(),
363
                    $taxRate,
364
                    0,
365
                    KlarnaFlags::INC_VAT | KlarnaFlags::IS_SHIPMENT
366
                );
367
            }
368
369
            if (!empty($positions)) {
370
                foreach ($positions as $positionData) {
371
                    if (empty($positionData['price'])) {
372
                        $positionData = $this->getPriceData($positionData);
373
                    }
374
                    $position = null;
375
                    if (!empty($positionData['id'])) {
376
                        /** @var \Shopware\Models\Order\Detail $testPosition */
377
                        foreach ($order->getDetails() as $testPosition) {
378
                            if ($testPosition->getId() == $positionData['id']) {
379
                                $position = $testPosition;
380
                                break;
381
                            }
382
                        }
383
                    }
384
                    if ($position === null) {
385
                        $position = new Shopware\Models\Order\Detail();
386
                        $position->fromArray([
387
                            'order' => $order,
388
                            'number' => $order->getNumber(),
389
                            'status' => $status,
390
                            'attribute' => ['attribute1' => '']
391
                        ]);
392
                    }
393
                    if (!empty($positionData['taxId'])
394
                        && ($position->getTax() === null || $position->getTax()->getId() != $positionData['taxId'])
395
                    ) {
396
                        /** @var \Shopware\Models\Tax\Tax $tax */
397
                        $tax = $this->modelManager->find('\Shopware\Models\Tax\Tax', $positionData['taxId']);
398
                        $position->setTax($tax);
399
                        $positionData['taxRate'] = $tax->getTax();
400
                    }
401
                    $position->fromArray([
402
                        'taxRate' => $positionData['taxRate'],
403
                        'articleId' => $positionData['articleId'],
404
                        'articleNumber' => $positionData['articleNumber'],
405
                        'articleName' => $positionData['articleName'],
406
                        'price' => $positionData['price'],
407
                        'quantity' => $positionData['quantity']
408
                    ]);
409
                    $newPositions[] = $position;
410
                    $orderAmount =  $orderAmount + ($positionData['price'] * $positionData['quantity']);
411
                    $orderAmountNet = $orderAmountNet + ($positionData['price'] / (1+ (0.01 * $positionData['taxRate'] * $positionData['quantity'])));
412
                }
413
                $order->setDetails($newPositions);
414
            }
415
416
            /** @var Shopware\Models\Order\Detail $position */
417
            foreach ($order->getDetails() as $position) {
418
                $flags = KlarnaFlags::INC_VAT;
419
                if ($position->getMode() != 0 && $position->getPrice() > 0) {
420
                    $flags |= KlarnaFlags::IS_HANDLING;
421
                } elseif ($position->getArticleNumber() == 'SHIPPING') {
422
                    $flags |= KlarnaFlags::IS_SHIPMENT;
423
                }
424
                $articleName = utf8_decode($position->getArticleName());
425
426
                $service->addArticle(
427
                    $position->getQuantity(),
428
                    $position->getArticleNumber(),
429
                    $articleName,
430
                    $position->getPrice(),
431
                    $position->getTaxRate(),
432
                    0,
433
                    $flags
434
                );
435
            }
436
437
            $service->update($order->getTransactionId());
438
            $order->setInvoiceAmount($orderAmount);
439
            $order->setInvoiceAmountNet($orderAmountNet);
440
            $this->modelManager->flush();
441
            $this->View()->assign([
442
                'success' => true
443
            ]);
444
        } catch (Exception $e) {
445
            $this->View()->assign([
446
                'success' => false,
447
                'message' => $e->getMessage()
448
            ]);
449
        }
450
    }
451
452
    public function discountAction()
453
    {
454
        $orderId = $this->Request()->getParam('orderId');
455
        $this->registerShopByOrderId($orderId);
456
        $order = $this->getOrderById($orderId);
457
        $value = (float)str_replace(',', '.', $this->Request()->getParam('value'));
458
        $service = $this->getService($order);
459
460
        /** @noinspection PhpUndefinedMethodInspection */
461
        $invoiceNumber = $order->getAttribute()->getSwagKlarnaInvoiceNumber();
462
        $status = $this->modelManager->find('\Shopware\Models\Order\DetailStatus', 3);
463
        $tax = null;
464
        /** @var Shopware\Models\Order\Detail $detail */
465
        foreach ($order->getDetails() as $detail) {
466
            if ($detail->getTax() !== null && $detail->getTax()->getId() != 0) {
467
                $tax = $detail->getTax();
468
            }
469
        }
470
471
        try {
472
            $result = $service->returnAmount(
473
                $invoiceNumber,
474
                $value,
475
                $detail->getTaxRate(),
0 ignored issues
show
Bug introduced by
The variable $detail seems to be defined by a foreach iteration on line 465. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
476
                KlarnaFlags::INC_VAT,
477
                'discount'
478
            );
479
480
            $value = $value > 0 ? $value * -1 : $value;
481
            $detail = new Shopware\Models\Order\Detail();
482
            $detail->fromArray([
483
                'order' => $order,
484
                'number' => $order->getNumber(),
485
                'tax' => $tax,
486
                'status' => $status,
487
                'taxRate' => $tax !== null ? $tax->getTax() : 0,
488
                'articleId' => 0,
489
                'articleNumber' => 'DISCOUNT',
490
                'articleName' => 'Discount',
491
                'price' => $value,
492
                'quantity' => 1,
493
                'attribute' => [
494
                    'swagKlarnaInvoiceNumber' => $result
495
                ]
496
            ]);
497
            $order->getDetails()->add($detail);
498
            $this->modelManager->flush();
499
            $this->View()->assign([
500
                'success' => true,
501
                'number' => $result
502
            ]);
503
        } catch (Exception $e) {
504
            $this->View()->assign([
505
                'success' => false,
506
                'message' => $e->getMessage()
507
            ]);
508
        }
509
    }
510
511
    public function autoUpdateAction()
512
    {
513
        $orderId = $this->Request()->getParam('orderId');
514
        $this->registerShopByOrderId($orderId);
515
        $order = $this->getOrderById($orderId);
516
517
        if ($order === null) {
518
            return;
519
        }
520
521
        if ($order->getInvoiceShipping() > 0 && $this->config->get('convertShippingFee')) {
522
            $status = $this->modelManager->find('\Shopware\Models\Order\DetailStatus', 0);
523
            $invoiceShippingNet = $order->getInvoiceShippingNet();
524
            $taxRate = round(($order->getInvoiceShipping() - $invoiceShippingNet) / $invoiceShippingNet * 100, 2);
525
            $detail = new Shopware\Models\Order\Detail();
526
            $detail->fromArray([
527
                'order' => $order,
528
                'number' => $order->getNumber(),
529
                'status' => $status,
530
                'taxRate' => $taxRate,
531
                'articleId' => 0,
532
                'articleNumber' => 'SHIPPING',
533
                'articleName' => 'Shipping Fee',
534
                'price' => $order->getInvoiceShipping(),
535
                'quantity' => 1,
536
                'attribute' => ['attribute1' => '']
537
            ]);
538
            $order->getDetails()->add($detail);
539
            $order->setInvoiceShipping(0);
540
            $order->setInvoiceShippingNet(0);
541
            $this->modelManager->flush();
542
        }
543
544
        $this->View()->assign([
545
            'success' => true,
546
        ]);
547
    }
548
549
    public function getInvoiceSecretAction()
550
    {
551
        $orderId = $this->Request()->getParam('orderId');
552
        $invoiceNo = $this->Request()->getParam('invoiceNo');
553
554
        if (empty($invoiceNo)) {
555
            /** @var DataLoader $dataLoader */
556
            $dataLoader = $this->get('shopware_attribute.data_loader');
557
558
            try {
559
                $data = $dataLoader->load('s_order_details_attributes', $orderId);
560
            } catch (Exception $e) {
561
                $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);
562
                return;
563
            }
564
565
            if (empty($data)) {
566
                $this->View()->assign(['success' => false, 'message' => 'Dataset was empty!']);
567
                return;
568
            }
569
570
            $invoiceNo = $data['swag_klarna_invoice_number'];
571
        }
572
573
        $eid = $this->config->get('merchantId');
574
        $sharedSecret = $this->config->get('sharedSecret');
575
        $testDrive = $this->config->get('testDrive');
576
577
        $secretParts = [$eid, $invoiceNo, $sharedSecret];
578
        $secret = urlencode(
579
            base64_encode(
580
                hash('sha512', implode(':', $secretParts), true)
581
            )
582
        );
583
584
        $this->View()->assign([
585
            'success' => true,
586
            'invoiceNo' => $invoiceNo,
587
            'secret' => $secret,
588
            'testDrive' => $testDrive
589
        ]);
590
    }
591
592
    /**
593
     * Helper method to get the default price for an article
594
     * @param $positionData
595
     */
596
    private function getPriceData($positionData)
597
    {
598
        /** @var Shopware\Models\Article\Detail $articleDetail */
599
        $articleDetail = Shopware()->Models()->getRepository('Shopware\Models\Article\Detail')->findOneBy([
600
            'number' => $positionData['articleNumber']
601
        ]);
602
        $article = $articleDetail->getArticle();
603
        $tax = intval($article->getTax()->getTax());
604
        $price = Shopware()->Models()->getRepository('Shopware\Models\Article\Price')->findOneBy([
605
            'articleDetailsId' => $articleDetail->getId(),
606
            'from' => 1
607
        ])->getPrice();
608
609
        $price = round($price * (100 + $tax) / 100, 3);
610
611
        $positionData['taxRate'] = $tax;
612
        $positionData['price'] = $price;
613
614
        return $positionData;
615
    }
616
617
    /**
618
     * Helper method to get the proper service with the correct EID
619
     *
620
     * @param Order $order
621
     * @return Klarna
622
     */
623
    private function getService($order)
624
    {
625
        $plugin = $this->plugin;
626
627
        if ($order->getPayment()->getName() !== 'klarna_checkout'
628
            && $this->plugin->isKpmActive()) {
629
            $plugin = Shopware()->Plugins()->Frontend()->SwagPaymentKlarnaKpm();
630
        }
631
632
        if (!method_exists($plugin, 'getService')) {
633
            // Older KPM version
634
            /** @noinspection PhpUndefinedMethodInspection */
635
            return $plugin->getKlarnaServiceByConfig($plugin->Config());
636
        }
637
        return $plugin->getService();
638
    }
639
640
641
    /**
642
     * @return array
643
     */
644
    public function getWhitelistedCSRFActions()
645
    {
646
        $csrfActions = [
647
            'activate',
648
            'autoUpdate',
649
            'cancel',
650
            'credit',
651
            'discount',
652
            'refund',
653
            'update'
654
        ];
655
        
656
        return $csrfActions;
657
    }
658
}
659