Completed
Push — master ( 85e8b4...f9423e )
by mark
14s queued 14s
created

mapAddressFromQuoteToComputopPayPalPayment()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 22
rs 9.7998
cc 3
nc 4
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\Yves\Computop\Mapper\Init\PostPlace;
9
10
use Generated\Shared\Transfer\ComputopPayPalPaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...opPayPalPaymentTransfer 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\ComputopConfig as ComputopSharedConfig;
14
use SprykerEco\Shared\Computop\Config\ComputopApiConfig;
15
use SprykerEco\Yves\Computop\Mapper\Init\AbstractMapper;
16
use SprykerEco\Yves\Computop\Plugin\Router\ComputopRouteProviderPlugin;
17
18
class PayPalMapper extends AbstractMapper
19
{
20
    /**
21
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
22
     *
23
     * @return \Generated\Shared\Transfer\ComputopPayPalPaymentTransfer
24
     */
25
    public function createComputopPaymentTransfer(QuoteTransfer $quoteTransfer)
26
    {
27
        /** @var \Generated\Shared\Transfer\ComputopPayPalPaymentTransfer $computopPaymentTransfer */
28
        $computopPaymentTransfer = parent::createComputopPaymentTransfer($quoteTransfer);
29
        $computopPaymentTransfer->setMac(
30
            $this->computopApiService->generateEncryptedMac(
31
                $this->createRequestTransfer($computopPaymentTransfer)
32
            )
33
        );
34
35
        $decryptedValues = $this->computopApiService->getEncryptedArray(
36
            $this->getDataSubArray($computopPaymentTransfer),
37
            $this->config->getBlowfishPassword()
38
        );
39
40
        $computopPaymentTransfer->setData($decryptedValues[ComputopApiConfig::DATA]);
41
        $computopPaymentTransfer->setLen($decryptedValues[ComputopApiConfig::LENGTH]);
42
        $computopPaymentTransfer->setUrl(
43
            $this->getActionUrl(
44
                $this->config->getPayPalInitActionUrl(),
45
                $this->getQueryParameters(
46
                    $computopPaymentTransfer->getMerchantId(),
47
                    $decryptedValues[ComputopApiConfig::DATA],
48
                    $decryptedValues[ComputopApiConfig::LENGTH]
49
                )
50
            )
51
        );
52
53
        return $computopPaymentTransfer;
54
    }
55
56
    /**
57
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
58
     *
59
     * @return \Generated\Shared\Transfer\ComputopPayPalPaymentTransfer
60
     */
61
    protected function createTransferWithUnencryptedValues(QuoteTransfer $quoteTransfer)
62
    {
63
        $computopPaymentTransfer = new ComputopPayPalPaymentTransfer();
64
65
        $computopPaymentTransfer->setCapture(
66
            $this->getCaptureType(ComputopSharedConfig::PAYMENT_METHOD_PAY_PAL)
67
        );
68
        $computopPaymentTransfer->setTransId($this->generateTransId($quoteTransfer));
69
        $computopPaymentTransfer->setTxType($this->config->getPayPalTxType());
70
        $computopPaymentTransfer->setUrlSuccess(
71
            $this->router->generate(ComputopRouteProviderPlugin::PAY_PAL_SUCCESS, [], Router::ABSOLUTE_URL)
72
        );
73
        $computopPaymentTransfer->setOrderDesc(
74
            $this->computopApiService->getDescriptionValue($quoteTransfer->getItems()->getArrayCopy())
75
        );
76
77
        $this->mapAddressFromQuoteToComputopPayPalPayment($quoteTransfer, $computopPaymentTransfer);
78
79
        return $computopPaymentTransfer;
80
    }
81
82
    /**
83
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
84
     * @param \Generated\Shared\Transfer\ComputopPayPalPaymentTransfer $computopPayPalPaymentTransfer
85
     *
86
     * @return \Generated\Shared\Transfer\ComputopPayPalPaymentTransfer
87
     */
88
    protected function mapAddressFromQuoteToComputopPayPalPayment(
89
        QuoteTransfer $quoteTransfer,
90
        ComputopPayPalPaymentTransfer $computopPayPalPaymentTransfer
91
    ): ComputopPayPalPaymentTransfer {
92
        $addressTransfer = $quoteTransfer->getBillingSameAsShipping() ? $quoteTransfer->getBillingAddress() : $quoteTransfer->getShippingAddress();
93
94
        if (!$addressTransfer) {
95
            return $computopPayPalPaymentTransfer;
96
        }
97
98
        $computopPayPalPaymentTransfer
99
            ->setFirstName($addressTransfer->getFirstName())
100
            ->setLastName($addressTransfer->getLastName())
101
            ->setAddressStreet($addressTransfer->getAddress1())
102
            ->setAddressStreet2($addressTransfer->getAddress2())
103
            ->setAddressCity($addressTransfer->getCity())
104
            ->setAddressState($addressTransfer->getState())
105
            ->setAddressZip($addressTransfer->getZipCode())
106
            ->setAddressCountryCode($addressTransfer->getIso2Code())
107
            ->setPhone($addressTransfer->getPhone());
108
109
        return $computopPayPalPaymentTransfer;
110
    }
111
112
    /**
113
     * @param \Generated\Shared\Transfer\ComputopPayPalPaymentTransfer $computopPayPalPaymentTransfer
114
     *
115
     * @return array
116
     */
117
    protected function getDataSubArray(ComputopPayPalPaymentTransfer $computopPayPalPaymentTransfer)
118
    {
119
        $dataSubArray[ComputopApiConfig::TRANS_ID] = $computopPayPalPaymentTransfer->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...
120
        $dataSubArray[ComputopApiConfig::AMOUNT] = $computopPayPalPaymentTransfer->getAmount();
121
        $dataSubArray[ComputopApiConfig::CURRENCY] = $computopPayPalPaymentTransfer->getCurrency();
122
        $dataSubArray[ComputopApiConfig::URL_SUCCESS] = $computopPayPalPaymentTransfer->getUrlSuccess();
123
        $dataSubArray[ComputopApiConfig::URL_NOTIFY] = $computopPayPalPaymentTransfer->getUrlNotify();
124
        $dataSubArray[ComputopApiConfig::URL_FAILURE] = $computopPayPalPaymentTransfer->getUrlFailure();
125
        $dataSubArray[ComputopApiConfig::CAPTURE] = $computopPayPalPaymentTransfer->getCapture();
126
        $dataSubArray[ComputopApiConfig::RESPONSE] = $computopPayPalPaymentTransfer->getResponse();
127
        $dataSubArray[ComputopApiConfig::MAC] = $computopPayPalPaymentTransfer->getMac();
128
        $dataSubArray[ComputopApiConfig::TX_TYPE] = $computopPayPalPaymentTransfer->getTxType();
129
        $dataSubArray[ComputopApiConfig::ORDER_DESC] = $computopPayPalPaymentTransfer->getOrderDesc();
130
        $dataSubArray[ComputopApiConfig::ETI_ID] = $this->config->getEtiId();
131
        $dataSubArray[ComputopApiConfig::IP_ADDRESS] = $computopPayPalPaymentTransfer->getClientIp();
132
        $dataSubArray[ComputopApiConfig::SHIPPING_ZIP] = $computopPayPalPaymentTransfer->getShippingZip();
133
134
        if (!$computopPayPalPaymentTransfer->getAddressStreet()) {
135
            $dataSubArray[ComputopApiConfig::NO_SHIPPING] = ComputopSharedConfig::PAY_PAL_NO_SHIPPING;
136
137
            return $dataSubArray;
138
        }
139
140
        $dataSubArray[ComputopApiConfig::FIRST_NAME] = $computopPayPalPaymentTransfer->getFirstName();
141
        $dataSubArray[ComputopApiConfig::LAST_NAME] = $computopPayPalPaymentTransfer->getLastName();
142
        $dataSubArray[ComputopApiConfig::ADDRESS_STREET] = $computopPayPalPaymentTransfer->getAddressStreet();
143
        $dataSubArray[ComputopApiConfig::ADDRESS_STREET2] = $computopPayPalPaymentTransfer->getAddressStreet2();
144
        $dataSubArray[ComputopApiConfig::ADDRESS_CITY] = $computopPayPalPaymentTransfer->getAddressCity();
145
146
        if ($computopPayPalPaymentTransfer->getAddressState()) {
147
            $dataSubArray[ComputopApiConfig::ADDRESS_STATE] = $computopPayPalPaymentTransfer->getAddressState();
148
        }
149
150
        $dataSubArray[ComputopApiConfig::ADDRESS_ZIP] = $computopPayPalPaymentTransfer->getAddressZip();
151
        $dataSubArray[ComputopApiConfig::ADDRESS_COUNTRY_CODE] = $computopPayPalPaymentTransfer->getAddressCountryCode();
152
153
        if ($computopPayPalPaymentTransfer->getPhone()) {
154
            $dataSubArray[ComputopApiConfig::PHONE] = $computopPayPalPaymentTransfer->getPhone();
155
        }
156
157
        return $dataSubArray;
158
    }
159
}
160