Passed
Push — feature/eco-3623-payone-pay-u-... ( 45545e...b801a4 )
by Roman
05:02
created

PayuCeeSingleMapper::replaceForbiddenCharacters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
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\ComputopPayuCeeSinglePaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...eeSinglePaymentTransfer 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\Yves\Computop\Mapper\Init\AbstractMapper;
16
use SprykerEco\Yves\Computop\Plugin\Router\ComputopRouteProviderPlugin;
17
18
class PayuCeeSingleMapper extends AbstractMapper
19
{
20
    /**
21
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
22
     *
23
     * @return \Generated\Shared\Transfer\ComputopPayuCeeSinglePaymentTransfer
24
     */
25
    public function createComputopPaymentTransfer(QuoteTransfer $quoteTransfer): ComputopPayuCeeSinglePaymentTransfer
26
    {
27
        /** @var \Generated\Shared\Transfer\ComputopPayuCeeSinglePaymentTransfer $computopPaymentTransfer */
28
        $computopPaymentTransfer = parent::createComputopPaymentTransfer($quoteTransfer);
29
30
        $computopPaymentTransfer->setMac(
31
            $this->computopApiService->generateEncryptedMac($this->createRequestTransfer($computopPaymentTransfer))
32
        );
33
34
        $computopPaymentTransfer->setOrderDesc(
35
            $this->computopApiService->getDescriptionValue($quoteTransfer->getItems()->getArrayCopy())
36
        );
37
38
        if ($quoteTransfer->getItems()->count()) {
39
            $computopPaymentTransfer->setArticleList($this->getArticleList($quoteTransfer->getItems()));
40
        }
41
42
        if ($quoteTransfer->getCustomer()) {
43
            $this->setCustomerData($computopPaymentTransfer, $quoteTransfer->getCustomer());
44
        }
45
46
        $computopPaymentTransfer->setCapture(
47
            $this->getCaptureType(ComputopSharedConfig::PAYMENT_METHOD_PAYU_CEE_SINGLE)
48
        );
49
50
        $computopPaymentTransfer->setLanguage(mb_strtoupper($this->store->getCurrentLanguage()));
51
52
        return $computopPaymentTransfer;
53
    }
54
55
    /**
56
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
57
     *
58
     * @return \Generated\Shared\Transfer\ComputopPayuCeeSinglePaymentTransfer
59
     */
60
    protected function createTransferWithUnencryptedValues(QuoteTransfer $quoteTransfer): ComputopPayuCeeSinglePaymentTransfer
61
    {
62
        $computopPaymentTransfer = new ComputopPayuCeeSinglePaymentTransfer();
63
64
        $computopPaymentTransfer->setTransId($this->generateTransId($quoteTransfer));
65
        $computopPaymentTransfer->setUrlSuccess(
66
            $this->router->generate(ComputopRouteProviderPlugin::PAYU_CEE_SINGLE_SUCCESS, [], Router::ABSOLUTE_URL)
67
        );
68
69
        return $computopPaymentTransfer;
70
    }
71
72
    /**
73
     * @param \ArrayObject|\Generated\Shared\Transfer\ItemTransfer[] $items
74
     * @phpstan-param \ArrayObject<int, \Generated\Shared\Transfer\ItemTransfer> $items
75
     *
76
     * @return string
77
     */
78
    protected function getArticleList($items): string
79
    {
80
        $out = [];
81
        foreach ($items as $item) {
82
            $out[] = implode(',', [
83
                $this->replaceForbiddenCharacters($item->getName()),
84
                $item->getUnitPrice(),
85
                $item->getQuantity(),
86
            ]);
87
        }
88
89
        return implode('+', $out);
90
    }
91
92
    /**
93
     * @param \Generated\Shared\Transfer\ComputopPayuCeeSinglePaymentTransfer $paymentTransfer
94
     * @param \Generated\Shared\Transfer\CustomerTransfer $customer
95
     *
96
     * @return \Generated\Shared\Transfer\ComputopPayuCeeSinglePaymentTransfer
97
     */
98
    protected function setCustomerData(
99
        ComputopPayuCeeSinglePaymentTransfer $paymentTransfer,
100
        CustomerTransfer $customer
101
    ): ComputopPayuCeeSinglePaymentTransfer {
102
        $paymentTransfer->setFirstName($customer->getFirstName());
103
        $paymentTransfer->setLastName($customer->getLastName());
104
        $paymentTransfer->setEmail($customer->getEmail());
105
        $paymentTransfer->setPhone($customer->getPhone());
106
107
        return $paymentTransfer;
108
    }
109
110
    /**
111
     * @param string $name
112
     *
113
     * @return string
114
     */
115
    protected function replaceForbiddenCharacters(string $name): string
116
    {
117
        return str_replace([',', '+'], ' ', $name);
118
    }
119
}
120