CreditCardPaymentOptionsToQuote   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasQuoteCreditCardPayment() 0 3 1
A __construct() 0 3 1
A hydrateCreditCardPaymentOptions() 0 6 1
A hydrate() 0 7 2
A initCreditCardPayment() 0 6 1
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\Hydrator;
9
10
use Generated\Shared\Transfer\HeidelpayCreditCardPaymentOptionsTransfer;
11
use Generated\Shared\Transfer\HeidelpayCreditCardPaymentTransfer;
12
use Generated\Shared\Transfer\QuoteTransfer;
13
use SprykerEco\Client\Heidelpay\HeidelpayClientInterface;
14
15
class CreditCardPaymentOptionsToQuote implements CreditCardPaymentOptionsToQuoteInterface
16
{
17
    /**
18
     * @var \SprykerEco\Client\Heidelpay\HeidelpayClientInterface
19
     */
20
    private $heidelpayClient;
21
22
    /**
23
     * @param \SprykerEco\Client\Heidelpay\HeidelpayClientInterface $heidelpayClient
24
     */
25
    public function __construct(HeidelpayClientInterface $heidelpayClient)
26
    {
27
        $this->heidelpayClient = $heidelpayClient;
28
    }
29
30
    /**
31
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
32
     *
33
     * @return void
34
     */
35
    public function hydrate(QuoteTransfer $quoteTransfer): void
36
    {
37
        if (!$this->hasQuoteCreditCardPayment($quoteTransfer)) {
38
            $this->initCreditCardPayment($quoteTransfer);
39
        }
40
41
        $this->hydrateCreditCardPaymentOptions($quoteTransfer);
42
    }
43
44
    /**
45
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
46
     *
47
     * @return bool
48
     */
49
    protected function hasQuoteCreditCardPayment(QuoteTransfer $quoteTransfer): bool
50
    {
51
        return $quoteTransfer->getPayment()->getHeidelpayCreditCardSecure() !== null;
52
    }
53
54
    /**
55
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
56
     *
57
     * @return void
58
     */
59
    protected function hydrateCreditCardPaymentOptions(QuoteTransfer $quoteTransfer): void
60
    {
61
        $creditCardPaymentOptionsTransfer = $this->heidelpayClient->getCreditCardPaymentOptions($quoteTransfer);
62
63
        $quotePayment = $quoteTransfer->getPayment()->getHeidelpayCreditCardSecure();
64
        $quotePayment->setPaymentOptions($creditCardPaymentOptionsTransfer);
65
    }
66
67
    /**
68
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
69
     *
70
     * @return void
71
     */
72
    protected function initCreditCardPayment(QuoteTransfer $quoteTransfer): void
73
    {
74
        $creditCardPaymentTransfer = (new HeidelpayCreditCardPaymentTransfer())
75
            ->setPaymentOptions(new HeidelpayCreditCardPaymentOptionsTransfer());
76
77
        $quoteTransfer->getPayment()->setHeidelpayCreditCardSecure($creditCardPaymentTransfer);
78
    }
79
}
80