1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\CrefoPay\Business\Processor; |
9
|
|
|
|
10
|
|
|
use ArrayObject; |
11
|
|
|
use Generated\Shared\Transfer\CrefoPayNotificationTransfer; |
|
|
|
|
12
|
|
|
use Generated\Shared\Transfer\PaymentCrefoPayOrderItemCollectionTransfer; |
|
|
|
|
13
|
|
|
use Generated\Shared\Transfer\PaymentCrefoPayOrderItemTransfer; |
|
|
|
|
14
|
|
|
use SprykerEco\Zed\CrefoPay\Business\Mapper\OmsStatus\CrefoPayOmsStatusMapperInterface; |
15
|
|
|
use SprykerEco\Zed\CrefoPay\Business\Reader\CrefoPayReaderInterface; |
16
|
|
|
use SprykerEco\Zed\CrefoPay\Business\Writer\CrefoPayWriterInterface; |
17
|
|
|
|
18
|
|
|
class CrefoPayNotificationProcessor implements CrefoPayNotificationProcessorInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var \SprykerEco\Zed\CrefoPay\Business\Mapper\OmsStatus\CrefoPayOmsStatusMapperInterface |
22
|
|
|
*/ |
23
|
|
|
protected $statusMapper; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var \SprykerEco\Zed\CrefoPay\Business\Reader\CrefoPayReaderInterface |
27
|
|
|
*/ |
28
|
|
|
protected $reader; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var \SprykerEco\Zed\CrefoPay\Business\Writer\CrefoPayWriterInterface |
32
|
|
|
*/ |
33
|
|
|
protected $writer; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param \SprykerEco\Zed\CrefoPay\Business\Mapper\OmsStatus\CrefoPayOmsStatusMapperInterface $statusMapper |
37
|
|
|
* @param \SprykerEco\Zed\CrefoPay\Business\Reader\CrefoPayReaderInterface $reader |
38
|
|
|
* @param \SprykerEco\Zed\CrefoPay\Business\Writer\CrefoPayWriterInterface $writer |
39
|
|
|
*/ |
40
|
|
|
public function __construct( |
41
|
|
|
CrefoPayOmsStatusMapperInterface $statusMapper, |
42
|
|
|
CrefoPayReaderInterface $reader, |
43
|
|
|
CrefoPayWriterInterface $writer |
44
|
|
|
) { |
45
|
|
|
$this->statusMapper = $statusMapper; |
46
|
|
|
$this->reader = $reader; |
47
|
|
|
$this->writer = $writer; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param \Generated\Shared\Transfer\CrefoPayNotificationTransfer $notificationTransfer |
52
|
|
|
* |
53
|
|
|
* @return \Generated\Shared\Transfer\CrefoPayNotificationTransfer |
54
|
|
|
*/ |
55
|
|
|
public function processNotification(CrefoPayNotificationTransfer $notificationTransfer): CrefoPayNotificationTransfer |
56
|
|
|
{ |
57
|
|
|
$status = $this->getOmsStatus($notificationTransfer); |
58
|
|
|
$paymentCrefoPayOrderItemsCollection = $this->getCrefoPayOrderItemCollection($notificationTransfer); |
59
|
|
|
|
60
|
|
|
$paymentCrefoPayOrderItems = array_map( |
61
|
|
|
function (PaymentCrefoPayOrderItemTransfer $paymentCrefoPayOrderItemTransfer) use ($status) { |
62
|
|
|
return $paymentCrefoPayOrderItemTransfer->setStatus($status); |
63
|
|
|
}, |
64
|
|
|
$paymentCrefoPayOrderItemsCollection->getCrefoPayOrderItems()->getArrayCopy() |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$paymentCrefoPayOrderItemsCollection->setCrefoPayOrderItems(new ArrayObject($paymentCrefoPayOrderItems)); |
68
|
|
|
|
69
|
|
|
$this->writer->createNotificationEntities( |
70
|
|
|
$notificationTransfer, |
71
|
|
|
$paymentCrefoPayOrderItemsCollection |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
return $notificationTransfer; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param \Generated\Shared\Transfer\CrefoPayNotificationTransfer $notificationTransfer |
79
|
|
|
* |
80
|
|
|
* @return string|null |
81
|
|
|
*/ |
82
|
|
|
protected function getOmsStatus(CrefoPayNotificationTransfer $notificationTransfer): ?string |
83
|
|
|
{ |
84
|
|
|
if (!empty($notificationTransfer->getTransactionStatus())) { |
85
|
|
|
$status = $this->statusMapper |
86
|
|
|
->mapNotificationTransactionStatusToOmsStatus( |
87
|
|
|
$notificationTransfer->getTransactionStatus() |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if (!empty($notificationTransfer->getOrderStatus())) { |
92
|
|
|
$status = $this->statusMapper |
93
|
|
|
->mapNotificationOrderStatusToOmsStatus( |
94
|
|
|
$notificationTransfer->getOrderStatus() |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $status ?? null; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param \Generated\Shared\Transfer\CrefoPayNotificationTransfer $notificationTransfer |
103
|
|
|
* |
104
|
|
|
* @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemCollectionTransfer |
105
|
|
|
*/ |
106
|
|
|
protected function getCrefoPayOrderItemCollection(CrefoPayNotificationTransfer $notificationTransfer): PaymentCrefoPayOrderItemCollectionTransfer |
107
|
|
|
{ |
108
|
|
|
if ($this->isCaptureRelatedNotification($notificationTransfer)) { |
109
|
|
|
return $this->reader |
110
|
|
|
->findPaymentCrefoPayOrderItemsByCaptureId($notificationTransfer->getCaptureID()); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return $this->reader |
114
|
|
|
->findPaymentCrefoPayOrderItemsByCrefoPayOrderId($notificationTransfer->getOrderID()); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param \Generated\Shared\Transfer\CrefoPayNotificationTransfer $notificationTransfer |
119
|
|
|
* |
120
|
|
|
* @return bool |
121
|
|
|
*/ |
122
|
|
|
protected function isCaptureRelatedNotification(CrefoPayNotificationTransfer $notificationTransfer): bool |
123
|
|
|
{ |
124
|
|
|
return !empty($notificationTransfer->getCaptureID()); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
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