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