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\Order; |
9
|
|
|
|
10
|
|
|
use ArrayObject; |
11
|
|
|
use Generated\Shared\Transfer\PaymentTransfer; |
|
|
|
|
12
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
|
|
|
13
|
|
|
use Generated\Shared\Transfer\SaveOrderTransfer; |
|
|
|
|
14
|
|
|
use Orm\Zed\Computop\Persistence\SpyPaymentComputop; |
|
|
|
|
15
|
|
|
use Orm\Zed\Computop\Persistence\SpyPaymentComputopDetail; |
|
|
|
|
16
|
|
|
use Orm\Zed\Computop\Persistence\SpyPaymentComputopOrderItem; |
|
|
|
|
17
|
|
|
use Spryker\Zed\Kernel\Persistence\EntityManager\TransactionTrait; |
18
|
|
|
use SprykerEco\Shared\Computop\ComputopConfig as ComputopSharedConfig; |
19
|
|
|
use SprykerEco\Zed\Computop\Business\Exception\ComputopMethodMapperException; |
20
|
|
|
use SprykerEco\Zed\Computop\Business\Order\Mapper\MapperInterface; |
21
|
|
|
use SprykerEco\Zed\Computop\ComputopConfig; |
22
|
|
|
|
23
|
|
|
class OrderManager implements OrderManagerInterface |
24
|
|
|
{ |
25
|
|
|
use TransactionTrait; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \SprykerEco\Zed\Computop\Business\Order\OrderManagerInterface |
29
|
|
|
*/ |
30
|
|
|
protected $mappers; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var \SprykerEco\Zed\Computop\Business\Order\OrderManagerInterface |
34
|
|
|
*/ |
35
|
|
|
protected $activeMapper; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var \Spryker\Shared\Kernel\Transfer\TransferInterface |
39
|
|
|
*/ |
40
|
|
|
protected $computopTransfer; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var \Spryker\Shared\Kernel\Transfer\TransferInterface |
44
|
|
|
*/ |
45
|
|
|
protected $computopResponseTransfer; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var \SprykerEco\Zed\Computop\ComputopConfig |
49
|
|
|
*/ |
50
|
|
|
protected $config; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
protected $methodName; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param \SprykerEco\Zed\Computop\ComputopConfig $config |
59
|
|
|
*/ |
60
|
|
|
public function __construct(ComputopConfig $config) |
61
|
|
|
{ |
62
|
|
|
$this->config = $config; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param \SprykerEco\Zed\Computop\Business\Order\Mapper\MapperInterface $mapper |
67
|
|
|
* |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
public function registerMapper(MapperInterface $mapper) |
71
|
|
|
{ |
72
|
|
|
$this->mappers[$mapper->getMethodName()] = $mapper; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string $methodName |
77
|
|
|
* |
78
|
|
|
* @throws \SprykerEco\Zed\Computop\Business\Exception\ComputopMethodMapperException |
79
|
|
|
* |
80
|
|
|
* @return \SprykerEco\Zed\Computop\Business\Order\Mapper\MapperInterface |
81
|
|
|
*/ |
82
|
|
|
protected function getMethodMapper($methodName) |
83
|
|
|
{ |
84
|
|
|
if (isset($this->mappers[$methodName]) === false) { |
85
|
|
|
throw new ComputopMethodMapperException('The method mapper is not registered.'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $this->mappers[$methodName]; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
93
|
|
|
* @param \Generated\Shared\Transfer\SaveOrderTransfer $saveOrderTransfer |
94
|
|
|
* |
95
|
|
|
* @return void |
96
|
|
|
*/ |
97
|
|
|
public function saveOrderPayment(QuoteTransfer $quoteTransfer, SaveOrderTransfer $saveOrderTransfer) |
98
|
|
|
{ |
99
|
|
|
if ($quoteTransfer->getPayment()->getPaymentProvider() !== ComputopSharedConfig::PROVIDER_NAME) { |
100
|
|
|
return; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$this->methodName = $quoteTransfer->getPayment()->getPaymentMethod(); |
104
|
|
|
$this->activeMapper = $this->getMethodMapper($quoteTransfer->getPayment()->getPaymentMethod()); |
|
|
|
|
105
|
|
|
$this->computopTransfer = $this->activeMapper->getComputopTransfer($quoteTransfer->getPayment()); |
106
|
|
|
$this->computopResponseTransfer = $this->activeMapper->getComputopResponseTransfer($quoteTransfer->getPayment()); |
107
|
|
|
|
108
|
|
|
$paymentEntity = $this->savePaymentForOrder( |
109
|
|
|
$quoteTransfer->getPayment(), |
110
|
|
|
$saveOrderTransfer |
111
|
|
|
); |
112
|
|
|
|
113
|
|
|
$this->savePaymentDetailForOrder( |
114
|
|
|
$quoteTransfer->getPayment(), |
115
|
|
|
$paymentEntity |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
$this->savePaymentForOrderItems( |
119
|
|
|
$saveOrderTransfer->getOrderItems(), |
120
|
|
|
$paymentEntity->getIdPaymentComputop() |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param \Generated\Shared\Transfer\PaymentTransfer $paymentTransfer |
126
|
|
|
* @param \Generated\Shared\Transfer\SaveOrderTransfer $saveOrderTransfer |
127
|
|
|
* |
128
|
|
|
* @return \Orm\Zed\Computop\Persistence\SpyPaymentComputop |
129
|
|
|
*/ |
130
|
|
|
protected function savePaymentForOrder(PaymentTransfer $paymentTransfer, SaveOrderTransfer $saveOrderTransfer) |
131
|
|
|
{ |
132
|
|
|
$paymentEntity = new SpyPaymentComputop(); |
133
|
|
|
|
134
|
|
|
$paymentEntity->setClientIp($this->computopTransfer->getClientIp()); |
|
|
|
|
135
|
|
|
$paymentEntity->setPaymentMethod($paymentTransfer->getPaymentMethod()); |
136
|
|
|
$paymentEntity->setReference($saveOrderTransfer->getOrderReference()); |
137
|
|
|
$paymentEntity->setFkSalesOrder($saveOrderTransfer->getIdSalesOrder()); |
138
|
|
|
$paymentEntity->setTransId($this->computopTransfer->getTransId()); |
|
|
|
|
139
|
|
|
$paymentEntity->setPayId($this->computopTransfer->getPayId()); |
|
|
|
|
140
|
|
|
$paymentEntity->setReqId($this->computopTransfer->getReqId()); |
|
|
|
|
141
|
|
|
|
142
|
|
|
if ($this->isPaymentMethodEasyCredit()) { |
143
|
|
|
$paymentEntity->setXId($this->computopResponseTransfer->getHeader()->getXId()); |
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$paymentEntity->save(); |
147
|
|
|
|
148
|
|
|
return $paymentEntity; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param \Generated\Shared\Transfer\PaymentTransfer $paymentTransfer |
153
|
|
|
* @param \Orm\Zed\Computop\Persistence\SpyPaymentComputop $paymentEntity |
154
|
|
|
* |
155
|
|
|
* @return \Orm\Zed\Computop\Persistence\SpyPaymentComputopDetail |
156
|
|
|
*/ |
157
|
|
|
protected function savePaymentDetailForOrder(PaymentTransfer $paymentTransfer, SpyPaymentComputop $paymentEntity) |
158
|
|
|
{ |
159
|
|
|
$paymentDetailEntity = new SpyPaymentComputopDetail(); |
160
|
|
|
|
161
|
|
|
$paymentDetailEntity->fromArray($this->activeMapper->getPaymentDetailsArray($paymentTransfer)); |
|
|
|
|
162
|
|
|
$paymentDetailEntity->setIdPaymentComputop($paymentEntity->getIdPaymentComputop()); |
163
|
|
|
|
164
|
|
|
if ($this->isPaymentMethodEasyCredit()) { |
165
|
|
|
$paymentDetailEntity->fromArray($this->computopResponseTransfer->toArray()); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
$paymentDetailEntity->save(); |
169
|
|
|
|
170
|
|
|
return $paymentDetailEntity; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param \ArrayObject|\Generated\Shared\Transfer\ItemTransfer[] $orderItemTransfers |
175
|
|
|
* @param int $idPayment |
176
|
|
|
* |
177
|
|
|
* @return void |
178
|
|
|
*/ |
179
|
|
|
protected function savePaymentForOrderItems(ArrayObject $orderItemTransfers, $idPayment) |
180
|
|
|
{ |
181
|
|
|
foreach ($orderItemTransfers as $orderItemTransfer) { |
182
|
|
|
$paymentOrderItemEntity = new SpyPaymentComputopOrderItem(); |
183
|
|
|
|
184
|
|
|
$paymentOrderItemEntity |
185
|
|
|
->setFkPaymentComputop($idPayment) |
186
|
|
|
->setFkSalesOrderItem($orderItemTransfer->getIdSalesOrderItem()); |
187
|
|
|
$paymentOrderItemEntity->setStatus($this->config->getOmsStatusNew()); |
188
|
|
|
|
189
|
|
|
if ($this->isPaymentMethodEasyCredit()) { |
190
|
|
|
$paymentOrderItemEntity->setStatus($this->config->getOmsStatusInitialized()); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
$paymentOrderItemEntity->save(); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @return bool |
199
|
|
|
*/ |
200
|
|
|
protected function isPaymentMethodEasyCredit(): bool |
201
|
|
|
{ |
202
|
|
|
return $this->methodName === ComputopSharedConfig::PAYMENT_METHOD_EASY_CREDIT; |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|
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