Completed
Push — master ( 56a686...736967 )
by Oleksandr
15s queued 11s
created

DirectDebitController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 33
c 1
b 0
f 0
dl 0
loc 107
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A registrationRequestAction() 0 11 2
A streamRedirectResponse() 0 7 1
A redirectToRegistrationFailureUrl() 0 9 1
A redirectToRegistrationSuccessUrl() 0 9 1
A redirectToHeidelpayPaymentFailedUrl() 0 5 1
A redirectToSummaryStep() 0 3 1
A registrationSuccessAction() 0 11 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\Controller;
9
10
use Generated\Shared\Transfer\HeidelpayDirectDebitRegistrationTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...bitRegistrationTransfer 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\HeidelpayResponseErrorTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...ayResponseErrorTransfer 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 SprykerEco\Yves\Heidelpay\Plugin\Provider\HeidelpayControllerProvider;
13
use Symfony\Component\HttpFoundation\RedirectResponse;
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\Response;
16
17
/**
18
 * @method \SprykerEco\Yves\Heidelpay\HeidelpayFactory getFactory()
19
 * @method \SprykerEco\Client\Heidelpay\HeidelpayClientInterface getClient()
20
 */
21
class DirectDebitController extends BaseHeidelpayController
22
{
23
    protected const REQUEST_PARAM_REGISTRATION_ID = 'id_registration';
24
    protected const URL_PARAM_ERROR_CODE = 'error_code';
25
    protected const PATH_CHECKOUT_SUMMARY = 'checkout-summary';
26
27
    /**
28
     * @param \Symfony\Component\HttpFoundation\Request $request
29
     *
30
     * @return \Symfony\Component\HttpFoundation\Response
31
     */
32
    public function registrationRequestAction(Request $request): Response
33
    {
34
        $directDebitRegistrationTransfer = $this->getFactory()
35
            ->createHeidelpayDirectDebitRegistrationProcessor()
36
            ->processNewRegistration($request);
37
38
        if ($directDebitRegistrationTransfer->getIsError()) {
39
            return $this->redirectToRegistrationFailureUrl($directDebitRegistrationTransfer->getError());
40
        }
41
42
        return $this->redirectToRegistrationSuccessUrl($directDebitRegistrationTransfer);
43
    }
44
45
    /**
46
     * @param \Symfony\Component\HttpFoundation\Request $request
47
     *
48
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
49
     */
50
    public function registrationSuccessAction(Request $request): RedirectResponse
51
    {
52
        $directDebitRegistrationTransfer = $this->getFactory()
53
            ->createHeidelpayDirectDebitRegistrationProcessor()
54
            ->processSuccessRegistration($request);
55
56
        if ($directDebitRegistrationTransfer->getIsError()) {
57
            return $this->redirectToHeidelpayPaymentFailedUrl($directDebitRegistrationTransfer->getError());
58
        }
59
60
        return $this->redirectToSummaryStep();
61
    }
62
63
    /**
64
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
65
     */
66
    protected function redirectToSummaryStep(): RedirectResponse
67
    {
68
        return $this->redirectResponseInternal(static::PATH_CHECKOUT_SUMMARY);
69
    }
70
71
    /**
72
     * @param \Generated\Shared\Transfer\HeidelpayResponseErrorTransfer $responseErrorTransfer
73
     *
74
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
75
     */
76
    protected function redirectToHeidelpayPaymentFailedUrl(HeidelpayResponseErrorTransfer $responseErrorTransfer): RedirectResponse
77
    {
78
        return $this->redirectResponseInternal(
79
            HeidelpayControllerProvider::HEIDELPAY_PAYMENT_FAILED,
80
            [static::URL_PARAM_ERROR_CODE => $responseErrorTransfer->getCode()]
81
        );
82
    }
83
84
    /**
85
     * @param \Generated\Shared\Transfer\HeidelpayResponseErrorTransfer $responseErrorTransfer
86
     *
87
     * @return \Symfony\Component\HttpFoundation\Response
88
     */
89
    protected function redirectToRegistrationFailureUrl(HeidelpayResponseErrorTransfer $responseErrorTransfer): Response
90
    {
91
        $redirectUrl = $this->getApplication()
92
            ->url(
93
                HeidelpayControllerProvider::HEIDELPAY_PAYMENT_FAILED,
94
                [static::URL_PARAM_ERROR_CODE => $responseErrorTransfer->getCode()]
95
            );
96
97
        return $this->streamRedirectResponse($redirectUrl);
98
    }
99
100
    /**
101
     * @param \Generated\Shared\Transfer\HeidelpayDirectDebitRegistrationTransfer $directDebitRegistrationTransfer
102
     *
103
     * @return \Symfony\Component\HttpFoundation\Response
104
     */
105
    protected function redirectToRegistrationSuccessUrl(HeidelpayDirectDebitRegistrationTransfer $directDebitRegistrationTransfer): Response
106
    {
107
        $redirectUrl = $this->getApplication()
108
            ->url(
109
                HeidelpayControllerProvider::HEIDELPAY_DIRECT_DEBIT_REGISTER_SUCCESS,
110
                [static::REQUEST_PARAM_REGISTRATION_ID => $directDebitRegistrationTransfer->getIdDirectDebitRegistration()]
111
            );
112
113
        return $this->streamRedirectResponse($redirectUrl);
114
    }
115
116
    /**
117
     * @param string $redirectUrl
118
     *
119
     * @return \Symfony\Component\HttpFoundation\Response
120
     */
121
    protected function streamRedirectResponse(string $redirectUrl): Response
122
    {
123
        $callback = function () use ($redirectUrl) {
124
            echo $redirectUrl;
125
        };
126
127
        return $this->streamedResponse($callback)->send();
128
    }
129
}
130