Completed
Push — feature/eco-3623-payone-pay-u-... ( 3d04a1...693bfb )
by Roman
08:43 queued 08:39
created

savePaymentComputopEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 6
rs 10
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\ComputopPayuCeeSingleInitResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...gleInitResponseTransfer 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 PayuCeeSingleResponseSaver 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): QuoteTransfer
21
    {
22
        $responseTransfer = $quoteTransfer->getPayment()->getComputopPayuCeeSingle()->getPayuCeeSingleInitResponse();
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\ComputopPayuCeeSingleInitResponseTransfer $responseTransfer
39
     *
40
     * @return void
41
     */
42
    protected function savePaymentComputopEntity(ComputopPayuCeeSingleInitResponseTransfer $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\ComputopPayuCeeSingleInitResponseTransfer $responseTransfer
52
     *
53
     * @return void
54
     */
55
    protected function savePaymentComputopDetailEntity(ComputopPayuCeeSingleInitResponseTransfer $responseTransfer)
56
    {
57
        $paymentEntityDetails = $this->getPaymentEntity()->getSpyPaymentComputopDetail();
58
        $paymentEntityDetails->fromArray($responseTransfer->toArray());
59
60
        $customerTransactionId = $responseTransfer->getCustomerTransactionId();
61
        if ($customerTransactionId) {
62
            $paymentEntityDetails->setCustomerTransactionId((int)$customerTransactionId);
63
        }
64
65
        $paymentEntityDetails->save();
66
    }
67
68
    /**
69
     * @return void
70
     */
71
    protected function savePaymentComputopOrderItemsEntities()
72
    {
73
        foreach ($this->getPaymentEntity()->getSpyPaymentComputopOrderItems() as $item) {
74
            $item->setStatus($this->config->getOmsStatusAuthorized());
75
            $item->save();
76
        }
77
    }
78
}
79