-
Notifications
You must be signed in to change notification settings - Fork 211
/
Copy pathPaymentInformationResetOrderId.php
78 lines (70 loc) · 1.99 KB
/
PaymentInformationResetOrderId.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
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2019 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Plugin;
use Adyen\Payment\Helper\PaymentMethods;
use Adyen\Payment\Logger\AdyenLogger;
use Exception;
use Magento\Checkout\Api\PaymentInformationManagementInterface;
use Magento\Quote\Api\CartRepositoryInterface;
class PaymentInformationResetOrderId
{
/**
* Quote repository.
*
* @var CartRepositoryInterface
*/
protected $quoteRepository;
/**
* Payment methods helper
*
* @var PaymentMethods
*/
protected $paymentMethodsHelper;
/**
* @var AdyenLogger
*/
protected $adyenLogger;
/**
* PaymentInformationResetOrderId constructor.
* @param CartRepositoryInterface $quoteRepository
* @param PaymentMethods $paymentMethodsHelper
* @param AdyenLogger $adyenLogger
*/
public function __construct(
CartRepositoryInterface $quoteRepository,
PaymentMethods $paymentMethodsHelper,
AdyenLogger $adyenLogger
) {
$this->quoteRepository = $quoteRepository;
$this->paymentMethodsHelper = $paymentMethodsHelper;
$this->adyenLogger = $adyenLogger;
}
/**
* @param PaymentInformationManagementInterface $subject
* @param $cartId
* @return null
*/
public function beforeSavePaymentInformationAndPlaceOrder(
PaymentInformationManagementInterface $subject,
$cartId
) {
try {
$quote = $this->quoteRepository->get($cartId);
$method = strval($quote->getPayment()->getMethod());
if ($this->paymentMethodsHelper->isAdyenPayment($method)) {
$quote->setReservedOrderId(null);
}
} catch (Exception $e) {
$this->adyenLogger->error("Failed to reset reservedOrderId " . $e->getMessage());
}
return null;
}
}