createTransferWithUnencryptedValues()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
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\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 Spryker\Yves\Router\Router\Router;
13
use SprykerEco\Shared\Computop\Config\ComputopApiConfig;
14
use SprykerEco\Yves\Computop\Mapper\Init\AbstractMapper;
15
use SprykerEco\Yves\Computop\Plugin\Router\ComputopRouteProviderPlugin;
16
17
class EasyCreditMapper extends AbstractMapper
18
{
19
    /**
20
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
21
     *
22
     * @return \Generated\Shared\Transfer\ComputopEasyCreditPaymentTransfer
23
     */
24
    public function createComputopPaymentTransfer(QuoteTransfer $quoteTransfer)
25
    {
26
        /** @var \Generated\Shared\Transfer\ComputopEasyCreditPaymentTransfer $computopPaymentTransfer */
27
        $computopPaymentTransfer = parent::createComputopPaymentTransfer($quoteTransfer);
28
29
        $addressData = $this->getAdditionalAddressData($quoteTransfer);
30
        $computopPaymentTransfer = $this->mapAddressDataToEasyCreditPayment($addressData, $computopPaymentTransfer);
31
        $computopPaymentTransfer->setMac(
32
            $this->computopApiService->generateEncryptedMac(
33
                $this->createRequestTransfer($computopPaymentTransfer)
34
            )
35
        );
36
37
        $decryptedValues = $this->computopApiService->getEncryptedArray(
38
            $this->getDataSubArray($computopPaymentTransfer),
39
            $this->config->getBlowfishPassword()
40
        );
41
42
        $computopPaymentTransfer->setData($decryptedValues[ComputopApiConfig::DATA]);
43
        $computopPaymentTransfer->setLen($decryptedValues[ComputopApiConfig::LENGTH]);
44
        $computopPaymentTransfer->setUrl(
45
            $this->getActionUrl(
46
                $this->config->getEasyCreditInitActionUrl(),
47
                $this->getQueryParameters(
48
                    $computopPaymentTransfer->getMerchantId(),
49
                    $decryptedValues[ComputopApiConfig::DATA],
50
                    $decryptedValues[ComputopApiConfig::LENGTH]
51
                )
52
            )
53
        );
54
55
        return $computopPaymentTransfer;
56
    }
57
58
    /**
59
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
60
     *
61
     * @return \Generated\Shared\Transfer\ComputopEasyCreditPaymentTransfer
62
     */
63
    protected function createTransferWithUnencryptedValues(QuoteTransfer $quoteTransfer)
64
    {
65
        $computopPaymentTransfer = new ComputopEasyCreditPaymentTransfer();
66
67
        $computopPaymentTransfer->setTransId($this->generateTransId($quoteTransfer));
68
        $computopPaymentTransfer->setUrlSuccess(
69
            $this->router->generate(ComputopRouteProviderPlugin::EASY_CREDIT_SUCCESS, [], Router::ABSOLUTE_URL)
70
        );
71
72
        return $computopPaymentTransfer;
73
    }
74
75
    /**
76
     * @param \Generated\Shared\Transfer\ComputopEasyCreditPaymentTransfer $cardPaymentTransfer
77
     *
78
     * @return array
79
     */
80
    protected function getDataSubArray(ComputopEasyCreditPaymentTransfer $cardPaymentTransfer)
81
    {
82
        $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...
83
        $dataSubArray[ComputopApiConfig::AMOUNT] = $cardPaymentTransfer->getAmount();
84
        $dataSubArray[ComputopApiConfig::CURRENCY] = $cardPaymentTransfer->getCurrency();
85
        $dataSubArray[ComputopApiConfig::URL_SUCCESS] = $cardPaymentTransfer->getUrlSuccess();
86
        $dataSubArray[ComputopApiConfig::URL_NOTIFY] = $cardPaymentTransfer->getUrlNotify();
87
        $dataSubArray[ComputopApiConfig::URL_FAILURE] = $cardPaymentTransfer->getUrlFailure();
88
        $dataSubArray[ComputopApiConfig::RESPONSE] = $cardPaymentTransfer->getResponse();
89
        $dataSubArray[ComputopApiConfig::EVENT_TOKEN] = ComputopApiConfig::EVENT_TOKEN_INIT;
90
        $dataSubArray[ComputopApiConfig::ETI_ID] = $this->config->getEtiId();
91
        $dataSubArray[ComputopApiConfig::IP_ADDRESS] = $cardPaymentTransfer->getClientIp();
92
        $dataSubArray[ComputopApiConfig::SHIPPING_ZIP] = $cardPaymentTransfer->getShippingZip();
93
        $dataSubArray[ComputopApiConfig::SHIPPING_CITY] = $cardPaymentTransfer->getShippingCity();
94
        $dataSubArray[ComputopApiConfig::SHIPPING_COUNTRY_CODE] = $cardPaymentTransfer->getShippingCountryCode();
95
        $dataSubArray[ComputopApiConfig::SHIPPING_STREET] = $cardPaymentTransfer->getShippingStreet();
96
        $dataSubArray[ComputopApiConfig::SHIPPING_STREET_NUMBER] = $cardPaymentTransfer->getShippingStreetNumber();
97
98
        return $dataSubArray;
99
    }
100
101
    /**
102
     * @param array $addressData
103
     * @param \Generated\Shared\Transfer\ComputopEasyCreditPaymentTransfer $computopEasyCreditPaymentTransfer
104
     *
105
     * @return \Generated\Shared\Transfer\ComputopEasyCreditPaymentTransfer
106
     */
107
    protected function mapAddressDataToEasyCreditPayment(
108
        array $addressData,
109
        ComputopEasyCreditPaymentTransfer $computopEasyCreditPaymentTransfer
110
    ): ComputopEasyCreditPaymentTransfer {
111
        $computopEasyCreditPaymentTransfer->setShippingCity($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_CITY]);
112
        $computopEasyCreditPaymentTransfer->setShippingStreet($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET]);
113
        $computopEasyCreditPaymentTransfer->setShippingStreetNumber($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET_NUMBER]);
114
        $computopEasyCreditPaymentTransfer->setShippingCountryCode($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_COUNTRY_CODE]);
115
116
        return $computopEasyCreditPaymentTransfer;
117
    }
118
119
    /**
120
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
121
     *
122
     * @return array
123
     */
124
    protected function getAdditionalAddressData(QuoteTransfer $quoteTransfer): array
125
    {
126
        $addressTransfer = $quoteTransfer->getBillingSameAsShipping() ? $quoteTransfer->getBillingAddress() : $quoteTransfer->getShippingAddress();
127
128
        $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...
129
        $addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET] = $addressTransfer->getAddress1();
130
        $addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET_NUMBER] = $addressTransfer->getAddress2();
131
        $addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_COUNTRY_CODE] = $addressTransfer->getIso2Code();
132
133
        return $addressData;
134
    }
135
}
136