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\PaymentMethodNotFoundException; |
16
|
|
|
use SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface; |
17
|
|
|
use SprykerEco\Zed\Computop\ComputopConfig; |
18
|
|
|
|
19
|
|
|
class ComputopPostSaveHook implements ComputopPostSaveHookInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var \SprykerEco\Zed\Computop\ComputopConfig |
23
|
|
|
*/ |
24
|
|
|
protected $config; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface[] |
28
|
|
|
*/ |
29
|
|
|
protected $methodMappers = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param \SprykerEco\Zed\Computop\ComputopConfig $config |
33
|
|
|
*/ |
34
|
|
|
public function __construct(ComputopConfig $config) |
35
|
|
|
{ |
36
|
|
|
$this->config = $config; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface $paymentMethod |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
public function registerMapper(InitMapperInterface $paymentMethod) |
45
|
|
|
{ |
46
|
|
|
$this->methodMappers[$paymentMethod->getMethodName()] = $paymentMethod; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
51
|
|
|
* @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponseTransfer |
52
|
|
|
* |
53
|
|
|
* @return \Generated\Shared\Transfer\CheckoutResponseTransfer |
54
|
|
|
*/ |
55
|
|
|
public function execute(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponseTransfer) |
56
|
|
|
{ |
57
|
|
|
$payment = $quoteTransfer->getPayment(); |
58
|
|
|
|
59
|
|
|
if ($payment->getPaymentProvider() !== ConputopSharedConfig::PROVIDER_NAME) { |
60
|
|
|
return $checkoutResponseTransfer; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$quoteTransfer->setOrderReference($checkoutResponseTransfer->getSaveOrder()->getOrderReference()); |
64
|
|
|
$computopPaymentTransfer = $this->getPaymentTransfer($quoteTransfer); |
65
|
|
|
|
66
|
|
|
if ($this->isPaymentInitRequired($payment)) { |
67
|
|
|
$checkoutResponseTransfer->setComputopInitPayment( |
68
|
|
|
(new ComputopInitPaymentTransfer()) |
69
|
|
|
->setData($computopPaymentTransfer->getData()) |
|
|
|
|
70
|
|
|
->setLen($computopPaymentTransfer->getLen()) |
|
|
|
|
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
return $checkoutResponseTransfer; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $this->setRedirect($computopPaymentTransfer, $checkoutResponseTransfer); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param \Spryker\Shared\Kernel\Transfer\TransferInterface $computopPaymentTransfer |
81
|
|
|
* @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponseTransfer |
82
|
|
|
* |
83
|
|
|
* @return \Generated\Shared\Transfer\CheckoutResponseTransfer |
84
|
|
|
*/ |
85
|
|
|
protected function setRedirect(TransferInterface $computopPaymentTransfer, CheckoutResponseTransfer $checkoutResponseTransfer) |
86
|
|
|
{ |
87
|
|
|
$checkoutResponseTransfer |
88
|
|
|
->setIsExternalRedirect(true) |
89
|
|
|
->setRedirectUrl($computopPaymentTransfer->getUrl()); |
|
|
|
|
90
|
|
|
|
91
|
|
|
return $checkoutResponseTransfer; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $methodName |
96
|
|
|
* |
97
|
|
|
* @return \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface|null |
98
|
|
|
*/ |
99
|
|
|
protected function getMethodMapper($methodName) |
100
|
|
|
{ |
101
|
|
|
if (isset($this->methodMappers[$methodName]) === false) { |
102
|
|
|
return null; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return $this->methodMappers[$methodName]; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
110
|
|
|
* |
111
|
|
|
* @throws \SprykerEco\Zed\Computop\Business\Exception\PaymentMethodNotFoundException |
112
|
|
|
* |
113
|
|
|
* @return \Spryker\Shared\Kernel\Transfer\TransferInterface |
114
|
|
|
*/ |
115
|
|
|
protected function getPaymentTransfer(QuoteTransfer $quoteTransfer) |
116
|
|
|
{ |
117
|
|
|
$paymentSelection = $quoteTransfer->getPayment()->getPaymentSelection(); |
118
|
|
|
|
119
|
|
|
$paymentMethod = ucfirst($paymentSelection); |
120
|
|
|
$method = 'get' . $paymentMethod; |
121
|
|
|
$paymentTransfer = $quoteTransfer->getPayment(); |
122
|
|
|
|
123
|
|
|
if (!method_exists($paymentTransfer, $method) || ($quoteTransfer->getPayment()->$method() === null)) { |
124
|
|
|
throw new PaymentMethodNotFoundException(sprintf('Selected payment method "%s" not found in PaymentTransfer', $paymentMethod)); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
$computopPaymentTransfer = $quoteTransfer->getPayment()->$method(); |
128
|
|
|
$methodMapper = $this->getMethodMapper($paymentSelection); |
129
|
|
|
if (!$methodMapper) { |
130
|
|
|
return $computopPaymentTransfer; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
return $methodMapper->updateComputopPaymentTransfer($quoteTransfer, $computopPaymentTransfer); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param \Generated\Shared\Transfer\PaymentTransfer $payment |
|
|
|
|
138
|
|
|
* |
139
|
|
|
* @return bool |
140
|
|
|
*/ |
141
|
|
|
protected function isPaymentInitRequired(PaymentTransfer $payment): bool |
|
|
|
|
142
|
|
|
{ |
143
|
|
|
return in_array($payment->getPaymentSelection(), [ |
144
|
|
|
ConputopSharedConfig::PAYMENT_METHOD_PAY_NOW, |
145
|
|
|
ConputopSharedConfig::PAYMENT_METHOD_EASY_CREDIT, |
146
|
|
|
ConputopSharedConfig::PAYMENT_METHOD_CREDIT_CARD, |
147
|
|
|
]); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
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