Passed
Push — feature/eco-2521/eco-2522-suit... ( ca0ff5...cfa5b3 )
by Ruslan
02:36
created

createTransferWithUnencryptedValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
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\Yves\Computop\Mapper\Init\PostPlace;
9
10
use Generated\Shared\Transfer\ComputopEasyCreditPaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...syCreditPaymentTransfer 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 SprykerEco\Shared\Computop\Config\ComputopApiConfig;
13
use SprykerEco\Yves\Computop\Mapper\Init\AbstractMapper;
14
use SprykerEco\Yves\Computop\Plugin\Provider\ComputopControllerProvider;
15
16
class EasyCreditMapper extends AbstractMapper
17
{
18
    /**
19
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
20
     *
21
     * @return \Generated\Shared\Transfer\ComputopEasyCreditPaymentTransfer
22
     */
23
    public function createComputopPaymentTransfer(QuoteTransfer $quoteTransfer)
24
    {
25
        /** @var \Generated\Shared\Transfer\ComputopEasyCreditPaymentTransfer $computopPaymentTransfer */
26
        $computopPaymentTransfer = parent::createComputopPaymentTransfer($quoteTransfer);
27
28
        $addressData = $this->getAdditionalAddressData($quoteTransfer);
29
        $computopPaymentTransfer = $this->mapAddressDataToEasyCreditPayment($addressData, $computopPaymentTransfer);
30
31
        $computopPaymentTransfer->setUrlNotify(
32
            $this->getAbsoluteUrl($this->application->path(ComputopControllerProvider::NOTIFY_PATH_NAME))
0 ignored issues
show
Bug introduced by
The method path() does not exist on Silex\Application. Did you maybe mean patch()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
            $this->getAbsoluteUrl($this->application->/** @scrutinizer ignore-call */ path(ComputopControllerProvider::NOTIFY_PATH_NAME))

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
        );
34
        $computopPaymentTransfer->setMac(
35
            $this->computopApiService->generateEncryptedMac(
36
                $this->createRequestTransfer($computopPaymentTransfer)
37
            )
38
        );
39
40
        $decryptedValues = $this->computopApiService->getEncryptedArray(
41
            $this->getDataSubArray($computopPaymentTransfer),
42
            $this->config->getBlowfishPassword()
43
        );
44
45
        $computopPaymentTransfer->setData($decryptedValues[ComputopApiConfig::DATA]);
46
        $computopPaymentTransfer->setLen($decryptedValues[ComputopApiConfig::LENGTH]);
47
        $computopPaymentTransfer->setUrl(
48
            $this->getActionUrl(
49
                $this->config->getEasyCreditInitActionUrl(),
50
                $this->getQueryParameters(
51
                    $computopPaymentTransfer->getMerchantId(),
52
                    $decryptedValues[ComputopApiConfig::DATA],
53
                    $decryptedValues[ComputopApiConfig::LENGTH]
54
                )
55
            )
56
        );
57
58
        return $computopPaymentTransfer;
59
    }
60
61
    /**
62
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
63
     *
64
     * @return \Generated\Shared\Transfer\ComputopEasyCreditPaymentTransfer
65
     */
66
    protected function createTransferWithUnencryptedValues(QuoteTransfer $quoteTransfer)
67
    {
68
        $computopPaymentTransfer = new ComputopEasyCreditPaymentTransfer();
69
70
        $computopPaymentTransfer->setTransId($this->generateTransId($quoteTransfer));
71
        $computopPaymentTransfer->setUrlSuccess(
72
            $this->getAbsoluteUrl($this->application->path(ComputopControllerProvider::EASY_CREDIT_SUCCESS))
73
        );
74
75
        return $computopPaymentTransfer;
76
    }
77
78
    /**
79
     * @param \Generated\Shared\Transfer\ComputopEasyCreditPaymentTransfer $cardPaymentTransfer
80
     *
81
     * @return array
82
     */
83
    protected function getDataSubArray(ComputopEasyCreditPaymentTransfer $cardPaymentTransfer)
84
    {
85
        $dataSubArray[ComputopApiConfig::TRANS_ID] = $cardPaymentTransfer->getTransId();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$dataSubArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dataSubArray = array(); before regardless.
Loading history...
86
        $dataSubArray[ComputopApiConfig::AMOUNT] = $cardPaymentTransfer->getAmount();
87
        $dataSubArray[ComputopApiConfig::CURRENCY] = $cardPaymentTransfer->getCurrency();
88
        $dataSubArray[ComputopApiConfig::URL_SUCCESS] = $cardPaymentTransfer->getUrlSuccess();
89
        $dataSubArray[ComputopApiConfig::URL_FAILURE] = $cardPaymentTransfer->getUrlFailure();
90
        $dataSubArray[ComputopApiConfig::URL_NOTIFY] = $cardPaymentTransfer->getUrlNotify();
91
        $dataSubArray[ComputopApiConfig::RESPONSE] = $cardPaymentTransfer->getResponse();
92
        $dataSubArray[ComputopApiConfig::EVENT_TOKEN] = ComputopApiConfig::EVENT_TOKEN_INIT;
93
        $dataSubArray[ComputopApiConfig::ETI_ID] = $this->config->getEtiId();
94
        $dataSubArray[ComputopApiConfig::IP_ADDRESS] = $cardPaymentTransfer->getClientIp();
95
        $dataSubArray[ComputopApiConfig::SHIPPING_ZIP] = $cardPaymentTransfer->getShippingZip();
96
        $dataSubArray[ComputopApiConfig::SHIPPING_CITY] = $cardPaymentTransfer->getShippingCity();
97
        $dataSubArray[ComputopApiConfig::SHIPPING_COUNTRY_CODE] = $cardPaymentTransfer->getShippingCountryCode();
98
        $dataSubArray[ComputopApiConfig::SHIPPING_STREET] = $cardPaymentTransfer->getShippingStreet();
99
        $dataSubArray[ComputopApiConfig::SHIPPING_STREET_NUMBER] = $cardPaymentTransfer->getShippingStreetNumber();
100
101
        return $dataSubArray;
102
    }
103
104
    /**
105
     * @param array $addressData
106
     * @param \Generated\Shared\Transfer\ComputopEasyCreditPaymentTransfer $computopEasyCreditPaymentTransfer
107
     *
108
     * @return \Generated\Shared\Transfer\ComputopEasyCreditPaymentTransfer
109
     */
110
    protected function mapAddressDataToEasyCreditPayment(
111
        array $addressData,
112
        ComputopEasyCreditPaymentTransfer $computopEasyCreditPaymentTransfer
113
    ): ComputopEasyCreditPaymentTransfer {
114
115
        $computopEasyCreditPaymentTransfer->setShippingCity($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_CITY]);
116
        $computopEasyCreditPaymentTransfer->setShippingStreet($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET]);
117
        $computopEasyCreditPaymentTransfer->setShippingStreetNumber($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET_NUMBER]);
118
        $computopEasyCreditPaymentTransfer->setShippingCountryCode($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_COUNTRY_CODE]);
119
120
        return $computopEasyCreditPaymentTransfer;
121
    }
122
123
    /**
124
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
125
     *
126
     * @return array
127
     */
128
    protected function getAdditionalAddressData(QuoteTransfer $quoteTransfer): array
129
    {
130
        $addressTransfer = $quoteTransfer->getBillingSameAsShipping() ? $quoteTransfer->getBillingAddress() : $quoteTransfer->getShippingAddress();
131
132
        $addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_CITY] = $addressTransfer->getCity();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$addressData was never initialized. Although not strictly required by PHP, it is generally a good practice to add $addressData = array(); before regardless.
Loading history...
133
        $addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET] = $addressTransfer->getAddress1();
134
        $addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET_NUMBER] = $addressTransfer->getAddress2();
135
        $addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_COUNTRY_CODE] = $addressTransfer->getIso2Code();
136
137
        return $addressData;
138
    }
139
}
140