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
|
|||
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
31 | 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
32 | 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
33 | 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
34 | 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
35 | use Payone\Core\Helper\Base; |
||
36 | use Payone\Core\Model\PayoneConfig; |
||
37 | |||
38 | /** |
||
39 | * Event observer for Transactionstatus paid |
||
40 | */ |
||
41 | class Paid implements ObserverInterface |
||
42 | { |
||
43 | /** |
||
44 | * InvoiceService object |
||
45 | * |
||
46 | * @var InvoiceService |
||
47 | */ |
||
48 | protected $invoiceService; |
||
49 | |||
50 | /** |
||
51 | * InvoiceSender object |
||
52 | * |
||
53 | * @var InvoiceSender |
||
54 | */ |
||
55 | protected $invoiceSender; |
||
56 | |||
57 | /** |
||
58 | * Payone base helper |
||
59 | * |
||
60 | * @var Base |
||
61 | */ |
||
62 | protected $baseHelper; |
||
63 | |||
64 | /** |
||
65 | * Constructor. |
||
66 | * |
||
67 | * @param InvoiceService $invoiceService |
||
68 | * @param InvoiceSender $invoiceSender |
||
69 | * @param Base $baseHelper |
||
70 | */ |
||
71 | public function __construct(InvoiceService $invoiceService, InvoiceSender $invoiceSender, Base $baseHelper) |
||
72 | { |
||
73 | $this->invoiceService = $invoiceService; |
||
74 | $this->invoiceSender = $invoiceSender; |
||
75 | $this->baseHelper = $baseHelper; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Generate an invoice for the order to mark the order as paid |
||
80 | * |
||
81 | * @param Observer $observer |
||
82 | * |
||
83 | * @return void |
||
84 | */ |
||
85 | public function execute(Observer $observer) |
||
86 | { |
||
87 | /* @var $oOrder Order */ |
||
88 | $oOrder = $observer->getOrder(); |
||
89 | |||
90 | // order is not guaranteed to exist if using transaction status forwarding |
||
91 | if (NULL === $oOrder) { |
||
92 | return; |
||
93 | } |
||
94 | |||
95 | // if advance payment is paid should create an invoice |
||
96 | if ($oOrder->getPayment()->getMethodInstance()->getCode() === PayoneConfig::METHOD_ADVANCE_PAYMENT) { |
||
97 | if ($this->baseHelper->getConfigParam('create_invoice', 'payone_advance_payment', 'payone_payment')) { |
||
98 | $oInvoice = $this->invoiceService->prepareInvoice($oOrder); |
||
99 | $oInvoice->setRequestedCaptureCase(Invoice::NOT_CAPTURE); |
||
100 | $oInvoice->setTransactionId($oOrder->getPayment()->getLastTransId()); |
||
101 | $oInvoice->register(); |
||
102 | $oInvoice->save(); |
||
103 | |||
104 | $oOrder->save(); |
||
105 | |||
106 | if ($this->baseHelper->getConfigParam('send_invoice_email', 'emails')) { |
||
107 | $this->invoiceSender->send($oInvoice); |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | |||
112 | $aInvoiceList = $oOrder->getInvoiceCollection()->getItems(); |
||
113 | if ($oInvoice = array_shift($aInvoiceList)) { // get first invoice |
||
114 | $oInvoice->pay(); // mark invoice as paid |
||
115 | $oInvoice->save(); |
||
116 | $oOrder->save(); |
||
117 | } |
||
118 | } |
||
119 | } |
||
120 |
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