Issues (1092)

Controller/Mandate/Download.php (7 issues)

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\Controller\Mandate;
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
31
/**
32
 * Controller for mandate download
33
 */
34
class Download extends \Magento\Framework\App\Action\Action
0 ignored issues
show
The type Magento\Framework\App\Action\Action 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
{
36
    /**
37
     * Checkout session
38
     *
39
     * @var \Magento\Checkout\Model\Session
0 ignored issues
show
The type Magento\Checkout\Model\Session 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...
40
     */
41
    protected $checkoutSession;
42
43
    /**
44
     * Payone getfile request model
45
     *
46
     * @var \Payone\Core\Model\Api\Request\Getfile
47
     */
48
    protected $getfileRequest;
49
50
    /**
51
     * PAYONE payment helper
52
     *
53
     * @var \Payone\Core\Helper\Payment
54
     */
55
    protected $paymentHelper;
56
57
    /**
58
     * Result factory for file-download
59
     *
60
     * @var \Magento\Framework\Controller\Result\RawFactory
0 ignored issues
show
The type Magento\Framework\Controller\Result\RawFactory 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...
61
     */
62
    protected $resultRawFactory;
63
64
    /**
65
     * Order object
66
     *
67
     * @var Order
68
     */
69
    protected $oOrder = null;
70
71
    /**
72
     * Constructor
73
     *
74
     * @param \Magento\Framework\App\Action\Context           $context
75
     * @param \Magento\Checkout\Model\Session                 $checkoutSession
76
     * @param \Payone\Core\Model\Api\Request\Getfile          $getfileRequest
77
     * @param \Payone\Core\Helper\Payment                     $paymentHelper
78
     * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
79
     */
80
    public function __construct(
81
        \Magento\Framework\App\Action\Context $context,
0 ignored issues
show
The type Magento\Framework\App\Action\Context 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...
82
        \Magento\Checkout\Model\Session $checkoutSession,
83
        \Payone\Core\Model\Api\Request\Getfile $getfileRequest,
84
        \Payone\Core\Helper\Payment $paymentHelper,
85
        \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
86
    ) {
87
        parent::__construct($context);
88
        $this->checkoutSession = $checkoutSession;
89
        $this->getfileRequest = $getfileRequest;
90
        $this->paymentHelper = $paymentHelper;
91
        $this->resultRawFactory = $resultRawFactory;
92
    }
93
94
    /**
95
     * Get order object
96
     *
97
     * @return Order
98
     */
99
    protected function getOrder()
100
    {
101
        if ($this->oOrder === null) {
102
            $this->oOrder = $this->checkoutSession->getLastRealOrder();
103
        }
104
        return $this->oOrder;
105
    }
106
107
    /**
108
     * Get pdf-file string
109
     *
110
     * @return string
111
     */
112
    protected function getMandate()
113
    {
114
        $oOrder = $this->getOrder();
115
        $oPayment = $oOrder->getPayment()->getMethodInstance();
116
        $sMandate = $this->getfileRequest->sendRequest($oOrder, $oPayment);
117
        return $sMandate;
118
    }
119
120
    /**
121
     * Output mandate as pdf download
122
     *
123
     * @return \Magento\Framework\Controller\Result\Raw
0 ignored issues
show
The type Magento\Framework\Controller\Result\Raw 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...
124
     */
125
    public function execute()
126
    {
127
        $oResultRaw = $this->resultRawFactory->create();
128
        $sContent = 'Error';
129
        if ($this->paymentHelper->isMandateManagementDownloadActive()) {
130
            $oOrder = $this->getOrder();
131
            $sContent = 'Error - order not found';
132
            if ($oOrder) {
0 ignored issues
show
$oOrder is of type Magento\Sales\Model\Order, thus it always evaluated to true.
Loading history...
133
                $sContent = $this->getMandate();
134
                $sFilename = $oOrder->getPayoneMandateId().'.pdf';
135
136
                $oResultRaw->setHeader("Content-Type", "application/pdf", true);
137
                $oResultRaw->setHeader("Content-Disposition", 'attachment; filename="'.$sFilename.'"', true);
138
            }
139
        }
140
        $oResultRaw->setContents($sContent);
141
        return $oResultRaw;
142
    }
143
}
144