Passed
Pull Request — master (#47)
by Aleksey
04:38
created

DirectDebitNewRegistration   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 18
c 1
b 0
f 0
dl 0
loc 77
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A isOptionAvailableForQuote() 0 3 1
A addPaymentOption() 0 15 2
A registerQuote() 0 6 1
A createPaymentOptionTransfer() 0 4 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\Zed\Heidelpay\Business\Payment\DirectDebit\PaymentOption;
9
10
use Generated\Shared\Transfer\HeidelpayDirectDebitPaymentOptionsTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...tPaymentOptionsTransfer 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\HeidelpayPaymentOptionTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...ayPaymentOptionTransfer 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 Generated\Shared\Transfer\HeidelpayResponseTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...idelpayResponseTransfer 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...
13
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...
14
use SprykerEco\Shared\Heidelpay\HeidelpayConfig;
15
use SprykerEco\Zed\Heidelpay\Business\Adapter\Payment\DirectDebitPaymentInterface;
16
use SprykerEco\Zed\Heidelpay\Business\Payment\Request\AdapterRequestFromQuoteBuilderInterface;
17
18
class DirectDebitNewRegistration implements DirectDebitPaymentOptionInterface
19
{
20
    /**
21
     * @var \SprykerEco\Zed\Heidelpay\Business\Payment\Request\AdapterRequestFromQuoteBuilderInterface
22
     */
23
    protected $adapterRequestBuilder;
24
25
    /**
26
     * @var \SprykerEco\Zed\Heidelpay\Business\Adapter\Payment\DirectDebitPaymentInterface
27
     */
28
    protected $directDebitPayment;
29
30
    /**
31
     * @param \SprykerEco\Zed\Heidelpay\Business\Payment\Request\AdapterRequestFromQuoteBuilderInterface $adapterRequestBuilder
32
     * @param \SprykerEco\Zed\Heidelpay\Business\Adapter\Payment\DirectDebitPaymentInterface $directDebitPayment
33
     */
34
    public function __construct(
35
        AdapterRequestFromQuoteBuilderInterface $adapterRequestBuilder,
36
        DirectDebitPaymentInterface $directDebitPayment
37
    ) {
38
        $this->adapterRequestBuilder = $adapterRequestBuilder;
39
        $this->directDebitPayment = $directDebitPayment;
40
    }
41
42
    /**
43
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
44
     * @param \Generated\Shared\Transfer\HeidelpayDirectDebitPaymentOptionsTransfer $paymentOptionsTransfer
45
     *
46
     * @return \Generated\Shared\Transfer\HeidelpayDirectDebitPaymentOptionsTransfer
47
     */
48
    public function addPaymentOption(
49
        QuoteTransfer $quoteTransfer,
50
        HeidelpayDirectDebitPaymentOptionsTransfer $paymentOptionsTransfer
51
    ): HeidelpayDirectDebitPaymentOptionsTransfer {
52
        $registrationResponseTransfer = $this->registerQuote($quoteTransfer);
53
54
        if ($registrationResponseTransfer->getIsError()) {
55
            return $paymentOptionsTransfer;
56
        }
57
58
        $paymentOptionsTransfer
59
            ->addOption($this->createPaymentOptionTransfer())
60
            ->setPaymentFormActionUrl($registrationResponseTransfer->getPaymentFormUrl());
61
62
        return $paymentOptionsTransfer;
63
    }
64
65
    /**
66
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
67
     *
68
     * @return bool
69
     */
70
    public function isOptionAvailableForQuote(QuoteTransfer $quoteTransfer): bool
71
    {
72
        return true;
73
    }
74
75
    /**
76
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
77
     *
78
     * @return \Generated\Shared\Transfer\HeidelpayResponseTransfer
79
     */
80
    protected function registerQuote(QuoteTransfer $quoteTransfer): HeidelpayResponseTransfer
81
    {
82
        $registrationRequestTransfer = $this->adapterRequestBuilder->buildDirectDebitRegistrationRequest($quoteTransfer);
83
        $registrationResponseTransfer = $this->directDebitPayment->register($registrationRequestTransfer);
84
85
        return $registrationResponseTransfer;
86
    }
87
88
    /**
89
     * @return \Generated\Shared\Transfer\HeidelpayPaymentOptionTransfer
90
     */
91
    protected function createPaymentOptionTransfer(): HeidelpayPaymentOptionTransfer
92
    {
93
        return (new HeidelpayPaymentOptionTransfer())
94
            ->setCode(HeidelpayConfig::DIRECT_DEBIT_PAYMENT_OPTION_NEW_REGISTRATION);
95
    }
96
}
97