Completed
Push — master ( 9db63e...40913a )
by Oleksandr
24s queued 13s
created

KlarnaController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 17
c 1
b 0
f 0
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTokenAction() 0 9 1
A createPayoneKlarnaStartSessionRequestTransfer() 0 10 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\Payone\Controller;
9
10
use Generated\Shared\Transfer\PayoneKlarnaStartSessionRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...tSessionRequestTransfer 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 Spryker\Yves\Kernel\Controller\AbstractController;
12
use Symfony\Component\HttpFoundation\JsonResponse;
13
use Symfony\Component\HttpFoundation\Request;
14
15
/**
16
 * @method \SprykerEco\Client\Payone\PayoneClientInterface getClient()
17
 * @method \SprykerEco\Yves\Payone\PayoneFactory getFactory()
18
 */
19
class KlarnaController extends AbstractController
20
{
21
    protected const REQUEST_PARAMETER_PAY_METHOD = 'pay_method';
22
    protected const RESPONSE_PARAMETER_IS_VALID = 'is_valid';
23
    protected const RESPONSE_PARAMETER_ERROR_MESSAGE = 'error_message';
24
    protected const RESPONSE_PARAMETER_CLIENT_TOKEN = 'client_token';
25
26
    /**
27
     * @param \Symfony\Component\HttpFoundation\Request $request
28
     *
29
     * @return \Symfony\Component\HttpFoundation\JsonResponse
30
     */
31
    public function getTokenAction(Request $request): JsonResponse
32
    {
33
        $payoneKlarnaStartSessionRequestTransfer = $this->createPayoneKlarnaStartSessionRequestTransfer($request);
34
        $payoneKlarnaStartSessionResponseTransfer = $this->getClient()->sendKlarnaStartSessionRequest($payoneKlarnaStartSessionRequestTransfer);
35
36
        return $this->jsonResponse([
37
            self::RESPONSE_PARAMETER_IS_VALID => $payoneKlarnaStartSessionResponseTransfer->getIsSuccessful(),
38
            self::RESPONSE_PARAMETER_ERROR_MESSAGE => $payoneKlarnaStartSessionResponseTransfer->getErrorMessage(),
39
            self::RESPONSE_PARAMETER_CLIENT_TOKEN => $payoneKlarnaStartSessionResponseTransfer->getToken(),
40
        ]);
41
    }
42
43
    /**
44
     * @param \Symfony\Component\HttpFoundation\Request $request
45
     *
46
     * @return \Generated\Shared\Transfer\PayoneKlarnaStartSessionRequestTransfer
47
     */
48
    protected function createPayoneKlarnaStartSessionRequestTransfer(Request $request): PayoneKlarnaStartSessionRequestTransfer
49
    {
50
        $quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote();
51
        $payMethod = $request->request->get(self::REQUEST_PARAMETER_PAY_METHOD);
52
53
        $payoneKlarnaStartSessionRequestTransfer = new PayoneKlarnaStartSessionRequestTransfer();
54
        $payoneKlarnaStartSessionRequestTransfer->setQuote($quoteTransfer);
55
        $payoneKlarnaStartSessionRequestTransfer->setPayMethod($payMethod);
56
57
        return $payoneKlarnaStartSessionRequestTransfer;
58
    }
59
}
60