Passed
Pull Request — feature/eco-3656/dev-paypal-ex... (#40)
by
unknown
07:17
created

PayPalExpressMapper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 51
dl 0
loc 109
rs 10
c 2
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A mapAddressFromQuoteToComputopPayPalPayment() 0 23 3
A createComputopPaymentTransfer() 0 21 1
A createTransferWithUnencryptedValues() 0 20 1
A getDataSubArray() 0 16 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\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 PayPalExpressMapper extends AbstractMapper
19
{
20
    /**
21
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
22
     *
23
     * @return \Generated\Shared\Transfer\ComputopPayPalExpressPaymentTransfer
24
     */
25
    public function createComputopPaymentTransfer(QuoteTransfer $quoteTransfer)
26
    {
27
        /** @var \Generated\Shared\Transfer\ComputopPayPalExpressPaymentTransfer $computopPaymentTransfer */
28
        $computopPaymentTransfer = parent::createComputopPaymentTransfer($quoteTransfer);
29
30
        $computopPaymentTransfer->setPayPalMethod($this->config->getPayPalMethod());
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
45
        return $computopPaymentTransfer;
46
    }
47
48
    /**
49
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
50
     *
51
     * @return \Generated\Shared\Transfer\ComputopPayPalExpressPaymentTransfer
52
     */
53
    protected function createTransferWithUnencryptedValues(QuoteTransfer $quoteTransfer): ComputopPayPalExpressPaymentTransfer
54
    {
55
        $computopPaymentTransfer = new ComputopPayPalExpressPaymentTransfer();
56
57
        $computopPaymentTransfer->setCapture(
58
            $this->getCaptureType(ComputopSharedConfig::PAYMENT_METHOD_PAY_PAL_EXPRESS)
59
        );
60
        $computopPaymentTransfer->setTransId($this->generateTransId($quoteTransfer));
61
        $computopPaymentTransfer->setTxType($this->config->getPayPalTxType());
62
63
        $computopPaymentTransfer->setUrlSuccess(
64
            $this->router->generate(ComputopRouteProviderPlugin::ROUTE_NAME_PAY_PAL_EXPRESS_PLACE_ORDER, [], Router::ABSOLUTE_URL)
65
        );
66
        $computopPaymentTransfer->setOrderDesc(
67
            $this->computopApiService->getDescriptionValue($quoteTransfer->getItems()->getArrayCopy())
68
        );
69
70
        $this->mapAddressFromQuoteToComputopPayPalPayment($quoteTransfer, $computopPaymentTransfer);
71
72
        return $computopPaymentTransfer;
73
    }
74
75
    /**
76
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
77
     * @param \Generated\Shared\Transfer\ComputopPayPalPaymentTransfer $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...
78
     *
79
     * @return \Generated\Shared\Transfer\ComputopPayPalPaymentTransfer
80
     */
81
    protected function mapAddressFromQuoteToComputopPayPalPayment(
82
        QuoteTransfer $quoteTransfer,
83
        ComputopPayPalExpressPaymentTransfer $computopPayPalPaymentTransfer
84
    ): ComputopPayPalExpressPaymentTransfer {
85
        $addressTransfer = $quoteTransfer->getBillingSameAsShipping() ?
86
            $quoteTransfer->getBillingAddress() : $quoteTransfer->getShippingAddress();
87
88
        if (!$addressTransfer) {
89
            return $computopPayPalPaymentTransfer;
90
        }
91
92
        $computopPayPalPaymentTransfer
93
            ->setFirstName($addressTransfer->getFirstName())
94
            ->setLastName($addressTransfer->getLastName())
95
            ->setAddressStreet($addressTransfer->getAddress1())
96
            ->setAddressStreet2($addressTransfer->getAddress2())
97
            ->setAddressCity($addressTransfer->getCity())
98
            ->setAddressState($addressTransfer->getState())
99
            ->setAddressZip($addressTransfer->getZipCode())
100
            ->setAddressCountryCode($addressTransfer->getIso2Code())
101
            ->setPhone($addressTransfer->getPhone());
102
103
        return $computopPayPalPaymentTransfer;
104
    }
105
106
    /**
107
     * @param \Generated\Shared\Transfer\ComputopPayPalExpressPaymentTransfer $computopPayPalPaymentTransfer
108
     *
109
     * @return array
110
     */
111
    protected function getDataSubArray(ComputopPayPalExpressPaymentTransfer $computopPayPalPaymentTransfer): array
112
    {
113
        $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...
114
        $dataSubArray[ComputopApiConfig::AMOUNT] = $computopPayPalPaymentTransfer->getAmount();
115
        $dataSubArray[ComputopApiConfig::CURRENCY] = $computopPayPalPaymentTransfer->getCurrency();
116
        $dataSubArray[ComputopApiConfig::CAPTURE] = $computopPayPalPaymentTransfer->getCapture();
117
        $dataSubArray[ComputopApiConfig::TX_TYPE] = $computopPayPalPaymentTransfer->getTxType();
118
        $dataSubArray[ComputopApiConfig::PAY_PAL_METHOD] = $computopPayPalPaymentTransfer->getPayPalMethod();
119
        $dataSubArray[ComputopApiConfig::ORDER_DESC] = $computopPayPalPaymentTransfer->getOrderDesc();
120
        $dataSubArray[ComputopApiConfig::URL_SUCCESS] = $computopPayPalPaymentTransfer->getUrlSuccess();
121
        $dataSubArray[ComputopApiConfig::URL_NOTIFY] = $computopPayPalPaymentTransfer->getUrlNotify();
122
        $dataSubArray[ComputopApiConfig::URL_FAILURE] = $computopPayPalPaymentTransfer->getUrlFailure();
123
        $dataSubArray[ComputopApiConfig::RESPONSE] = $computopPayPalPaymentTransfer->getResponse();
124
        $dataSubArray[ComputopApiConfig::MAC] = $computopPayPalPaymentTransfer->getMac();
125
126
        return $dataSubArray;
127
    }
128
}
129