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\Payment\Handler\Saver\Init; |
9
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\ComputopApiResponseHeaderTransfer; |
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\ComputopPaymentComputopOrderItemCollectionTransfer; |
|
|
|
|
12
|
|
|
use Generated\Shared\Transfer\ComputopPaymentComputopTransfer; |
|
|
|
|
13
|
|
|
use Generated\Shared\Transfer\ComputopPayuCeeSingleInitResponseTransfer; |
|
|
|
|
14
|
|
|
use Generated\Shared\Transfer\ComputopSalesOrderItemTransfer; |
|
|
|
|
15
|
|
|
use Generated\Shared\Transfer\PaymentTransfer; |
|
|
|
|
16
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
|
|
|
17
|
|
|
use Spryker\Zed\Kernel\Persistence\EntityManager\TransactionTrait; |
18
|
|
|
use SprykerEco\Shared\Computop\ComputopConfig as SharedComputopConfig; |
19
|
|
|
use SprykerEco\Zed\Computop\ComputopConfig; |
20
|
|
|
use SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface; |
21
|
|
|
use SprykerEco\Zed\Computop\Persistence\ComputopRepositoryInterface; |
22
|
|
|
|
23
|
|
|
class PayuCeeSingleResponseSaver implements InitResponseSaverInterface |
24
|
|
|
{ |
25
|
|
|
use TransactionTrait; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface |
29
|
|
|
*/ |
30
|
|
|
protected $computopEntityManager; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var \SprykerEco\Zed\Computop\ComputopConfig |
34
|
|
|
*/ |
35
|
|
|
protected $computopConfig; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var \SprykerEco\Zed\Computop\Persistence\ComputopRepositoryInterface |
39
|
|
|
*/ |
40
|
|
|
protected $computopRepository; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param \SprykerEco\Zed\Computop\ComputopConfig $computopConfig |
44
|
|
|
* @param \SprykerEco\Zed\Computop\Persistence\ComputopRepositoryInterface $computopRepository |
45
|
|
|
* @param \SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface $computopEntityManager |
46
|
|
|
*/ |
47
|
|
|
public function __construct( |
48
|
|
|
ComputopConfig $computopConfig, |
49
|
|
|
ComputopRepositoryInterface $computopRepository, |
50
|
|
|
ComputopEntityManagerInterface $computopEntityManager |
51
|
|
|
) { |
52
|
|
|
$this->computopConfig = $computopConfig; |
53
|
|
|
$this->computopRepository = $computopRepository; |
54
|
|
|
$this->computopEntityManager = $computopEntityManager; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
59
|
|
|
* |
60
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
61
|
|
|
*/ |
62
|
|
|
public function save(QuoteTransfer $quoteTransfer): QuoteTransfer |
63
|
|
|
{ |
64
|
|
|
$computopPayuCeeSingleInitResponseTransfer = $this->getPaymentTransferFromQuoteOrFail($quoteTransfer) |
65
|
|
|
->getComputopPayuCeeSingleOrFail() |
66
|
|
|
->getPayuCeeSingleInitResponseOrFail(); |
67
|
|
|
|
68
|
|
|
$computopApiResponseHeaderTransfer = $computopPayuCeeSingleInitResponseTransfer->getHeaderOrFail() |
69
|
|
|
->requireTransId() |
70
|
|
|
->requirePayId() |
71
|
|
|
->requireXid(); |
72
|
|
|
|
73
|
|
|
if (!$computopApiResponseHeaderTransfer->getIsSuccess()) { |
74
|
|
|
return $quoteTransfer; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$computopPaymentComputopTransfer = $this->computopRepository->findComputopPaymentByComputopTransId( |
78
|
|
|
$computopApiResponseHeaderTransfer->getTransId() |
79
|
|
|
); |
80
|
|
|
if ($computopPaymentComputopTransfer === null) { |
81
|
|
|
return $quoteTransfer; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$this->getTransactionHandler()->handleTransaction(function () use ($computopPaymentComputopTransfer, $computopPayuCeeSingleInitResponseTransfer) { |
85
|
|
|
$this->executeSavePaymentResponseTransaction($computopPaymentComputopTransfer, $computopPayuCeeSingleInitResponseTransfer); |
86
|
|
|
}); |
87
|
|
|
|
88
|
|
|
return $quoteTransfer; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer |
93
|
|
|
* @param \Generated\Shared\Transfer\ComputopPayuCeeSingleInitResponseTransfer $computopPayuCeeSingleInitResponseTransfer |
94
|
|
|
* |
95
|
|
|
* @return void |
96
|
|
|
*/ |
97
|
|
|
protected function executeSavePaymentResponseTransaction( |
98
|
|
|
ComputopPaymentComputopTransfer $computopPaymentComputopTransfer, |
99
|
|
|
ComputopPayuCeeSingleInitResponseTransfer $computopPayuCeeSingleInitResponseTransfer |
100
|
|
|
): void { |
101
|
|
|
$this->savePaymentComputopEntity($computopPaymentComputopTransfer, $computopPayuCeeSingleInitResponseTransfer->getHeader()); |
102
|
|
|
$this->savePaymentComputopDetailEntity($computopPaymentComputopTransfer, $computopPayuCeeSingleInitResponseTransfer); |
103
|
|
|
$paymentStatus = $this->getOrderItemPaymentStatusFromResponseHeader($computopPayuCeeSingleInitResponseTransfer->getHeader()); |
104
|
|
|
if ($paymentStatus) { |
105
|
|
|
$this->savePaymentComputopOrderItemsEntities($computopPaymentComputopTransfer, $paymentStatus); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
111
|
|
|
* |
112
|
|
|
* @return \Generated\Shared\Transfer\PaymentTransfer |
113
|
|
|
*/ |
114
|
|
|
protected function getPaymentTransferFromQuoteOrFail(QuoteTransfer $quoteTransfer): PaymentTransfer |
115
|
|
|
{ |
116
|
|
|
foreach ($quoteTransfer->getPayments() as $paymentTransfer) { |
117
|
|
|
if ($paymentTransfer !== null) { |
118
|
|
|
return $paymentTransfer; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return $quoteTransfer->getPaymentOrFail(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer |
127
|
|
|
* @param \Generated\Shared\Transfer\ComputopApiResponseHeaderTransfer $computopApiResponseHeaderTransfer |
128
|
|
|
* |
129
|
|
|
* @return void |
130
|
|
|
*/ |
131
|
|
|
protected function savePaymentComputopEntity( |
132
|
|
|
ComputopPaymentComputopTransfer $computopPaymentComputopTransfer, |
133
|
|
|
ComputopApiResponseHeaderTransfer $computopApiResponseHeaderTransfer |
134
|
|
|
): void { |
135
|
|
|
$computopPaymentComputopTransfer |
136
|
|
|
->setPayId($computopApiResponseHeaderTransfer->getPayId()) |
137
|
|
|
->setXId($computopApiResponseHeaderTransfer->getXId()); |
138
|
|
|
|
139
|
|
|
$this->computopEntityManager->saveComputopPayment($computopPaymentComputopTransfer); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer |
144
|
|
|
* @param \Generated\Shared\Transfer\ComputopPayuCeeSingleInitResponseTransfer $computopPayuCeeSingleInitResponseTransfer |
145
|
|
|
* |
146
|
|
|
* @return void |
147
|
|
|
*/ |
148
|
|
|
protected function savePaymentComputopDetailEntity( |
149
|
|
|
ComputopPaymentComputopTransfer $computopPaymentComputopTransfer, |
150
|
|
|
ComputopPayuCeeSingleInitResponseTransfer $computopPayuCeeSingleInitResponseTransfer |
151
|
|
|
): void { |
152
|
|
|
$computopPaymentComputopDetailTransfer = $this->computopRepository->findComputopPaymentDetail($computopPaymentComputopTransfer); |
153
|
|
|
$computopPaymentComputopDetailTransfer->fromArray($computopPayuCeeSingleInitResponseTransfer->toArray(), true); |
154
|
|
|
$computopPaymentComputopDetailTransfer->setCustomerTransactionId( |
155
|
|
|
(int)$computopPaymentComputopDetailTransfer->getCustomerTransactionId() |
156
|
|
|
); |
157
|
|
|
|
158
|
|
|
$this->computopEntityManager->updateComputopPaymentDetail($computopPaymentComputopDetailTransfer); |
|
|
|
|
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer |
163
|
|
|
* @param string $paymentStatus |
164
|
|
|
* |
165
|
|
|
* @return void |
166
|
|
|
*/ |
167
|
|
|
protected function savePaymentComputopOrderItemsEntities( |
168
|
|
|
ComputopPaymentComputopTransfer $computopPaymentComputopTransfer, |
169
|
|
|
string $paymentStatus |
170
|
|
|
): void { |
171
|
|
|
$salesOrderItemsCollectionTransfer = $this->computopRepository |
172
|
|
|
->getComputopSalesOrderItemsCollection($computopPaymentComputopTransfer); |
173
|
|
|
|
174
|
|
|
$computopPaymentComputopOrderItemsCollection = $this->computopRepository |
175
|
|
|
->getComputopPaymentComputopOrderItemsCollection($computopPaymentComputopTransfer); |
176
|
|
|
|
177
|
|
|
foreach ($salesOrderItemsCollectionTransfer->getComputopSalesOrderItems() as $computopSalesOrderItem) { |
178
|
|
|
$this->updateComputopSalesOrderItem( |
179
|
|
|
$computopPaymentComputopOrderItemsCollection, |
180
|
|
|
$computopSalesOrderItem, |
181
|
|
|
$paymentStatus |
182
|
|
|
); |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param \Generated\Shared\Transfer\ComputopPaymentComputopOrderItemCollectionTransfer $computopPaymentComputopOrderItemsCollection |
188
|
|
|
* @param \Generated\Shared\Transfer\ComputopSalesOrderItemTransfer $computopSalesOrderItem |
189
|
|
|
* @param string|null $paymentStatus |
190
|
|
|
* |
191
|
|
|
* @return void |
192
|
|
|
*/ |
193
|
|
|
protected function updateComputopSalesOrderItem( |
194
|
|
|
ComputopPaymentComputopOrderItemCollectionTransfer $computopPaymentComputopOrderItemsCollection, |
195
|
|
|
ComputopSalesOrderItemTransfer $computopSalesOrderItem, |
196
|
|
|
?string $paymentStatus |
197
|
|
|
): void { |
198
|
|
|
foreach ($computopPaymentComputopOrderItemsCollection->getComputopPaymentComputopOrderItems() as $computopPaymentComputopOrderItem) { |
199
|
|
|
if ($computopSalesOrderItem->getIdSalesOrderItem() !== $computopPaymentComputopOrderItem->getFkSalesOrderItem()) { |
200
|
|
|
continue; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
$computopPaymentComputopOrderItem->setStatus($paymentStatus); |
204
|
|
|
$this->computopEntityManager->updateComputopPaymentComputopOrderItem($computopPaymentComputopOrderItem); |
205
|
|
|
|
206
|
|
|
return; |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param \Generated\Shared\Transfer\ComputopApiResponseHeaderTransfer $computopApiResponseHeaderTransfer |
212
|
|
|
* |
213
|
|
|
* @return string |
214
|
|
|
*/ |
215
|
|
|
protected function getOrderItemPaymentStatusFromResponseHeader( |
216
|
|
|
ComputopApiResponseHeaderTransfer $computopApiResponseHeaderTransfer |
217
|
|
|
): ?string { |
218
|
|
|
if ($computopApiResponseHeaderTransfer->getStatus() === SharedComputopConfig::AUTHORIZE_REQUEST_STATUS) { |
219
|
|
|
return $this->computopConfig->getAuthorizeRequestOmsStatus(); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
if ($computopApiResponseHeaderTransfer->getStatus() === SharedComputopConfig::SUCCESS_OK) { |
223
|
|
|
return $this->computopConfig->getOmsStatusAuthorized(); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
return null; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|
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