|
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\Handler; |
|
9
|
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
11
|
|
|
use SprykerEco\Shared\Heidelpay\HeidelpayConfig; |
|
12
|
|
|
use SprykerEco\Yves\Heidelpay\Dependency\Client\HeidelpayToCalculationClientInterface; |
|
13
|
|
|
use SprykerEco\Yves\Heidelpay\Dependency\Client\HeidelpayToQuoteClientInterface; |
|
14
|
|
|
|
|
15
|
|
|
class HeidelpayDirectDebitHandler extends HeidelpayHandler |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var \SprykerEco\Yves\Heidelpay\Dependency\Client\HeidelpayToCalculationClientInterface |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $calculationClient; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \SprykerEco\Yves\Heidelpay\Dependency\Client\HeidelpayToQuoteClientInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $quoteClient; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param \SprykerEco\Yves\Heidelpay\Dependency\Client\HeidelpayToCalculationClientInterface $calculationClient |
|
29
|
|
|
* @param \SprykerEco\Yves\Heidelpay\Dependency\Client\HeidelpayToQuoteClientInterface $quoteClient |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct( |
|
32
|
|
|
HeidelpayToCalculationClientInterface $calculationClient, |
|
33
|
|
|
HeidelpayToQuoteClientInterface $quoteClient |
|
34
|
|
|
) { |
|
35
|
|
|
$this->calculationClient = $calculationClient; |
|
36
|
|
|
$this->quoteClient = $quoteClient; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
|
41
|
|
|
* |
|
42
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
|
43
|
|
|
*/ |
|
44
|
|
|
public function addPaymentToQuote(QuoteTransfer $quoteTransfer): QuoteTransfer |
|
45
|
|
|
{ |
|
46
|
|
|
$quoteTransfer = parent::addPaymentToQuote($quoteTransfer); |
|
47
|
|
|
|
|
48
|
|
|
$quoteTransfer = $this->addCurrentRegistrationToQuote($quoteTransfer); |
|
49
|
|
|
$quoteTransfer = $this->calculationClient->recalculate($quoteTransfer); |
|
50
|
|
|
$this->quoteClient->setQuote($quoteTransfer); |
|
51
|
|
|
|
|
52
|
|
|
return $quoteTransfer; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
|
57
|
|
|
* |
|
58
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function addCurrentRegistrationToQuote(QuoteTransfer $quoteTransfer): QuoteTransfer |
|
61
|
|
|
{ |
|
62
|
|
|
$directDebitPayment = $quoteTransfer->getPayment()->getHeidelpayDirectDebit(); |
|
63
|
|
|
|
|
64
|
|
|
if ($directDebitPayment->getSelectedPaymentOption() !== HeidelpayConfig::DIRECT_DEBIT_PAYMENT_OPTION_EXISTING_REGISTRATION) { |
|
65
|
|
|
return $quoteTransfer; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$directDebitPayment->setSelectedRegistration( |
|
69
|
|
|
$directDebitPayment->getPaymentOptions()->getLastSuccessfulRegistration() |
|
70
|
|
|
); |
|
71
|
|
|
|
|
72
|
|
|
$quoteTransfer->getPayment()->setHeidelpayDirectDebit($directDebitPayment); |
|
73
|
|
|
|
|
74
|
|
|
return $quoteTransfer; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|