-
Notifications
You must be signed in to change notification settings - Fork 211
/
Order.php
722 lines (637 loc) · 27.2 KB
/
Order.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2021 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Helper;
use Adyen\Payment\Api\Data\OrderPaymentInterface;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Model\Notification;
use Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory as OrderPaymentCollectionFactory;
use Adyen\Payment\Model\ResourceModel\Creditmemo\Creditmemo as AdyenCreditMemoResourceModel;
use Adyen\Payment\Helper\Creditmemo as AdyenCreditmemoHelper;
use Adyen\Payment\Model\Creditmemo as AdyenCreditmemoModel;
use Exception;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\DB\TransactionFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Notification\NotifierPool;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\TransactionInterface;
use Magento\Sales\Model\Order as MagentoOrder;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
use Magento\Sales\Model\Order\Payment\Transaction\Builder;
use Magento\Sales\Model\OrderRepository;
use Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory as OrderStatusCollectionFactory;
class Order extends AbstractHelper
{
/** @var Builder */
private $transactionBuilder;
/** @var Data */
private $dataHelper;
/** @var AdyenLogger */
private $adyenLogger;
/** @var OrderSender */
private $orderSender;
/** @var TransactionFactory */
private $transactionFactory;
/** @var ChargedCurrency */
private $chargedCurrency;
/** @var AdyenOrderPayment */
private $adyenOrderPaymentHelper;
/** @var Config */
private $configHelper;
/** @var OrderStatusCollectionFactory */
private $orderStatusCollectionFactory;
/** @var SearchCriteriaBuilder */
private $searchCriteriaBuilder;
/** @var OrderRepository */
private $orderRepository;
/** @var NotifierPool */
private $notifierPool;
/** @var OrderPaymentCollectionFactory */
private $adyenOrderPaymentCollectionFactory;
/** @var PaymentMethods */
private $paymentMethodsHelper;
/** @var AdyenCreditMemoResourceModel */
private $adyenCreditmemoResourceModel;
/** @var AdyenCreditmemoHelper */
private $adyenCreditmemoHelper;
private MagentoOrder\StatusResolver $statusResolver;
public function __construct(
Context $context,
Builder $transactionBuilder,
Data $dataHelper,
AdyenLogger $adyenLogger,
OrderSender $orderSender,
TransactionFactory $transactionFactory,
ChargedCurrency $chargedCurrency,
AdyenOrderPayment $adyenOrderPaymentHelper,
Config $configHelper,
OrderStatusCollectionFactory $orderStatusCollectionFactory,
SearchCriteriaBuilder $searchCriteriaBuilder,
OrderRepository $orderRepository,
NotifierPool $notifierPool,
OrderPaymentCollectionFactory $adyenOrderPaymentCollectionFactory,
PaymentMethods $paymentMethodsHelper,
AdyenCreditMemoResourceModel $adyenCreditmemoResourceModel,
AdyenCreditmemoHelper $adyenCreditmemoHelper,
MagentoOrder\StatusResolver $statusResolver
) {
parent::__construct($context);
$this->transactionBuilder = $transactionBuilder;
$this->dataHelper = $dataHelper;
$this->adyenLogger = $adyenLogger;
$this->orderSender = $orderSender;
$this->transactionFactory = $transactionFactory;
$this->chargedCurrency = $chargedCurrency;
$this->adyenOrderPaymentHelper = $adyenOrderPaymentHelper;
$this->configHelper = $configHelper;
$this->orderStatusCollectionFactory = $orderStatusCollectionFactory;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->orderRepository = $orderRepository;
$this->notifierPool = $notifierPool;
$this->adyenOrderPaymentCollectionFactory = $adyenOrderPaymentCollectionFactory;
$this->paymentMethodsHelper = $paymentMethodsHelper;
$this->adyenCreditmemoResourceModel = $adyenCreditmemoResourceModel;
$this->adyenCreditmemoHelper = $adyenCreditmemoHelper;
$this->statusResolver = $statusResolver;
}
/**
* @param MagentoOrder $order
* @param Notification $notification
* @return TransactionInterface|null
* @throws \Exception
*/
public function updatePaymentDetails(MagentoOrder $order, Notification $notification): ?TransactionInterface
{
//Set order state to new because with order state payment_review it is not possible to create an invoice
if (strcmp($order->getState(), MagentoOrder::STATE_PAYMENT_REVIEW) == 0) {
$order->setState(MagentoOrder::STATE_NEW);
}
$paymentObj = $order->getPayment();
// set pspReference as transactionId
$paymentObj->setCcTransId($notification->getPspreference());
$paymentObj->setLastTransId($notification->getPspreference());
// set transaction
$paymentObj->setTransactionId($notification->getPspreference());
// Prepare transaction
$transaction = $this->transactionBuilder->setPayment($paymentObj)
->setOrder($order)
->setTransactionId($notification->getPspreference())
->build(TransactionInterface::TYPE_AUTH);
$transaction->setIsClosed(false);
$transaction->save();
return $transaction;
}
/**
* @param MagentoOrder $order
* @param Notification $notification
* @return MagentoOrder
*/
public function addWebhookStatusHistoryComment(MagentoOrder $order, Notification $notification): MagentoOrder
{
$order->addStatusHistoryComment(__(sprintf(
'%s webhook notification w/amount %s %s was processed',
$notification->getEventCode(),
$notification->getAmountCurrency(),
$this->dataHelper->originalAmount($notification->getAmountValue(), $notification->getAmountCurrency())
)), false);
return $order;
}
/**
* @param MagentoOrder $order
*/
public function sendOrderMail(MagentoOrder $order)
{
try {
$this->orderSender->send($order);
$this->adyenLogger->addAdyenNotification(
'Send order confirmation email to shopper',
[
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]
);
} catch (Exception $exception) {
$this->adyenLogger->addAdyenWarning(
"Exception in Send Mail in Magento. This is an issue in the the core of Magento" .
$exception->getMessage()
);
}
}
/**
* @param MagentoOrder $order
* @return MagentoOrder
*
* TODO: Throw exception when order cannot be shipped
*/
public function createShipment(MagentoOrder $order): MagentoOrder
{
// create shipment for cash payment
if ($order->canShip()) {
$itemQty = [];
$shipment = $order->prepareShipment($itemQty);
if ($shipment) {
$shipment->register();
$shipment->getOrder()->setIsInProcess(true);
$comment = __('Shipment created by Adyen');
$shipment->addComment($comment);
$transaction = $this->transactionFactory->create();
$transaction->addObject($shipment)
->addObject($shipment->getOrder())
->save();
}
} else {
$this->adyenLogger->addAdyenNotification(
'Order can\'t be shipped',
[
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]
);
}
return $order;
}
/**
* Finalize order by setting it to captured if manual capture is enabled, or authorized if auto capture is used
* Full order will only NOT be finalized if the full amount has not been captured/authorized.
*
* @param MagentoOrder $order
* @param Notification $notification
* @return MagentoOrder
*/
public function finalizeOrder(MagentoOrder $order, Notification $notification): MagentoOrder
{
$amount = $notification->getAmountValue();
$orderAmountCurrency = $this->chargedCurrency->getOrderAmountCurrency($order, false);
$formattedOrderAmount = $this->dataHelper->formatAmount($orderAmountCurrency->getAmount(), $orderAmountCurrency->getCurrencyCode());
$fullAmountFinalized = $this->adyenOrderPaymentHelper->isFullAmountFinalized($order);
$eventLabel = 'payment_authorized';
$status = $this->configHelper->getConfigData(
$eventLabel,
'adyen_abstract',
$order->getStoreId()
);
$possibleStates = Webhook::STATE_TRANSITION_MATRIX[$eventLabel];
// virtual order can have different statuses
if ($order->getIsVirtual()) {
$status = $this->getVirtualStatus($order, $status);
}
// check for boleto if payment is totally paid
if ($order->getPayment()->getMethod() == "adyen_boleto") {
$status = $this->paymentMethodsHelper->getBoletoStatus($order, $notification, $status);
}
$order = $this->addProcessedStatusHistoryComment($order, $notification);
if ($fullAmountFinalized) {
$this->adyenLogger->addAdyenNotification(sprintf(
'Notification w/amount %s has completed the capturing of order %s w/amount %s',
$amount,
$order->getIncrementId(),
$formattedOrderAmount
),
[
'pspReference' => $notification->getPspreference(),
'merchantReference' => $notification->getMerchantReference()
]);
$comment = "Adyen Payment Successfully completed";
// If a status is set, add comment, set status and update the state based on the status
// Else add comment
if (!empty($status)) {
$order->addStatusHistoryComment(__($comment), $status);
$this->setState($order, $status, $possibleStates);
$this->adyenLogger->addAdyenNotification(
'Order status was changed to authorised status: ' . $status,
array_merge(
$this->adyenLogger->getOrderContext($order),
['pspReference' => $notification->getPspreference()]
)
);
} else {
$order->addStatusHistoryComment(__($comment));
$this->adyenLogger->addAdyenNotification(sprintf(
'Order %s was finalized. Authorised status not set',
$order->getIncrementId()
),
[
'pspReference' => $notification->getPspreference(),
'merchantReference' => $notification->getMerchantReference()
]);
}
} else {
/*
* Set order status back to pre_payment_authorized if the order state is payment_review.
* Otherwise, capture-cancel-refund is not possible.
*/
if ($order->getState() === MagentoOrder::STATE_PAYMENT_REVIEW) {
$order = $this->setPrePaymentAuthorized($order);
}
}
return $order;
}
/**
* @param MagentoOrder $order
* @param Notification $notification
* @return MagentoOrder
*/
public function addProcessedStatusHistoryComment(MagentoOrder $order, Notification $notification): MagentoOrder
{
$order->addStatusHistoryComment(__(sprintf(
'%s webhook notification w/amount %s %s was processed',
$notification->getEventCode(),
$notification->getAmountCurrency(),
$this->dataHelper->originalAmount($notification->getAmountValue(), $notification->getAmountCurrency())
)), false);
return $order;
}
/**
* Set status on authorisation
*
* @param MagentoOrder $order
*
* @return MagentoOrder
*/
public function setPrePaymentAuthorized(MagentoOrder $order): MagentoOrder
{
$eventLabel = "payment_pre_authorized";
$status = $this->configHelper->getConfigData(
$eventLabel,
'adyen_abstract',
$order->getStoreId()
);
$possibleStates = Webhook::STATE_TRANSITION_MATRIX[$eventLabel];
// only do this if status in configuration is set
if (!empty($status)) {
$order->setStatus($status);
$order = $this->setState($order, $status, $possibleStates);
$this->adyenLogger->addAdyenNotification(
'Order status is changed to Pre-authorised status, status is ' . $status,
[
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]
);
} else {
$this->adyenLogger->addAdyenNotification(
'No pre-authorised status is used so ignore',
[
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]
);
}
return $order;
}
public function setStatusOrderCreation(OrderInterface $order): OrderInterface
{
$paymentMethod = $order->getPayment()->getMethod();
// Fetch the default order status for order creation from the configuration.
$status = $this->configHelper->getConfigData(
'order_status',
$paymentMethod,
$order->getStoreId()
);
if (is_null($status)) {
// If the configuration doesn't exist, use the default status.
$status = $this->statusResolver->getOrderStatusByState($order, MagentoOrder::STATE_NEW);
}
$order->setStatus($status);
$order->setState(MagentoOrder::STATE_NEW);
return $order;
}
/**
* @param MagentoOrder $order
* @param $ignoreHasInvoice
* @return MagentoOrder
* @throws LocalizedException
*/
public function holdCancelOrder(MagentoOrder $order, $ignoreHasInvoice): MagentoOrder
{
if (!$this->configHelper->getNotificationsCanCancel($order->getStoreId())) {
$this->adyenLogger->addAdyenNotification(
'Order cannot be cancelled based on the plugin configuration',
[
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]
);
return $order;
}
$orderStatus = $this->configHelper->getConfigData(
'payment_cancelled',
'adyen_abstract',
$order->getStoreId()
);
// check if order has in invoice only cancel/hold if this is not the case
if ($ignoreHasInvoice || !$order->hasInvoices()) {
if ($orderStatus == MagentoOrder::STATE_HOLDED) {
// Allow magento to hold order
$order->setActionFlag(MagentoOrder::ACTION_FLAG_HOLD, true);
if ($order->canHold()) {
$order->hold();
$order->addCommentToStatusHistory('Order held', $orderStatus);
} else {
$this->adyenLogger->addAdyenNotification(
'Order can not hold or is already on Hold',
[
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]
);
}
} else {
// Allow magento to cancel order
$order->setActionFlag(MagentoOrder::ACTION_FLAG_CANCEL, true);
if ($order->canCancel()) {
$order->cancel();
$order->addCommentToStatusHistory('Order cancelled', $orderStatus ?? false);
} else {
$this->adyenLogger->addAdyenNotification(
'Order can not be cancelled',
[
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]
);
}
}
} else {
$this->adyenLogger->addAdyenNotification(sprintf(
'Order %s already has an invoice linked so it cannot be cancelled', $order->getIncrementId()
), [
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]);
}
return $order;
}
public function addRefundFailedNotice(MagentoOrder $order, Notification $notification): Notification
{
$description = __(
"Reason: %1 | PSPReference: %2 | You can go to Adyen Customer Area
and trigger this refund manually or contact our support.",
$notification->getReason(),
$notification->getPspreference()
);
$this->notifierPool->addNotice(
__("Adyen: Refund for order #%1 has failed", $notification->getMerchantReference()),
$description,
$this->dataHelper->getPspReferenceSearchUrl($notification->getPspreference(), $notification->getLive())
);
$order->addStatusHistoryComment(__(
sprintf('Refund has failed. Unable to change back status of the order.<br /> %s', $description)
), $order->getStatus());
$linkedAdyenCreditmemo = $this->adyenCreditmemoHelper->getAdyenCreditmemoByPspreference(
$notification->getPspreference()
);
if ($linkedAdyenCreditmemo instanceof AdyenCreditmemoModel) {
$this->adyenCreditmemoHelper->updateAdyenCreditmemosStatus(
$linkedAdyenCreditmemo,
AdyenCreditmemoModel::FAILED_STATUS
);
}
return $notification;
}
/**
* Set order state, based on the passed status
*
* @param MagentoOrder $order
* @param $status
* @param $possibleStates
* @return MagentoOrder
*/
private function setState(MagentoOrder $order, $status, $possibleStates): MagentoOrder
{
// Loop over possible states, select first available status that fits this state
foreach ($possibleStates as $state) {
$statusObject = $this->orderStatusCollectionFactory->create()
->addFieldToFilter('main_table.status', $status)
->joinStates()
->addStateFilter($state)
->getFirstItem();
if ($statusObject->getState() == $state) {
// Exit function if fitting state is found
$order->setState($statusObject->getState());
$this->adyenLogger->addAdyenNotification(
'State is changed to ' . $statusObject->getState(),
[
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]
);
return $order;
}
}
$this->adyenLogger->addAdyenNotification(
'No new state assigned, status should be connected to one of the following states: ' . json_encode($possibleStates),
[
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]);
return $order;
}
/**
* Set the order data member by fetching the entity from the database.
* This should be moved out of this file in the future.
* @param Notification $notification
* @return false|\Magento\Sales\Api\Data\OrderInterface
*/
public function fetchOrderByIncrementId(Notification $notification)
{
$incrementId = $notification->getMerchantReference();
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('increment_id', $incrementId, 'eq')
->create();
$orderList = $this->orderRepository->getList($searchCriteria)->getItems();
/** @var MagentoOrder $order */
return reset($orderList);
}
/**
* @param MagentoOrder $order
* @param Notification $notification
* @return void
* @throws Exception
*/
public function refundOrder(MagentoOrder $order, Notification $notification): MagentoOrder
{
/*
* Update AdyenOrderPayment entity with the refund
*/
/** @var OrderPaymentInterface $orderPayment */
$orderPayment = $this->adyenOrderPaymentCollectionFactory
->create()
->addFieldToFilter(Notification::PSPREFRENCE, $notification->getOriginalReference())
->getFirstItem();
$this->adyenOrderPaymentHelper->refundAdyenOrderPayment($orderPayment, $notification);
$this->adyenLogger->addAdyenNotification(
sprintf(
'Refunding %s from AdyenOrderPayment %s',
$notification->getAmountCurrency() . $notification->getAmountValue(),
$orderPayment->getEntityId()
),
array_merge(
$this->adyenLogger->getOrderContext($order),
['pspReference' => $notification->getPspreference()]
)
);
/*
* Check adyen_creditmemo table.
* If credit memo doesn't exist for this notification, create it.
*/
$linkedAdyenCreditmemo = $this->adyenCreditmemoHelper->getAdyenCreditmemoByPspreference(
$notification->getPspreference()
);
if (is_null($linkedAdyenCreditmemo)) {
if ($order->canCreditmemo()) {
$amount = $this->dataHelper->originalAmount(
$notification->getAmountValue(),
$notification->getAmountCurrency()
);
$linkedAdyenCreditmemo = $this->adyenCreditmemoHelper->createAdyenCreditMemo(
$order->getPayment(),
$notification->getPspreference(),
$notification->getOriginalReference(),
$amount
);
/*
* Following method will try to create the credit memo for this order.
* If the credit memo can't be created, this method will also provide comment history to warn
* merchant to create an offline credit memo.
* For the Adyen Customer Area initiated refunds, order currency and the store currency should match
* and the full amount should be refunded at once.
*/
$payment = $order->getPayment()->registerRefundNotification($amount);
if (!is_null($payment->getCreditmemo())) {
/*
* Since the full amount is refunded and the credit memo is created,
* now the order can be closed by plugin. This call is required since
* `registerRefundNotification()` function changes the status to `processing` again.
*/
$order->setState(MagentoOrder::STATE_CLOSED);
$order->setStatus($order->getConfig()->getStateDefaultStatus(MagentoOrder::STATE_CLOSED));
$this->adyenLogger->addAdyenNotification(
sprintf('Created credit memo for order %s', $order->getIncrementId()),
array_merge(
$this->adyenLogger->getOrderContext($order),
['pspReference' => $notification->getPspreference()]
)
);
}
} else {
$this->adyenLogger->addAdyenNotification(
sprintf(
'Could not create a credit memo for order %s while processing notification %s',
$order->getIncrementId(),
$notification->getId()
),
array_merge(
$this->adyenLogger->getOrderContext($order),
['pspReference' => $notification->getPspreference()]
)
);
}
} else {
$this->adyenLogger->addAdyenNotification(
sprintf(
'Did not create a credit memo for order %s. '
. 'Because credit memo already exists for this refund request %s',
$order->getIncrementId(),
$notification->getPspreference()
),
array_merge(
$this->adyenLogger->getOrderContext($order),
['pspReference' => $notification->getPspreference()]
)
);
}
if ($linkedAdyenCreditmemo instanceof AdyenCreditmemoModel) {
$this->adyenCreditmemoHelper->updateAdyenCreditmemosStatus(
$linkedAdyenCreditmemo, AdyenCreditmemoModel::COMPLETED_STATUS
);
}
$order->addStatusHistoryComment(__(sprintf(
'%s Webhook successfully handled',
$notification->getEventCode())), $order->getStatus());
return $order;
}
public function getOrderByIncrementId(string $incrementId): ?OrderInterface
{
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('increment_id', $incrementId)
->create();
$orders = $this->orderRepository->getList($searchCriteria)->getItems();
return $orders ? reset($orders) : null;
}
/**
* If the payment_authorized_virtual config is set, return the virtual status
*
* @param MagentoOrder $order
* @param $status
* @return mixed
*/
private function getVirtualStatus(MagentoOrder $order, $status)
{
$this->adyenLogger->addAdyenNotification(
'Product is a virtual product',
[
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]);
$virtualStatus = $this->configHelper->getConfigData(
'payment_authorized_virtual',
'adyen_abstract',
$order->getStoreId()
);
if ($virtualStatus != "") {
$status = $virtualStatus;
}
return $status;
}
}