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\Persistence; |
9
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\ComputopNotificationTransfer; |
|
|
|
|
11
|
|
|
use Orm\Zed\Computop\Persistence\SpyPaymentComputopDetail; |
|
|
|
|
12
|
|
|
use Orm\Zed\Computop\Persistence\SpyPaymentComputopOrderItem; |
|
|
|
|
13
|
|
|
use Propel\Runtime\Collection\ObjectCollection; |
14
|
|
|
use Spryker\Shared\Kernel\Transfer\TransferInterface; |
15
|
|
|
use Spryker\Zed\Kernel\Persistence\AbstractEntityManager; |
16
|
|
|
use SprykerEco\Zed\Computop\ComputopConfig; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @method \SprykerEco\Zed\Computop\Persistence\ComputopPersistenceFactory getFactory() |
20
|
|
|
*/ |
21
|
|
|
class ComputopEntityManager extends AbstractEntityManager implements ComputopEntityManagerInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @param \Generated\Shared\Transfer\ComputopNotificationTransfer $computopNotificationTransfer |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
|
|
public function savePaymentComputopNotification(ComputopNotificationTransfer $computopNotificationTransfer): void |
29
|
|
|
{ |
30
|
|
|
$paymentComputopNotificationEntity = $this->getFactory() |
31
|
|
|
->createPaymentComputopNotificationQuery() |
32
|
|
|
->filterByPayId($computopNotificationTransfer->getPayId()) |
33
|
|
|
->filterByTransId($computopNotificationTransfer->getTransId()) |
34
|
|
|
->filterByXId($computopNotificationTransfer->getXId()) |
35
|
|
|
->findOneOrCreate(); |
36
|
|
|
|
37
|
|
|
$paymentComputopNotificationEntity->fromArray( |
38
|
|
|
$computopNotificationTransfer->modifiedToArray() |
39
|
|
|
); |
40
|
|
|
$paymentComputopNotificationEntity->save(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param \Generated\Shared\Transfer\ComputopNotificationTransfer $computopNotificationTransfer |
45
|
|
|
* |
46
|
|
|
* @return bool |
47
|
|
|
*/ |
48
|
|
|
public function updatePaymentComputopOrderItemPaymentConfirmation( |
49
|
|
|
ComputopNotificationTransfer $computopNotificationTransfer |
50
|
|
|
): bool { |
51
|
|
|
/** @var \Orm\Zed\Computop\Persistence\SpyPaymentComputopOrderItem[]|\Propel\Runtime\Collection\ObjectCollection $paymentComputopOrderItemEntities */ |
52
|
|
|
$paymentComputopOrderItemEntities = $this->getFactory() |
53
|
|
|
->createPaymentComputopOrderItemQuery() |
54
|
|
|
->useSpyPaymentComputopQuery() |
55
|
|
|
->filterByTransId($computopNotificationTransfer->getTransId()) |
56
|
|
|
->filterByPayId($computopNotificationTransfer->getPayId()) |
57
|
|
|
->endUse() |
58
|
|
|
->find(); |
59
|
|
|
|
60
|
|
|
if (!$paymentComputopOrderItemEntities->count()) { |
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
foreach ($paymentComputopOrderItemEntities as $paymentComputopOrderItemEntity) { |
65
|
|
|
$orderItemEntityStatus = $this->getCurrentOrderItemEntityStatus($computopNotificationTransfer, $paymentComputopOrderItemEntity); |
66
|
|
|
$paymentComputopOrderItemEntity |
67
|
|
|
->setIsPaymentConfirmed((bool)$computopNotificationTransfer->getIsSuccess()) |
68
|
|
|
->setStatus($orderItemEntityStatus) |
69
|
|
|
->save(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return true; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param \Spryker\Shared\Kernel\Transfer\TransferInterface $responseTransfer |
77
|
|
|
* @param string|null $paymentStatus |
78
|
|
|
* |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
|
|
public function savePaymentResponse(TransferInterface $responseTransfer, ?string $paymentStatus = null): void |
82
|
|
|
{ |
83
|
|
|
$header = $responseTransfer->requireHeader() |
|
|
|
|
84
|
|
|
->getHeader() |
85
|
|
|
->requireTransId() |
86
|
|
|
->requirePayId() |
87
|
|
|
->requireXid(); |
88
|
|
|
|
89
|
|
|
$paymentEntity = $this->getFactory() |
90
|
|
|
->createPaymentComputopQuery() |
91
|
|
|
->filterByTransId($header->getTransId()) |
92
|
|
|
->findOne(); |
93
|
|
|
|
94
|
|
|
if (!$paymentEntity) { |
95
|
|
|
return; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$paymentEntity |
99
|
|
|
->setPayId($header->getPayId()) |
100
|
|
|
->setXId($header->getXId()) |
101
|
|
|
->save(); |
102
|
|
|
|
103
|
|
|
$this->savePaymentDetailEntity($paymentEntity->getSpyPaymentComputopDetail(), $responseTransfer); |
104
|
|
|
|
105
|
|
|
$this->saveAuthorizedPaymentOrderItems($paymentEntity->getSpyPaymentComputopOrderItems(), $paymentStatus); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param \Orm\Zed\Computop\Persistence\SpyPaymentComputopDetail $paymentEntityDetails |
110
|
|
|
* @param \Generated\Shared\Transfer\ComputopPayuCeeSingleInitResponseTransfer $responseTransfer |
|
|
|
|
111
|
|
|
* |
112
|
|
|
* @return void |
113
|
|
|
*/ |
114
|
|
|
public function savePaymentDetailEntity( |
115
|
|
|
SpyPaymentComputopDetail $paymentEntityDetails, |
116
|
|
|
TransferInterface $responseTransfer |
117
|
|
|
): void { |
118
|
|
|
$paymentEntityDetails->fromArray($responseTransfer->toArray()); |
119
|
|
|
$customerTransactionId = $responseTransfer->getCustomerTransactionId(); |
|
|
|
|
120
|
|
|
if ($customerTransactionId) { |
121
|
|
|
$paymentEntityDetails->setCustomerTransactionId((int)$customerTransactionId); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$paymentEntityDetails->save(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param \Orm\Zed\Computop\Persistence\SpyPaymentComputopOrderItem[]|\Propel\Runtime\Collection\ObjectCollection $paymentComputopOrderItems |
129
|
|
|
* @param string|null $paymentStatus |
130
|
|
|
* |
131
|
|
|
* @return void |
132
|
|
|
*/ |
133
|
|
|
public function saveAuthorizedPaymentOrderItems(ObjectCollection $paymentComputopOrderItems, ?string $paymentStatus = null): void |
134
|
|
|
{ |
135
|
|
|
$paymentStatus = $paymentStatus ?? $this->getFactory()->getConfig()->getOmsStatusAuthorized(); |
136
|
|
|
foreach ($paymentComputopOrderItems as $paymentComputopOrderItem) { |
137
|
|
|
$paymentComputopOrderItem->setStatus($paymentStatus); |
138
|
|
|
$paymentComputopOrderItem->save(); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param \Generated\Shared\Transfer\ComputopNotificationTransfer $computopNotificationTransfer |
144
|
|
|
* @param \Orm\Zed\Computop\Persistence\SpyPaymentComputopOrderItem $paymentComputopOrderItemEntity |
145
|
|
|
* |
146
|
|
|
* @return string |
147
|
|
|
*/ |
148
|
|
|
protected function getCurrentOrderItemEntityStatus( |
149
|
|
|
ComputopNotificationTransfer $computopNotificationTransfer, |
150
|
|
|
SpyPaymentComputopOrderItem $paymentComputopOrderItemEntity |
151
|
|
|
): string { |
152
|
|
|
if ( |
153
|
|
|
$paymentComputopOrderItemEntity->getStatus() === ComputopConfig::OMS_STATUS_NEW && |
154
|
|
|
(int)$computopNotificationTransfer->getAmountauth() > 0 |
155
|
|
|
) { |
156
|
|
|
return $this->getFactory()->getConfig()->getOmsStatusAuthorized(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
if ( |
160
|
|
|
$paymentComputopOrderItemEntity->getStatus() === ComputopConfig::OMS_STATUS_AUTHORIZED && |
161
|
|
|
(int)$computopNotificationTransfer->getAmountcap() === (int)$computopNotificationTransfer->getAmountauth() |
162
|
|
|
) { |
163
|
|
|
return $this->getFactory()->getConfig()->getOmsStatusCaptured(); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
return $paymentComputopOrderItemEntity->getStatus(); |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
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