Completed
Pull Request — dev (#22)
by Andrey
08:39 queued 04:18
created

WidgetController   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 91
rs 10
c 0
b 0
f 0
wmc 14

7 Methods

Rating   Name   Duplication   Size   Complexity  
A walletWidgetAction() 0 4 1
A isLogout() 0 7 3
A getAmazonPayConfig() 0 3 1
A getAmazonPaymentOrderReferenceId() 0 7 3
A checkoutWidgetAction() 0 10 2
A payButtonAction() 0 5 1
A isAmazonPaymentInvalid() 0 8 3
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 Generated\Shared\Transfer\QuoteTransfer;
1 ignored issue
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...
11
use Spryker\Yves\Kernel\Controller\AbstractController;
12
use SprykerEco\Shared\AmazonPay\AmazonPayConfig;
13
14
/**
15
 * @method \SprykerEco\Yves\AmazonPay\AmazonPayFactory getFactory()
16
 */
17
class WidgetController extends AbstractController
18
{
19
    const ADDRESS_BOOK_MODE = 'addressBookMode';
20
    const AMAZON_PAY_CONFIG = 'amazonpayConfig';
21
    const LOGOUT = 'logout';
22
    const QUOTE_TRANSFER = 'quoteTransfer';
23
24
    /**
25
     * @return array
26
     */
27
    public function payButtonAction()
28
    {
29
        return [
30
            static::AMAZON_PAY_CONFIG => $this->getAmazonPayConfig(),
31
            static::LOGOUT => (int)$this->isLogout(),
32
        ];
33
    }
34
35
    /**
36
     * @return bool
37
     */
38
    protected function isLogout()
39
    {
40
        $quote = $this->getFactory()->getQuoteClient()->getQuote();
41
42
        return $quote->getAmazonpayPayment()
43
            && $quote->getAmazonpayPayment()->getResponseHeader()
44
            && !$quote->getAmazonpayPayment()->getResponseHeader()->getIsSuccess();
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    public function checkoutWidgetAction()
51
    {
52
        $quoteTransfer = $this->getFactory()
53
            ->getQuoteClient()
54
            ->getQuote();
55
56
        return [
57
            static::QUOTE_TRANSFER => $this->getAmazonPaymentOrderReferenceId($quoteTransfer),
58
            static::AMAZON_PAY_CONFIG => $this->getAmazonPayConfig(),
59
            static::ADDRESS_BOOK_MODE => $this->isAmazonPaymentInvalid($quoteTransfer) ? AmazonPayConfig::DISPLAY_MODE_READONLY : null,
60
        ];
61
    }
62
63
    /**
64
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
65
     *
66
     * @return null|string
67
     */
68
    protected function getAmazonPaymentOrderReferenceId(QuoteTransfer $quoteTransfer)
69
    {
70
        if ($quoteTransfer->getAmazonpayPayment() !== null && $quoteTransfer->getAmazonpayPayment()->getOrderReferenceId() !== null) {
71
            return $quoteTransfer->getAmazonpayPayment()->getOrderReferenceId();
72
        }
73
74
        return null;
75
    }
76
77
    /**
78
     * @return array
79
     */
80
    public function walletWidgetAction()
81
    {
82
        return [
83
            static::AMAZON_PAY_CONFIG => $this->getAmazonPayConfig(),
84
        ];
85
    }
86
87
    /**
88
     * @return \SprykerEco\Shared\AmazonPay\AmazonPayConfigInterface
89
     */
90
    protected function getAmazonPayConfig()
91
    {
92
        return $this->getFactory()->createAmazonPayConfig();
93
    }
94
95
    /**
96
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
97
     *
98
     * @return bool
99
     */
100
    protected function isAmazonPaymentInvalid(QuoteTransfer $quoteTransfer)
101
    {
102
        if ($quoteTransfer->getAmazonpayPayment()->getResponseHeader() !== null
103
            && $quoteTransfer->getAmazonpayPayment()->getResponseHeader()->getIsInvalidPaymentMethod()) {
104
            return true;
105
        }
106
107
        return false;
108
    }
109
}
110