1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\Computop\Business\Hook; |
9
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\CheckoutResponseTransfer; |
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\ComputopInitPaymentTransfer; |
|
|
|
|
12
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
|
|
|
13
|
|
|
use Spryker\Shared\Kernel\Transfer\TransferInterface; |
14
|
|
|
use SprykerEco\Shared\Computop\ComputopConfig as ConputopSharedConfig; |
15
|
|
|
use SprykerEco\Zed\Computop\Business\Exception\ComputopMethodMapperException; |
16
|
|
|
use SprykerEco\Zed\Computop\Business\Exception\PaymentMethodNotFoundException; |
17
|
|
|
use SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface; |
18
|
|
|
use SprykerEco\Zed\Computop\ComputopConfig; |
19
|
|
|
|
20
|
|
|
class ComputopPostSaveHook implements ComputopPostSaveHookInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var \SprykerEco\Zed\Computop\ComputopConfig |
24
|
|
|
*/ |
25
|
|
|
protected $config; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface[] |
29
|
|
|
*/ |
30
|
|
|
protected $methodMappers = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param \SprykerEco\Zed\Computop\ComputopConfig $config |
34
|
|
|
*/ |
35
|
|
|
public function __construct(ComputopConfig $config) |
36
|
|
|
{ |
37
|
|
|
$this->config = $config; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface $paymentMethod |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function registerMapper(InitMapperInterface $paymentMethod) |
46
|
|
|
{ |
47
|
|
|
$this->methodMappers[$paymentMethod->getMethodName()] = $paymentMethod; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
52
|
|
|
* @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponseTransfer |
53
|
|
|
* |
54
|
|
|
* @return \Generated\Shared\Transfer\CheckoutResponseTransfer |
55
|
|
|
*/ |
56
|
|
|
public function execute(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponseTransfer) |
57
|
|
|
{ |
58
|
|
|
$quoteTransfer->setOrderReference($checkoutResponseTransfer->getSaveOrder()->getOrderReference()); |
59
|
|
|
$computopPaymentTransfer = $this->getPaymentTransfer($quoteTransfer); |
60
|
|
|
|
61
|
|
|
if ( |
62
|
|
|
$quoteTransfer->getPayment()->getPaymentSelection() !== ConputopSharedConfig::PAYMENT_METHOD_PAY_NOW |
63
|
|
|
&& $quoteTransfer->getPayment()->getPaymentSelection() !== ConputopSharedConfig::PAYMENT_METHOD_EASY_CREDIT |
64
|
|
|
&& $quoteTransfer->getPayment()->getPaymentSelection() !== ConputopSharedConfig::PAYMENT_METHOD_CREDIT_CARD |
65
|
|
|
) { |
66
|
|
|
return $this->setRedirect($computopPaymentTransfer, $checkoutResponseTransfer); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$checkoutResponseTransfer->setComputopInitPayment( |
70
|
|
|
(new ComputopInitPaymentTransfer()) |
71
|
|
|
->setData($computopPaymentTransfer->getData()) |
|
|
|
|
72
|
|
|
->setLen($computopPaymentTransfer->getLen()) |
|
|
|
|
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
return $checkoutResponseTransfer; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param \Spryker\Shared\Kernel\Transfer\TransferInterface $computopPaymentTransfer |
80
|
|
|
* @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponseTransfer |
81
|
|
|
* |
82
|
|
|
* @return \Generated\Shared\Transfer\CheckoutResponseTransfer |
83
|
|
|
*/ |
84
|
|
|
protected function setRedirect(TransferInterface $computopPaymentTransfer, CheckoutResponseTransfer $checkoutResponseTransfer) |
85
|
|
|
{ |
86
|
|
|
$checkoutResponseTransfer |
87
|
|
|
->setIsExternalRedirect(true) |
88
|
|
|
->setRedirectUrl($computopPaymentTransfer->getUrl()); |
|
|
|
|
89
|
|
|
|
90
|
|
|
return $checkoutResponseTransfer; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $methodName |
95
|
|
|
* |
96
|
|
|
* @throws \SprykerEco\Zed\Computop\Business\Exception\ComputopMethodMapperException |
97
|
|
|
* |
98
|
|
|
* @return \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface |
99
|
|
|
*/ |
100
|
|
|
protected function getMethodMapper($methodName) |
101
|
|
|
{ |
102
|
|
|
if (isset($this->methodMappers[$methodName]) === false) { |
103
|
|
|
throw new ComputopMethodMapperException('The method mapper is not registered.'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $this->methodMappers[$methodName]; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
111
|
|
|
* |
112
|
|
|
* @throws \SprykerEco\Zed\Computop\Business\Exception\PaymentMethodNotFoundException |
113
|
|
|
* |
114
|
|
|
* @return \Spryker\Shared\Kernel\Transfer\TransferInterface |
115
|
|
|
*/ |
116
|
|
|
protected function getPaymentTransfer(QuoteTransfer $quoteTransfer) |
117
|
|
|
{ |
118
|
|
|
$paymentSelection = $quoteTransfer->getPayment()->getPaymentSelection(); |
119
|
|
|
|
120
|
|
|
$paymentMethod = ucfirst($paymentSelection); |
121
|
|
|
$method = 'get' . $paymentMethod; |
122
|
|
|
$paymentTransfer = $quoteTransfer->getPayment(); |
123
|
|
|
|
124
|
|
|
if (!method_exists($paymentTransfer, $method) || ($quoteTransfer->getPayment()->$method() === null)) { |
125
|
|
|
throw new PaymentMethodNotFoundException(sprintf('Selected payment method "%s" not found in PaymentTransfer', $paymentMethod)); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$computopPaymentTransfer = $quoteTransfer->getPayment()->$method(); |
129
|
|
|
$computopPaymentTransfer = $this->getMethodMapper($paymentSelection)->updateComputopPaymentTransfer($quoteTransfer, $computopPaymentTransfer); |
130
|
|
|
|
131
|
|
|
return $computopPaymentTransfer; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths