updateComputopPaymentTransfer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 25
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
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\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...
11
use Spryker\Shared\Kernel\Transfer\TransferInterface;
12
use SprykerEco\Shared\Computop\ComputopConfig;
13
use SprykerEco\Shared\Computop\Config\ComputopApiConfig;
14
15
class InitPaydirektMapper extends AbstractMapper
16
{
17
    /**
18
     * @return string
19
     */
20
    public function getMethodName()
21
    {
22
        return ComputopConfig::PAYMENT_METHOD_PAYDIREKT;
23
    }
24
25
    /**
26
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
27
     * @param \Spryker\Shared\Kernel\Transfer\TransferInterface $computopPaymentTransfer
28
     *
29
     * @return \Spryker\Shared\Kernel\Transfer\TransferInterface
30
     */
31
    public function updateComputopPaymentTransfer(QuoteTransfer $quoteTransfer, TransferInterface $computopPaymentTransfer)
32
    {
33
        /** @var \Generated\Shared\Transfer\ComputopPaydirektPaymentTransfer $computopPaymentTransfer */
34
        $computopPaymentTransfer = parent::updateComputopPaymentTransfer($quoteTransfer, $computopPaymentTransfer);
35
        $computopPaymentTransfer->setMerchantId($this->config->getMerchantId());
36
        $computopPaymentTransfer->setAmount($quoteTransfer->getTotals()->getGrandTotal());
37
        $computopPaymentTransfer->setMac(
38
            $this->computopApiService->generateEncryptedMac(
39
                $this->createRequestTransfer($computopPaymentTransfer)
40
            )
41
        );
42
43
        $decryptedValues = $this->computopApiService->getEncryptedArray(
44
            $this->getDataSubArray($computopPaymentTransfer),
45
            $this->config->getBlowfishPass()
46
        );
47
48
        $length = $decryptedValues[ComputopApiConfig::LENGTH];
49
        $data = $decryptedValues[ComputopApiConfig::DATA];
50
51
        $computopPaymentTransfer->setData($data);
52
        $computopPaymentTransfer->setLen($length);
53
        $computopPaymentTransfer->setUrl($this->getUrlToComputop($computopPaymentTransfer->getMerchantId(), $data, $length));
54
55
        return $computopPaymentTransfer;
56
    }
57
58
    /**
59
     * @param \Spryker\Shared\Kernel\Transfer\TransferInterface $computopPaydirectPaymentTransfer
60
     *
61
     * @return array
62
     */
63
    protected function getDataSubArray(TransferInterface $computopPaydirectPaymentTransfer)
64
    {
65
        /** @var \Generated\Shared\Transfer\ComputopPaydirektPaymentTransfer $computopPaydirectPaymentTransfer */
66
        $dataSubArray[ComputopApiConfig::TRANS_ID] = $computopPaydirectPaymentTransfer->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...
67
        $dataSubArray[ComputopApiConfig::AMOUNT] = $computopPaydirectPaymentTransfer->getAmount();
68
        $dataSubArray[ComputopApiConfig::CURRENCY] = $computopPaydirectPaymentTransfer->getCurrency();
69
        $dataSubArray[ComputopApiConfig::URL_SUCCESS] = $computopPaydirectPaymentTransfer->getUrlSuccess();
70
        $dataSubArray[ComputopApiConfig::URL_NOTIFY] = $computopPaydirectPaymentTransfer->getUrlNotify();
71
        $dataSubArray[ComputopApiConfig::URL_FAILURE] = $computopPaydirectPaymentTransfer->getUrlFailure();
72
        $dataSubArray[ComputopApiConfig::RESPONSE] = $computopPaydirectPaymentTransfer->getResponse();
73
        $dataSubArray[ComputopApiConfig::MAC] = $computopPaydirectPaymentTransfer->getMac();
74
        $dataSubArray[ComputopApiConfig::ORDER_DESC] = $computopPaydirectPaymentTransfer->getOrderDesc();
75
76
        $dataSubArray[ComputopApiConfig::SHOP_API_KEY] = $computopPaydirectPaymentTransfer->getShopApiKey();
77
        $dataSubArray[ComputopApiConfig::SHIPPING_FIRST_NAME] = $computopPaydirectPaymentTransfer->getShippingFirstName();
78
        $dataSubArray[ComputopApiConfig::SHIPPING_LAST_NAME] = $computopPaydirectPaymentTransfer->getShippingLastName();
79
        $dataSubArray[ComputopApiConfig::SHIPPING_ZIP] = $computopPaydirectPaymentTransfer->getShippingZip();
80
        $dataSubArray[ComputopApiConfig::SHIPPING_CITY] = $computopPaydirectPaymentTransfer->getShippingCity();
81
        $dataSubArray[ComputopApiConfig::SHIPPING_COUNTRY_CODE] = $computopPaydirectPaymentTransfer->getShippingCountryCode();
82
        $dataSubArray[ComputopApiConfig::SHIPPING_AMOUNT] = $computopPaydirectPaymentTransfer->getShippingAmount();
83
        $dataSubArray[ComputopApiConfig::SHOPPING_BASKET_AMOUNT] = $computopPaydirectPaymentTransfer->getShoppingBasketAmount();
84
        $dataSubArray[ComputopApiConfig::ETI_ID] = $this->config->getEtiId();
85
        $dataSubArray[ComputopApiConfig::IP_ADDRESS] = $computopPaydirectPaymentTransfer->getClientIp();
86
        $dataSubArray[ComputopApiConfig::SHIPPING_ZIP] = $computopPaydirectPaymentTransfer->getShippingZip();
87
88
        return $dataSubArray;
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    protected function getActionUrl()
95
    {
96
        return $this->config->getPaydirektInitAction();
97
    }
98
}
99