savePaymentComputopDetailEntity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\Init;
9
10
use Generated\Shared\Transfer\ComputopEasyCreditInitResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ditInitResponseTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
class EasyCreditResponseSaver extends AbstractResponseSaver
14
{
15
    /**
16
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
17
     *
18
     * @return \Generated\Shared\Transfer\QuoteTransfer
19
     */
20
    public function save(QuoteTransfer $quoteTransfer)
21
    {
22
        $responseTransfer = $quoteTransfer->getPayment()->getComputopEasyCredit()->getEasyCreditInitResponse();
23
        $this->setPaymentEntity($responseTransfer->getHeader()->getTransId());
24
        if ($responseTransfer->getHeader()->getIsSuccess()) {
25
            $this->getTransactionHandler()->handleTransaction(
26
                function () use ($responseTransfer) {
27
                    $this->savePaymentComputopEntity($responseTransfer);
28
                    $this->savePaymentComputopDetailEntity($responseTransfer);
29
                    $this->savePaymentComputopOrderItemsEntities();
30
                }
31
            );
32
        }
33
34
        return $quoteTransfer;
35
    }
36
37
    /**
38
     * @param \Generated\Shared\Transfer\ComputopEasyCreditInitResponseTransfer $responseTransfer
39
     *
40
     * @return void
41
     */
42
    protected function savePaymentComputopEntity(ComputopEasyCreditInitResponseTransfer $responseTransfer)
43
    {
44
        $paymentEntity = $this->getPaymentEntity();
45
        $paymentEntity->setPayId($responseTransfer->getHeader()->getPayId());
46
        $paymentEntity->setXId($responseTransfer->getHeader()->getXId());
47
        $paymentEntity->save();
48
    }
49
50
    /**
51
     * @param \Generated\Shared\Transfer\ComputopEasyCreditInitResponseTransfer $responseTransfer
52
     *
53
     * @return void
54
     */
55
    protected function savePaymentComputopDetailEntity(ComputopEasyCreditInitResponseTransfer $responseTransfer)
56
    {
57
        $paymentEntityDetails = $this->getPaymentEntity()->getSpyPaymentComputopDetail();
58
        $paymentEntityDetails->fromArray($responseTransfer->toArray());
59
        $paymentEntityDetails->save();
60
    }
61
62
    /**
63
     * @return void
64
     */
65
    protected function savePaymentComputopOrderItemsEntities()
66
    {
67
        $orderItems = $this
68
            ->queryContainer
69
            ->getSpySalesOrderItemsById($this->getPaymentEntity()->getFkSalesOrder())
70
            ->find();
71
72
        foreach ($orderItems as $selectedItem) {
73
            foreach ($this->getPaymentEntity()->getSpyPaymentComputopOrderItems() as $item) {
74
                if ($item->getFkSalesOrderItem() !== $selectedItem->getIdSalesOrderItem()) {
75
                    continue;
76
                }
77
                $item->setStatus($this->config->getOmsStatusInitialized());
78
                $item->save();
79
            }
80
        }
81
    }
82
}
83