HeidelpayEasycreditInitializeStep::execute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 7
c 2
b 0
f 1
dl 0
loc 13
rs 10
cc 3
nc 3
nop 2
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Yves\Heidelpay\CheckoutPage\Process\Steps;
9
10
use Generated\Shared\Transfer\HeidelpayPaymentTransfer;
11
use Generated\Shared\Transfer\HeidelpayResponseTransfer;
12
use Generated\Shared\Transfer\PaymentTransfer;
13
use Generated\Shared\Transfer\QuoteTransfer;
14
use Spryker\Shared\Kernel\Transfer\AbstractTransfer;
15
use SprykerEco\Client\Heidelpay\HeidelpayClientInterface;
16
use SprykerEco\Shared\Heidelpay\HeidelpayConfig;
17
use SprykerShop\Yves\CheckoutPage\Process\Steps\AbstractBaseStep;
18
use Symfony\Component\HttpFoundation\Request;
19
20
class HeidelpayEasycreditInitializeStep extends AbstractBaseStep
21
{
22
    /**
23
     * @var \SprykerEco\Client\Heidelpay\HeidelpayClientInterface
24
     */
25
    protected $heidelpayClient;
26
27
    /**
28
     * @var string
29
     */
30
    protected $externalRedirectUrl;
31
32
    /**
33
     * @param string $stepRoute
34
     * @param string $escapeRoute
35
     * @param \SprykerEco\Client\Heidelpay\HeidelpayClientInterface $heidelpayClient
36
     */
37
    public function __construct(
38
        string $stepRoute,
39
        string $escapeRoute,
40
        HeidelpayClientInterface $heidelpayClient
41
    ) {
42
        parent::__construct($stepRoute, $escapeRoute);
43
44
        $this->heidelpayClient = $heidelpayClient;
45
    }
46
47
    /**
48
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer $quoteTransfer
49
     *
50
     * @return bool
51
     */
52
    public function requireInput(AbstractTransfer $quoteTransfer)
53
    {
54
        return false;
55
    }
56
57
    /**
58
     * @param \Symfony\Component\HttpFoundation\Request $request
59
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
60
     *
61
     * @return \Generated\Shared\Transfer\QuoteTransfer|\Spryker\Shared\Kernel\Transfer\AbstractTransfer
62
     */
63
    public function execute(Request $request, AbstractTransfer $quoteTransfer)
64
    {
65
        $easyCreditInitializeResponse = $this->getEasyCreditInitializeResponse($quoteTransfer);
66
67
        if ($easyCreditInitializeResponse->getIsSuccess() === true) {
68
            if (!$quoteTransfer->getHeidelpayPayment()) {
0 ignored issues
show
Bug introduced by
The method getHeidelpayPayment() does not exist on Spryker\Shared\Kernel\Transfer\AbstractTransfer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
            if (!$quoteTransfer->/** @scrutinizer ignore-call */ getHeidelpayPayment()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
                $quoteTransfer->setHeidelpayPayment(new HeidelpayPaymentTransfer());
0 ignored issues
show
Bug introduced by
The method setHeidelpayPayment() does not exist on Spryker\Shared\Kernel\Transfer\AbstractTransfer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
                $quoteTransfer->/** @scrutinizer ignore-call */ 
70
                                setHeidelpayPayment(new HeidelpayPaymentTransfer());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
70
            }
71
            $quoteTransfer->getHeidelpayPayment()->setLegalText($easyCreditInitializeResponse->getLegalText());
72
            $quoteTransfer->getHeidelpayPayment()->setExternalRedirectUrl($easyCreditInitializeResponse->getPaymentFormUrl());
73
        }
74
75
        return $quoteTransfer;
76
    }
77
78
    /**
79
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer|\Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
80
     *
81
     * @return bool
82
     */
83
    public function postCondition(AbstractTransfer $quoteTransfer)
84
    {
85
        return true;
86
    }
87
88
    /**
89
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
90
     *
91
     * @return \Generated\Shared\Transfer\HeidelpayResponseTransfer
92
     */
93
    protected function getEasyCreditInitializeResponse(QuoteTransfer $quoteTransfer): HeidelpayResponseTransfer
94
    {
95
        $quoteTransferMock = clone($quoteTransfer);
96
        $quoteTransferMock->setPayment(
97
            (new PaymentTransfer())
98
                ->setPaymentMethod(HeidelpayConfig::PAYMENT_METHOD_EASY_CREDIT)
99
        );
100
101
        return $this->heidelpayClient->sendHeidelpayEasycreditInitializeRequest($quoteTransferMock);
102
    }
103
}
104