Completed
Pull Request — master (#25)
by Andrey
11:08 queued 03:02
created

WidgetController::walletWidgetAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Apache OSL-2
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Yves\AmazonPay\Controller;
9
10
use Spryker\Yves\Kernel\Controller\AbstractController;
11
use Symfony\Component\HttpFoundation\Request;
12
13
/**
14
 * @method \SprykerEco\Yves\AmazonPay\AmazonPayFactory getFactory()
15
 */
16
class WidgetController extends AbstractController
17
{
18
    public const AMAZON_PAY_CONFIG = 'amazonpayConfig';
19
    public const LOGOUT = 'logout';
20
21
    /**
22
     * @param \Symfony\Component\HttpFoundation\Request $request
23
     *
24
     * @return \Spryker\Yves\Kernel\View\View
25
     */
26
    public function payButtonAction(Request $request)
27
    {
28
        $response = $this->executePayButtonAction($request);
29
30
        return $this->view($response, [], '@AmazonPay/views/pay-button/pay-button.twig');
31
    }
32
33
    /**
34
     * @param \Symfony\Component\HttpFoundation\Request $request
35
     *
36
     * @return array
37
     */
38
    protected function executePayButtonAction(Request $request)
1 ignored issue
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

38
    protected function executePayButtonAction(/** @scrutinizer ignore-unused */ Request $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
    {
40
        $isLogout = $this->isLogout();
41
42
        if ($isLogout) {
43
            $this->resetAmazonPaymentInQuote();
44
        }
45
46
        return [
47
            static::AMAZON_PAY_CONFIG => $this->getAmazonPayConfig(),
48
            static::LOGOUT => $isLogout,
49
        ];
50
    }
51
52
    /**
53
     * @return void
54
     */
55
    protected function resetAmazonPaymentInQuote()
56
    {
57
        $quoteTransfer = $this->getFactory()->getQuoteClient()->getQuote();
58
59
        $quoteTransfer->setAmazonpayPayment(null);
60
        $this->getFactory()
61
            ->getQuoteClient()
62
            ->setQuote($quoteTransfer);
63
    }
64
65
    /**
66
     * @return int
67
     */
68
    protected function isLogout()
69
    {
70
        $quote = $this->getFactory()->getQuoteClient()->getQuote();
71
72
        $isLogout = $quote->getAmazonpayPayment()
73
            && $quote->getAmazonpayPayment()->getResponseHeader()
74
            && !$quote->getAmazonpayPayment()->getResponseHeader()->getIsSuccess();
75
76
        if ($isLogout) {
77
            return 1;
78
        }
79
80
        return 0;
81
    }
82
83
    /**
84
     * @return \SprykerEco\Shared\AmazonPay\AmazonPayConfigInterface
85
     */
86
    protected function getAmazonPayConfig()
87
    {
88
        return $this->getFactory()->createAmazonPayConfig();
89
    }
90
}
91