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

PayPalExpressMapper::getDataSubArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
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 17
rs 9.7998
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\ComputopPayPalExpressPaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...lExpressPaymentTransfer 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\CustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CustomerTransfer 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 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...
13
use Spryker\Yves\Router\Router\Router;
14
use SprykerEco\Shared\Computop\ComputopConfig as ComputopSharedConfig;
15
use SprykerEco\Shared\Computop\Config\ComputopApiConfig;
16
use SprykerEco\Yves\Computop\Mapper\Init\AbstractMapper;
17
use SprykerEco\Yves\Computop\Plugin\Router\ComputopRouteProviderPlugin;
18
19
class PayPalExpressMapper extends AbstractMapper
20
{
21
    /**
22
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
23
     *
24
     * @return \Generated\Shared\Transfer\ComputopPayPalExpressPaymentTransfer
25
     */
26
    public function createComputopPaymentTransfer(QuoteTransfer $quoteTransfer)
27
    {
28
        if ($quoteTransfer->getCustomer() === null) {
29
            $quoteTransfer->setCustomer(new CustomerTransfer());
30
        }
31
        /** @var \Generated\Shared\Transfer\ComputopPayPalExpressPaymentTransfer $computopPaymentTransfer */
32
        $computopPaymentTransfer = parent::createComputopPaymentTransfer($quoteTransfer);
33
34
        $computopPaymentTransfer->setPayPalMethod($this->config->getPayPalMethod());
35
        $computopPaymentTransfer->setMac(
36
            $this->computopApiService->generateEncryptedMac(
37
                $this->createRequestTransfer($computopPaymentTransfer),
38
            ),
39
        );
40
41
        $decryptedValues = $this->computopApiService->getEncryptedArray(
42
            $this->getDataSubArray($computopPaymentTransfer),
43
            $this->config->getBlowfishPassword(),
44
        );
45
46
        $computopPaymentTransfer->setData($decryptedValues[ComputopApiConfig::DATA]);
47
        $computopPaymentTransfer->setLen($decryptedValues[ComputopApiConfig::LENGTH]);
48
49
        return $computopPaymentTransfer;
50
    }
51
52
    /**
53
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
54
     *
55
     * @return \Generated\Shared\Transfer\ComputopPayPalExpressPaymentTransfer
56
     */
57
    protected function createTransferWithUnencryptedValues(QuoteTransfer $quoteTransfer): ComputopPayPalExpressPaymentTransfer
58
    {
59
        $computopPaymentTransfer = new ComputopPayPalExpressPaymentTransfer();
60
61
        $computopPaymentTransfer->setCapture(
62
            $this->getCaptureType(ComputopSharedConfig::PAYMENT_METHOD_PAY_PAL_EXPRESS),
63
        );
64
        $computopPaymentTransfer->setTransId($this->generateTransId($quoteTransfer));
65
        $computopPaymentTransfer->setTxType($this->config->getPayPalTxType());
66
67
        $computopPaymentTransfer->setUrlSuccess(
68
            $this->router->generate(ComputopRouteProviderPlugin::ROUTE_NAME_PAY_PAL_EXPRESS_PLACE_ORDER, [], Router::ABSOLUTE_URL),
69
        );
70
        $computopPaymentTransfer->setOrderDesc(
71
            $this->computopApiService->getDescriptionValue($quoteTransfer->getItems()->getArrayCopy()),
72
        );
73
74
        $this->mapAddressFromQuoteTransferToComputopPayPalExpressPaymentTransfer($quoteTransfer, $computopPaymentTransfer);
75
76
        return $computopPaymentTransfer;
77
    }
78
79
    /**
80
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
81
     * @param \Generated\Shared\Transfer\ComputopPayPalExpressPaymentTransfer $computopPayPalPaymentTransfer
82
     *
83
     * @return \Generated\Shared\Transfer\ComputopPayPalExpressPaymentTransfer
84
     */
85
    protected function mapAddressFromQuoteTransferToComputopPayPalExpressPaymentTransfer(
86
        QuoteTransfer $quoteTransfer,
87
        ComputopPayPalExpressPaymentTransfer $computopPayPalPaymentTransfer
88
    ): ComputopPayPalExpressPaymentTransfer {
89
        $addressTransfer = $quoteTransfer->getBillingSameAsShipping() ?
90
            $quoteTransfer->getBillingAddress() : $quoteTransfer->getShippingAddress();
91
92
        if (!$addressTransfer) {
93
            return $computopPayPalPaymentTransfer;
94
        }
95
96
        $computopPayPalPaymentTransfer
97
            ->fromArray($addressTransfer->toArray(), true)
98
            ->setAddressStreet($addressTransfer->getAddress1())
99
            ->setAddressStreet2($addressTransfer->getAddress2())
100
            ->setAddressCity($addressTransfer->getCity())
101
            ->setAddressState($addressTransfer->getState())
102
            ->setAddressZip($addressTransfer->getZipCode())
103
            ->setAddressCountryCode($addressTransfer->getIso2Code());
104
105
        return $computopPayPalPaymentTransfer;
106
    }
107
108
    /**
109
     * @param \Generated\Shared\Transfer\ComputopPayPalExpressPaymentTransfer $computopPayPalPaymentTransfer
110
     *
111
     * @return array
112
     */
113
    protected function getDataSubArray(ComputopPayPalExpressPaymentTransfer $computopPayPalPaymentTransfer): array
114
    {
115
        $dataSubArray = [];
116
        $dataSubArray[ComputopApiConfig::TRANS_ID] = $computopPayPalPaymentTransfer->getTransId();
117
        $dataSubArray[ComputopApiConfig::AMOUNT] = $computopPayPalPaymentTransfer->getAmount();
118
        $dataSubArray[ComputopApiConfig::CURRENCY] = $computopPayPalPaymentTransfer->getCurrency();
119
        $dataSubArray[ComputopApiConfig::CAPTURE] = $computopPayPalPaymentTransfer->getCapture();
120
        $dataSubArray[ComputopApiConfig::TX_TYPE] = $computopPayPalPaymentTransfer->getTxType();
121
        $dataSubArray[ComputopApiConfig::PAY_PAL_METHOD] = $computopPayPalPaymentTransfer->getPayPalMethod();
122
        $dataSubArray[ComputopApiConfig::ORDER_DESC] = $computopPayPalPaymentTransfer->getOrderDesc();
123
        $dataSubArray[ComputopApiConfig::URL_SUCCESS] = $computopPayPalPaymentTransfer->getUrlSuccess();
124
        $dataSubArray[ComputopApiConfig::URL_NOTIFY] = $computopPayPalPaymentTransfer->getUrlNotify();
125
        $dataSubArray[ComputopApiConfig::URL_FAILURE] = $computopPayPalPaymentTransfer->getUrlFailure();
126
        $dataSubArray[ComputopApiConfig::RESPONSE] = $computopPayPalPaymentTransfer->getResponse();
127
        $dataSubArray[ComputopApiConfig::MAC] = $computopPayPalPaymentTransfer->getMac();
128
129
        return $dataSubArray;
130
    }
131
}
132