|
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
|
|
|
$paymentTransfer = $quoteTransfer->getPayment(); |
|
60
|
|
|
if (!$paymentTransfer || $paymentTransfer->getPaymentProvider() !== ConputopSharedConfig::PROVIDER_NAME) { |
|
61
|
|
|
return $checkoutResponseTransfer; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$quoteTransfer->setOrderReference($checkoutResponseTransfer->getSaveOrder()->getOrderReference()); |
|
65
|
|
|
$computopPaymentTransfer = $this->getPaymentTransfer($quoteTransfer); |
|
66
|
|
|
|
|
67
|
|
|
if ($this->isPaymentInitRequired($paymentTransfer)) { |
|
68
|
|
|
$checkoutResponseTransfer->setComputopInitPayment( |
|
69
|
|
|
(new ComputopInitPaymentTransfer()) |
|
70
|
|
|
->setData($computopPaymentTransfer->getData()) |
|
|
|
|
|
|
71
|
|
|
->setLen($computopPaymentTransfer->getLen()) |
|
|
|
|
|
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
return $checkoutResponseTransfer; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $this->setRedirect($computopPaymentTransfer, $checkoutResponseTransfer); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param \Generated\Shared\Transfer\PaymentTransfer $computopPaymentTransfer |
|
82
|
|
|
* @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponseTransfer |
|
83
|
|
|
* |
|
84
|
|
|
* @return \Generated\Shared\Transfer\CheckoutResponseTransfer |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function setRedirect(TransferInterface $computopPaymentTransfer, CheckoutResponseTransfer $checkoutResponseTransfer) |
|
87
|
|
|
{ |
|
88
|
|
|
$checkoutResponseTransfer |
|
89
|
|
|
->setIsExternalRedirect(true) |
|
90
|
|
|
->setRedirectUrl($computopPaymentTransfer->getUrl()); |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
return $checkoutResponseTransfer; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @param string $methodName |
|
97
|
|
|
* |
|
98
|
|
|
* @throws \SprykerEco\Zed\Computop\Business\Exception\ComputopMethodMapperException |
|
99
|
|
|
* |
|
100
|
|
|
* @return \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface |
|
101
|
|
|
*/ |
|
102
|
|
|
protected function getMethodMapper($methodName) |
|
103
|
|
|
{ |
|
104
|
|
|
if (isset($this->methodMappers[$methodName]) === false) { |
|
105
|
|
|
throw new ComputopMethodMapperException('The method mapper is not registered.'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
return $this->methodMappers[$methodName]; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
|
113
|
|
|
* |
|
114
|
|
|
* @throws \SprykerEco\Zed\Computop\Business\Exception\PaymentMethodNotFoundException |
|
115
|
|
|
* |
|
116
|
|
|
* @return \Spryker\Shared\Kernel\Transfer\TransferInterface |
|
117
|
|
|
*/ |
|
118
|
|
|
protected function getPaymentTransfer(QuoteTransfer $quoteTransfer) |
|
119
|
|
|
{ |
|
120
|
|
|
$paymentSelection = $quoteTransfer->getPayment()->getPaymentSelection(); |
|
121
|
|
|
|
|
122
|
|
|
$paymentMethod = ucfirst($paymentSelection); |
|
123
|
|
|
$method = 'get' . $paymentMethod; |
|
124
|
|
|
$paymentTransfer = $quoteTransfer->getPayment(); |
|
125
|
|
|
|
|
126
|
|
|
if (!method_exists($paymentTransfer, $method) || ($quoteTransfer->getPayment()->$method() === null)) { |
|
127
|
|
|
throw new PaymentMethodNotFoundException(sprintf('Selected payment method "%s" not found in PaymentTransfer', $paymentMethod)); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
$computopPaymentTransfer = $quoteTransfer->getPayment()->$method(); |
|
131
|
|
|
$methodMapper = $this->getMethodMapper($paymentSelection); |
|
132
|
|
|
|
|
133
|
|
|
return $methodMapper->updateComputopPaymentTransfer($quoteTransfer, $computopPaymentTransfer); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @param \Generated\Shared\Transfer\PaymentTransfer $paymentTransfer |
|
138
|
|
|
* |
|
139
|
|
|
* @return bool |
|
140
|
|
|
*/ |
|
141
|
|
|
protected function isPaymentInitRequired(PaymentTransfer $paymentTransfer): bool |
|
142
|
|
|
{ |
|
143
|
|
|
return in_array($paymentTransfer->getPaymentSelection(), [ |
|
144
|
|
|
ConputopSharedConfig::PAYMENT_METHOD_PAY_NOW, |
|
145
|
|
|
ConputopSharedConfig::PAYMENT_METHOD_EASY_CREDIT, |
|
146
|
|
|
ConputopSharedConfig::PAYMENT_METHOD_CREDIT_CARD, |
|
147
|
|
|
], true); |
|
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