-
Notifications
You must be signed in to change notification settings - Fork 211
/
Copy pathNotification.php
executable file
·290 lines (245 loc) · 8.21 KB
/
Notification.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2023 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
// phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod.Found
namespace Adyen\Payment\Model;
use Adyen\Payment\Api\Data\NotificationInterface;
use DateTime;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\Context;
use Magento\Framework\Model\ResourceModel\AbstractResource;
use Magento\Framework\Registry;
class Notification extends AbstractModel implements NotificationInterface
{
const AUTHORISATION = 'AUTHORISATION';
const PENDING = 'PENDING';
const AUTHORISED = 'AUTHORISED';
const RECEIVED = 'RECEIVED';
const CANCELLED = 'CANCELLED';
const REFUSED = 'REFUSED';
const ERROR = 'ERROR';
const REFUND = 'REFUND';
const REFUND_FAILED = 'REFUND_FAILED';
const CANCEL_OR_REFUND = 'CANCEL_OR_REFUND';
const CAPTURE = 'CAPTURE';
const CAPTURE_FAILED = 'CAPTURE_FAILED';
const CANCELLATION = 'CANCELLATION';
const POSAPPROVED = 'POS_APPROVED';
const HANDLED_EXTERNALLY = 'HANDLED_EXTERNALLY';
const MANUAL_REVIEW_ACCEPT = 'MANUAL_REVIEW_ACCEPT';
const MANUAL_REVIEW_REJECT = 'MANUAL_REVIEW_REJECT';
const RECURRING_CONTRACT = "RECURRING_CONTRACT";
const REPORT_AVAILABLE = "REPORT_AVAILABLE";
const ORDER_OPENED = 'ORDER_OPENED';
const ORDER_CLOSED = "ORDER_CLOSED";
const OFFER_CLOSED = "OFFER_CLOSED";
const CHARGEBACK = "CHARGEBACK";
const SECOND_CHARGEBACK = "SECOND_CHARGEBACK";
const CHARGEBACK_REVERSED = "CHARGEBACK_REVERSED";
const REQUEST_FOR_INFORMATION = "REQUEST_FOR_INFORMATION";
const NOTIFICATION_OF_CHARGEBACK = "NOTIFICATION_OF_CHARGEBACK";
const STATE_ADYEN_AUTHORIZED = "adyen_authorized";
const MAX_ERROR_COUNT = 5;
public function __construct(
Context $context,
Registry $registry,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
array $data = []
) {
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
}
protected function _construct()
{
$this->_init(ResourceModel\Notification::class);
}
/**
* Check if the Adyen Notification is already stored in the system
*
* @param null $done
* @return bool
*/
public function isDuplicate($done = null): bool
{
$result = $this->getResource()->getNotification(
$this->getPspreference(),
$this->getEventCode(),
$this->getSuccess(),
$this->getOriginalReference(),
$done
);
return !empty($result);
}
/**
* Remove OFFER_CLOSED and AUTHORISATION success=false notifications for some time from the processing list
* to ensure they won't close any order which has an AUTHORISED notification arrived a bit later than the
* OFFER_CLOSED or the AUTHORISATION success=false one.
*/
public function shouldSkipProcessing(): bool
{
if ((
self::OFFER_CLOSED === $this->getEventCode() ||
self::ORDER_CLOSED === $this->getEventCode() ||
(self::AUTHORISATION === $this->getEventCode() && !$this->isSuccessful())
) &&
$this->isLessThan10MinutesOld()
) {
return true;
}
return false;
}
public function getPspreference(): ?string
{
return $this->getData(self::PSPREFRENCE);
}
public function setPspreference(string $pspReference): NotificationInterface
{
return $this->setData(self::PSPREFRENCE, $pspReference);
}
public function getOriginalReference(): ?string
{
return $this->getData(self::ORIGINAL_REFERENCE);
}
public function setOriginalReference(?string $originalReference): NotificationInterface
{
return $this->setData(self::ORIGINAL_REFERENCE, $originalReference);
}
public function getMerchantReference(): ?string
{
return $this->getData(self::MERCHANT_REFERENCE);
}
public function setMerchantReference(string $merchantReference): NotificationInterface
{
return $this->setData(self::MERCHANT_REFERENCE, $merchantReference);
}
public function getEventCode(): ?string
{
return $this->getData(self::EVENT_CODE);
}
public function setEventCode(string $eventCode): NotificationInterface
{
return $this->setData(self::EVENT_CODE, $eventCode);
}
public function getSuccess(): ?string
{
return $this->getData(self::SUCCESS);
}
public function setSuccess(string $success): NotificationInterface
{
return $this->setData(self::SUCCESS, $success);
}
public function isSuccessful(): bool
{
return strcmp($this->getSuccess(), 'true') === 0 || strcmp($this->getSuccess(), '1') === 0;
}
public function getPaymentMethod(): ?string
{
return $this->getData(self::PAYMENT_METHOD);
}
public function setPaymentMethod(string $paymentMethod): NotificationInterface
{
return $this->setData(self::PAYMENT_METHOD, $paymentMethod);
}
public function getAmountValue(): ?int
{
return $this->getData(self::AMOUNT_VALUE);
}
public function setAmountValue(int $amountValue): NotificationInterface
{
return $this->setData(self::AMOUNT_VALUE, $amountValue);
}
public function getAmountCurrency(): ?string
{
return $this->getData(self::AMOUNT_CURRENCY);
}
public function setAmountCurrency(string $amountCurrency): NotificationInterface
{
return $this->setData(self::AMOUNT_CURRENCY, $amountCurrency);
}
public function getReason(): ?string
{
return $this->getData(self::REASON);
}
public function setReason(string $reason): NotificationInterface
{
return $this->setData(self::REASON, $reason);
}
public function getLive(): ?string
{
return $this->getData(self::LIVE);
}
public function setLive(string $live): NotificationInterface
{
return $this->setData(self::LIVE, $live);
}
public function getAdditionalData(): ?string
{
return $this->getData(self::ADDITIONAL_DATA);
}
public function setAdditionalData(string $additionalData): NotificationInterface
{
return $this->setData(self::ADDITIONAL_DATA, $additionalData);
}
public function getDone(): ?bool
{
return $this->getData(self::DONE);
}
public function setDone(bool $done): NotificationInterface
{
return $this->setData(self::DONE, $done);
}
public function getProcessing(): bool
{
return $this->getData(self::PROCESSING);
}
public function setProcessing(bool $processing): NotificationInterface
{
return $this->setData(self::PROCESSING, $processing);
}
public function getErrorCount(): ?int
{
return $this->getData(self::ERROR_COUNT);
}
public function setErrorCount(int $errorCount): NotificationInterface
{
return $this->setData(self::ERROR_COUNT, $errorCount);
}
public function getErrorMessage(): ?string
{
return $this->getData(self::ERROR_MESSAGE);
}
public function setErrorMessage(string $errorMessage): NotificationInterface
{
return $this->setData(self::ERROR_MESSAGE, $errorMessage);
}
public function getCreatedAt(): ?string
{
return $this->getData(self::CREATED_AT);
}
public function setCreatedAt(string $createdAt): NotificationInterface
{
return $this->setData(self::CREATED_AT, $createdAt);
}
public function getUpdatedAt(): ?string
{
return $this->getData(self::UPDATED_AT);
}
public function setUpdatedAt(string $timestamp): NotificationInterface
{
return $this->setData(self::UPDATED_AT, $timestamp);
}
public function isLessThan10MinutesOld(): bool
{
$createdAt = DateTime::createFromFormat('Y-m-d H:i:s', $this->getCreatedAt());
$tenMinutesAgo = new DateTime('-10 minutes');
return $createdAt >= $tenMinutesAgo;
}
}