Passed
Pull Request — master (#45)
by
unknown
03:36
created

updateComputopPaymentTransfer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 39
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 39
rs 9.536
cc 2
nc 2
nop 2
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\Hook\Mapper\Init;
9
10
use Generated\Shared\Transfer\ComputopPayuCeeSinglePaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...eeSinglePaymentTransfer 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
use Spryker\Shared\Kernel\Transfer\TransferInterface;
13
use SprykerEco\Shared\Computop\ComputopConfig;
14
use SprykerEco\Shared\Computop\Config\ComputopApiConfig;
15
16
class InitPayuCeeSingleMapper extends AbstractMapper
17
{
18
    /**
19
     * @return string
20
     */
21
    public function getMethodName(): string
22
    {
23
        return ComputopConfig::PAYMENT_METHOD_PAYU_CEE_SINGLE;
24
    }
25
26
    /**
27
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
28
     * @param \Spryker\Shared\Kernel\Transfer\TransferInterface $computopPayuCeeSinglePaymentTransfer
29
     *
30
     * @return \Spryker\Shared\Kernel\Transfer\TransferInterface
31
     */
32
    public function updateComputopPaymentTransfer(
33
        QuoteTransfer $quoteTransfer,
34
        TransferInterface $computopPayuCeeSinglePaymentTransfer
35
    ): TransferInterface {
36
        /** @var \Generated\Shared\Transfer\ComputopPayuCeeSinglePaymentTransfer $computopPayuCeeSinglePaymentTransfer */
37
        $computopPayuCeeSinglePaymentTransfer = parent::updateComputopPaymentTransfer(
38
            $quoteTransfer,
39
            $computopPayuCeeSinglePaymentTransfer,
40
        );
41
        $computopPayuCeeSinglePaymentTransfer
42
            ->setRefNr($quoteTransfer->getOrderReference() . '-' . date('Y-m-d H:i:s'))
43
            ->setMerchantId($this->config->getMerchantId())
44
            ->setAmount($quoteTransfer->getTotals()->getGrandTotal());
45
46
        $requestTransfer = $this->createRequestTransfer($computopPayuCeeSinglePaymentTransfer);
47
        $encryptedMac = $this->computopApiService->generateEncryptedMac($requestTransfer);
48
        $computopPayuCeeSinglePaymentTransfer->setMac($encryptedMac);
49
50
        $encryptedValues = $this->computopApiService->getEncryptedArray(
51
            $this->getDataSubArray($computopPayuCeeSinglePaymentTransfer),
52
            $this->config->getBlowfishPass(),
53
        );
54
55
        if (!isset($encryptedValues[ComputopApiConfig::LENGTH], $encryptedValues[ComputopApiConfig::DATA])) {
56
            return $computopPayuCeeSinglePaymentTransfer;
57
        }
58
59
        $urlToComputop = $this->getUrlToComputop(
60
            (string)$computopPayuCeeSinglePaymentTransfer->getMerchantId(),
61
            $encryptedValues[ComputopApiConfig::DATA],
62
            $encryptedValues[ComputopApiConfig::LENGTH],
63
        );
64
65
        $computopPayuCeeSinglePaymentTransfer
66
            ->setData($encryptedValues[ComputopApiConfig::DATA])
67
            ->setLen($encryptedValues[ComputopApiConfig::LENGTH])
68
            ->setUrl($urlToComputop);
69
70
        return $computopPayuCeeSinglePaymentTransfer;
71
    }
72
73
    /**
74
     * @return string|null
75
     */
76
    protected function getActionUrl(): ?string
77
    {
78
        return $this->config->getPayuCeeSingleInitAction();
79
    }
80
81
    /**
82
     * @param \Generated\Shared\Transfer\ComputopPayuCeeSinglePaymentTransfer $computopPayuCeeSinglePaymentTransfer
83
     *
84
     * @return array
85
     */
86
    protected function getDataSubArray(ComputopPayuCeeSinglePaymentTransfer $computopPayuCeeSinglePaymentTransfer): array
87
    {
88
        return [
89
            ComputopApiConfig::MERCHANT_ID => $computopPayuCeeSinglePaymentTransfer->getMerchantId(),
90
            ComputopApiConfig::TRANS_ID => $computopPayuCeeSinglePaymentTransfer->getTransId(),
91
            ComputopApiConfig::REF_NR => $computopPayuCeeSinglePaymentTransfer->getRefNr(),
92
            ComputopApiConfig::AMOUNT => $computopPayuCeeSinglePaymentTransfer->getAmount(),
93
            ComputopApiConfig::CURRENCY => $computopPayuCeeSinglePaymentTransfer->getCurrency(),
94
            ComputopApiConfig::MAC => $computopPayuCeeSinglePaymentTransfer->getMac(),
95
            ComputopApiConfig::URL_SUCCESS => $computopPayuCeeSinglePaymentTransfer->getUrlSuccess(),
96
            ComputopApiConfig::URL_FAILURE => $computopPayuCeeSinglePaymentTransfer->getUrlFailure(),
97
            ComputopApiConfig::RESPONSE => $computopPayuCeeSinglePaymentTransfer->getResponse(),
98
            ComputopApiConfig::URL_NOTIFY => $computopPayuCeeSinglePaymentTransfer->getUrlNotify(),
99
            ComputopApiConfig::REQ_ID => $computopPayuCeeSinglePaymentTransfer->getReqId(),
100
            ComputopApiConfig::CAPTURE => $computopPayuCeeSinglePaymentTransfer->getCapture(),
101
            ComputopApiConfig::ORDER_DESC => $computopPayuCeeSinglePaymentTransfer->getOrderDesc(),
102
            ComputopApiConfig::ARTICLE_LIST => $computopPayuCeeSinglePaymentTransfer->getArticleList(),
103
            ComputopApiConfig::FIRST_NAME => $computopPayuCeeSinglePaymentTransfer->getFirstName(),
104
            ComputopApiConfig::LAST_NAME => $computopPayuCeeSinglePaymentTransfer->getLastName(),
105
            ComputopApiConfig::EMAIL_ADDRESS => $computopPayuCeeSinglePaymentTransfer->getEmail(),
106
            ComputopApiConfig::LANGUAGE => strtolower((string)$computopPayuCeeSinglePaymentTransfer->getLanguage()),
107
        ];
108
    }
109
}
110