Issues (1092)

Observer/Transactionstatus/Appointed.php (8 issues)

Labels
Severity
1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2016 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Observer\Transactionstatus;
28
29
use Magento\Sales\Model\Order;
0 ignored issues
show
The type Magento\Sales\Model\Order was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use Magento\Sales\Model\Order\Invoice;
0 ignored issues
show
The type Magento\Sales\Model\Order\Invoice was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
use Magento\Framework\Event\ObserverInterface;
0 ignored issues
show
The type Magento\Framework\Event\ObserverInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
use Magento\Framework\Event\Observer;
0 ignored issues
show
The type Magento\Framework\Event\Observer was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
0 ignored issues
show
The type Magento\Sales\Model\Order\Email\Sender\OrderSender was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
use Psr\Log\LoggerInterface;
0 ignored issues
show
The type Psr\Log\LoggerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
use Magento\Sales\Model\Service\InvoiceService;
0 ignored issues
show
The type Magento\Sales\Model\Service\InvoiceService was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
use Magento\Sales\Model\Order\Email\Sender\InvoiceSender;
0 ignored issues
show
The type Magento\Sales\Model\Orde...il\Sender\InvoiceSender was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
use Payone\Core\Helper\Base;
38
use Payone\Core\Model\PayoneConfig;
39
40
/**
41
 * Event observer for Transactionstatus appointed
42
 */
43
class Appointed implements ObserverInterface
44
{
45
    /**
46
     * Logger object
47
     *
48
     * @var LoggerInterface
49
     */
50
    protected $logger = null;
51
52
    /**
53
     * OrderSender object
54
     *
55
     * @var OrderSender
56
     */
57
    protected $orderSender = null;
58
59
    /**
60
     * InvoiceService object
61
     *
62
     * @var InvoiceService
63
     */
64
    protected $invoiceService;
65
66
    /**
67
     * InvoiceSender object
68
     *
69
     * @var InvoiceSender
70
     */
71
    protected $invoiceSender;
72
73
    /**
74
     * Payone base helper
75
     *
76
     * @var Base
77
     */
78
    protected $baseHelper;
79
80
    /**
81
     * Constructor.
82
     *
83
     * @param LoggerInterface $logger
84
     * @param OrderSender     $orderSender
85
     * @param InvoiceService  $invoiceService
86
     * @param InvoiceSender   $invoiceSender
87
     * @param Base            $baseHelper
88
     */
89
    public function __construct(
90
        LoggerInterface $logger,
91
        OrderSender $orderSender,
92
        InvoiceService $invoiceService,
93
        InvoiceSender $invoiceSender,
94
        Base $baseHelper
95
    ) {
96
        $this->logger = $logger;
97
        $this->orderSender = $orderSender;
98
        $this->invoiceService = $invoiceService;
99
        $this->invoiceSender = $invoiceSender;
100
        $this->baseHelper = $baseHelper;
101
    }
102
103
    /**
104
     * Send order confirmation mail to the customer
105
     *
106
     * @param  Observer $observer
107
     * @return void
108
     */
109
    public function execute(Observer $observer)
110
    {
111
        /* @var $oOrder Order */
112
        $oOrder = $observer->getOrder();
113
114
        // order is not guaranteed to exist if using transaction status forwarding
115
        if (null === $oOrder) {
116
            return;
117
        }
118
119
        if (!$oOrder->getEmailSent()) {
120
            // the email should not have been sent at this given moment,
121
            // but some custom modules may have changed this behaviour
122
            try {
123
                $this->orderSender->send($oOrder);
124
            } catch (\Exception $e) {
125
                $this->logger->critical($e);
126
            }
127
        }
128
129
        // preauthorization-orders and advance payment should not create an invoice
130
        if ($oOrder->getPayoneAuthmode() !== 'authorization' || $oOrder->getPayment()->getMethodInstance()->getCode() === PayoneConfig::METHOD_ADVANCE_PAYMENT || !$oOrder->canInvoice()){
131
            return;
132
        }
133
134
        if ($oOrder->getInvoiceCollection()->count() == 0) {
135
            $oInvoice = $this->invoiceService->prepareInvoice($oOrder);
136
            $oInvoice->setRequestedCaptureCase(Invoice::NOT_CAPTURE);
137
            $oInvoice->setTransactionId($oOrder->getPayment()->getLastTransId());
138
            $oInvoice->register();
139
            $oInvoice->save();
140
141
            $oOrder->save();
142
143
            if ($this->baseHelper->getConfigParam('send_invoice_email', 'emails')) {
144
                $this->invoiceSender->send($oInvoice);
145
            }
146
        }
147
    }
148
}
149