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\ComputopPaymentComputopOrderItemCollectionTransfer; |
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\ComputopPaymentComputopTransfer; |
|
|
|
|
12
|
|
|
use Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer; |
|
|
|
|
13
|
|
|
use Generated\Shared\Transfer\ComputopSalesOrderItemTransfer; |
|
|
|
|
14
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
|
|
|
15
|
|
|
use Spryker\Zed\Kernel\Persistence\EntityManager\TransactionTrait; |
16
|
|
|
use SprykerEco\Zed\Computop\ComputopConfig; |
17
|
|
|
use SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface; |
18
|
|
|
use SprykerEco\Zed\Computop\Persistence\ComputopRepositoryInterface; |
19
|
|
|
|
20
|
|
|
class PayPalExpressResponseSaver implements InitResponseSaverInterface |
21
|
|
|
{ |
22
|
|
|
use TransactionTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var \SprykerEco\Zed\Computop\ComputopConfig |
26
|
|
|
*/ |
27
|
|
|
protected $computopConfig; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var \SprykerEco\Zed\Computop\Persistence\ComputopRepositoryInterface |
31
|
|
|
*/ |
32
|
|
|
protected $computopRepository; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var \SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface |
36
|
|
|
*/ |
37
|
|
|
protected $computopEntityManager; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param \SprykerEco\Zed\Computop\ComputopConfig $computopConfig |
41
|
|
|
* @param \SprykerEco\Zed\Computop\Persistence\ComputopRepositoryInterface $computopRepository |
42
|
|
|
* @param \SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface $computopEntityManager |
43
|
|
|
*/ |
44
|
|
|
public function __construct( |
45
|
|
|
ComputopConfig $computopConfig, |
46
|
|
|
ComputopRepositoryInterface $computopRepository, |
47
|
|
|
ComputopEntityManagerInterface $computopEntityManager |
48
|
|
|
) { |
49
|
|
|
$this->computopConfig = $computopConfig; |
50
|
|
|
$this->computopRepository = $computopRepository; |
51
|
|
|
$this->computopEntityManager = $computopEntityManager; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
56
|
|
|
* |
57
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
58
|
|
|
*/ |
59
|
|
|
public function save(QuoteTransfer $quoteTransfer): QuoteTransfer |
60
|
|
|
{ |
61
|
|
|
$computopPayPalExpressInitResponseTransfer = $quoteTransfer->getPaymentOrFail() |
62
|
|
|
->getComputopPayPalExpressOrFail() |
63
|
|
|
->getPayPalExpressInitResponseOrFail(); |
64
|
|
|
|
65
|
|
|
$computopPaymentComputopTransfer = $this->computopRepository |
66
|
|
|
->findComputopPaymentByComputopTransId( |
67
|
|
|
$computopPayPalExpressInitResponseTransfer->getHeader()->getTransId(), |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
if ($computopPaymentComputopTransfer === null) { |
71
|
|
|
return $quoteTransfer; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if ($computopPayPalExpressInitResponseTransfer->getHeader()->getIsSuccess()) { |
75
|
|
|
$this->getTransactionHandler()->handleTransaction( |
76
|
|
|
function () use ($computopPaymentComputopTransfer, $computopPayPalExpressInitResponseTransfer) { |
77
|
|
|
$this->executeSavePaymentComputopDataTransaction($computopPaymentComputopTransfer, $computopPayPalExpressInitResponseTransfer); |
78
|
|
|
}, |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $quoteTransfer; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer |
87
|
|
|
* @param \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer |
88
|
|
|
* |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
|
|
protected function executeSavePaymentComputopDataTransaction( |
92
|
|
|
ComputopPaymentComputopTransfer $computopPaymentComputopTransfer, |
93
|
|
|
ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer |
94
|
|
|
): void { |
95
|
|
|
$this->savePaymentComputopEntity($computopPaymentComputopTransfer, $computopPayPalExpressInitResponseTransfer); |
96
|
|
|
$this->savePaymentComputopDetailEntity($computopPaymentComputopTransfer, $computopPayPalExpressInitResponseTransfer); |
97
|
|
|
$this->savePaymentComputopOrderItemEntities($computopPaymentComputopTransfer); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer |
102
|
|
|
* @param \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer |
103
|
|
|
* |
104
|
|
|
* @return void |
105
|
|
|
*/ |
106
|
|
|
protected function savePaymentComputopEntity( |
107
|
|
|
ComputopPaymentComputopTransfer $computopPaymentComputopTransfer, |
108
|
|
|
ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer |
109
|
|
|
): void { |
110
|
|
|
$computopPaymentComputopTransfer->setPayId($computopPayPalExpressInitResponseTransfer->getHeader()->getPayId()); |
111
|
|
|
$computopPaymentComputopTransfer->setXId($computopPayPalExpressInitResponseTransfer->getHeader()->getXId()); |
112
|
|
|
|
113
|
|
|
$this->computopEntityManager->updateComputopPayment($computopPaymentComputopTransfer); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer |
118
|
|
|
* @param \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer |
119
|
|
|
* |
120
|
|
|
* @return void |
121
|
|
|
*/ |
122
|
|
|
protected function savePaymentComputopDetailEntity( |
123
|
|
|
ComputopPaymentComputopTransfer $computopPaymentComputopTransfer, |
124
|
|
|
ComputopPayPalExpressInitResponseTransfer $computopPayPalExpressInitResponseTransfer |
125
|
|
|
): void { |
126
|
|
|
$computopPaymentComputopDetailTransfer = $this->computopRepository |
127
|
|
|
->findComputopPaymentDetail($computopPaymentComputopTransfer); |
128
|
|
|
|
129
|
|
|
if ($computopPaymentComputopDetailTransfer === null) { |
130
|
|
|
return; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$computopPaymentComputopDetailTransfer->fromArray($computopPayPalExpressInitResponseTransfer->toArray(), true); |
134
|
|
|
|
135
|
|
|
$this->computopEntityManager->updateComputopPaymentDetail($computopPaymentComputopDetailTransfer); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer |
140
|
|
|
* |
141
|
|
|
* @return void |
142
|
|
|
*/ |
143
|
|
|
protected function savePaymentComputopOrderItemEntities( |
144
|
|
|
ComputopPaymentComputopTransfer $computopPaymentComputopTransfer |
145
|
|
|
): void { |
146
|
|
|
$salesOrderItemCollectionTransfer = $this->computopRepository |
147
|
|
|
->getComputopSalesOrderItemCollection($computopPaymentComputopTransfer); |
148
|
|
|
|
149
|
|
|
$computopPaymentComputopOrderItemCollection = $this->computopRepository |
150
|
|
|
->getComputopPaymentComputopOrderItemCollection($computopPaymentComputopTransfer); |
151
|
|
|
|
152
|
|
|
foreach ($salesOrderItemCollectionTransfer->getComputopSalesOrderItems() as $computopSalesOrderItem) { |
153
|
|
|
$this->updateComputopSalesOrderItemCollection( |
154
|
|
|
$computopPaymentComputopOrderItemCollection, |
155
|
|
|
$computopSalesOrderItem, |
156
|
|
|
); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param \Generated\Shared\Transfer\ComputopPaymentComputopOrderItemCollectionTransfer $computopPaymentComputopOrderItemCollection |
162
|
|
|
* @param \Generated\Shared\Transfer\ComputopSalesOrderItemTransfer $computopSalesOrderItem |
163
|
|
|
* |
164
|
|
|
* @return void |
165
|
|
|
*/ |
166
|
|
|
protected function updateComputopSalesOrderItemCollection( |
167
|
|
|
ComputopPaymentComputopOrderItemCollectionTransfer $computopPaymentComputopOrderItemCollection, |
168
|
|
|
ComputopSalesOrderItemTransfer $computopSalesOrderItem |
169
|
|
|
): void { |
170
|
|
|
foreach ($computopPaymentComputopOrderItemCollection->getComputopPaymentComputopOrderItems() as $computopPaymentComputopOrderItem) { |
171
|
|
|
if ($computopSalesOrderItem->getIdSalesOrderItem() !== $computopPaymentComputopOrderItem->getFkSalesOrderItem()) { |
172
|
|
|
continue; |
173
|
|
|
} |
174
|
|
|
$computopPaymentComputopOrderItem->setStatus($this->computopConfig->getOmsStatusInitialized()); |
175
|
|
|
$this->computopEntityManager->updateComputopPaymentComputopOrderItem($computopPaymentComputopOrderItem); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
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