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 - 2017 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\Onepage; |
||
28 | |||
29 | use Magento\Framework\View\Result\Page; |
||
0 ignored issues
–
show
|
|||
30 | use Magento\Quote\Model\Quote; |
||
0 ignored issues
–
show
The type
Magento\Quote\Model\Quote 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\Framework\Controller\ResultFactory; |
||
0 ignored issues
–
show
The type
Magento\Framework\Controller\ResultFactory 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\Framework\Controller\Result\Redirect as CoreRedirect; |
||
0 ignored issues
–
show
The type
Magento\Framework\Controller\Result\Redirect 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 Payone\Core\Model\Methods\AmazonPayV2; |
||
34 | use Payone\Core\Model\PayoneConfig; |
||
35 | |||
36 | /** |
||
37 | * Controller for mandate management with debit payment |
||
38 | */ |
||
39 | class Review 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
40 | { |
||
41 | /** |
||
42 | * Checkout session |
||
43 | * |
||
44 | * @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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
45 | */ |
||
46 | protected $checkoutSession; |
||
47 | |||
48 | /** |
||
49 | * Page result factory |
||
50 | * |
||
51 | * @var \Magento\Framework\View\Result\PageFactory |
||
0 ignored issues
–
show
The type
Magento\Framework\View\Result\PageFactory 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 ![]() |
|||
52 | */ |
||
53 | protected $pageFactory; |
||
54 | |||
55 | /** |
||
56 | * @var \Magento\Quote\Api\CartRepositoryInterface |
||
0 ignored issues
–
show
The type
Magento\Quote\Api\CartRepositoryInterface 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 ![]() |
|||
57 | */ |
||
58 | protected $quoteRepository; |
||
59 | |||
60 | /** |
||
61 | * @var \Payone\Core\Model\Api\Request\Genericpayment\UpdateCheckoutSession |
||
62 | */ |
||
63 | protected $updateCheckoutSession; |
||
64 | |||
65 | /** |
||
66 | * List of all PAYONE payment methods available for this review step |
||
67 | * |
||
68 | * @var array |
||
69 | */ |
||
70 | protected $availableReviewMethods = [ |
||
71 | PayoneConfig::METHOD_PAYPAL, |
||
72 | PayoneConfig::METHOD_PAYPALV2, |
||
73 | PayoneConfig::METHOD_AMAZONPAYV2, |
||
74 | ]; |
||
75 | |||
76 | /** |
||
77 | * Constructor |
||
78 | * |
||
79 | * @param \Magento\Framework\App\Action\Context $context |
||
80 | * @param \Magento\Checkout\Model\Session $checkoutSession |
||
81 | * @param \Magento\Framework\View\Result\PageFactory $pageFactory |
||
82 | * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository |
||
83 | * @param \Payone\Core\Model\Api\Request\Genericpayment\UpdateCheckoutSession $updateCheckoutSession |
||
84 | */ |
||
85 | public function __construct( |
||
86 | \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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
87 | \Magento\Checkout\Model\Session $checkoutSession, |
||
88 | \Magento\Framework\View\Result\PageFactory $pageFactory, |
||
89 | \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, |
||
90 | \Payone\Core\Model\Api\Request\Genericpayment\UpdateCheckoutSession $updateCheckoutSession |
||
91 | ) { |
||
92 | parent::__construct($context); |
||
93 | $this->checkoutSession = $checkoutSession; |
||
94 | $this->pageFactory = $pageFactory; |
||
95 | $this->quoteRepository = $quoteRepository; |
||
96 | $this->updateCheckoutSession = $updateCheckoutSession; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Render order review |
||
101 | * Redirect to basket if quote or payment is missing |
||
102 | * |
||
103 | * @return null|Page|CoreRedirect |
||
104 | */ |
||
105 | public function execute() |
||
106 | { |
||
107 | if ($this->canReviewBeShown() === false) { |
||
108 | /** @var CoreRedirect $resultRedirect */ |
||
109 | $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); |
||
110 | return $resultRedirect->setPath('checkout'); |
||
111 | } |
||
112 | |||
113 | $oPageObject = $this->pageFactory->create(); |
||
114 | |||
115 | $sSelectedShippingMethod = $this->getRequest()->getParam('shipping_method'); |
||
116 | if ($sSelectedShippingMethod) { |
||
117 | $this->updateShippingMethod($sSelectedShippingMethod); |
||
118 | } |
||
119 | |||
120 | return $oPageObject; |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * Validates if the review step can be shown by checking some status flags |
||
125 | * |
||
126 | * @return bool |
||
127 | */ |
||
128 | protected function canReviewBeShown() |
||
129 | { |
||
130 | if (!in_array($this->checkoutSession->getQuote()->getPayment()->getMethod(), $this->availableReviewMethods)) { |
||
131 | return false; |
||
132 | } |
||
133 | |||
134 | $sWorkorderId = $this->checkoutSession->getPayoneWorkorderId(); |
||
135 | if (empty($sWorkorderId)) { |
||
136 | return false; |
||
137 | } |
||
138 | return true; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Update shipping method |
||
143 | * |
||
144 | * @param string $sShippingMethod |
||
145 | * @return void |
||
146 | */ |
||
147 | protected function updateShippingMethod($sShippingMethod) |
||
148 | { |
||
149 | $oQuote = $this->checkoutSession->getQuote(); |
||
150 | $oShippingAddress = $oQuote->getShippingAddress(); |
||
151 | if (!$oQuote->getIsVirtual() && $oShippingAddress) { |
||
152 | if ($sShippingMethod != $oShippingAddress->getShippingMethod()) { |
||
153 | $this->ignoreAddressValidation($oQuote); |
||
154 | $oShippingAddress->setShippingMethod($sShippingMethod)->setCollectShippingRates(true); |
||
155 | $cartExtension = $oQuote->getExtensionAttributes(); |
||
156 | if ($cartExtension && $cartExtension->getShippingAssignments()) { |
||
157 | $cartExtension->getShippingAssignments()[0]->getShipping()->setMethod($sShippingMethod); |
||
158 | } |
||
159 | $oQuote->collectTotals(); |
||
160 | $this->quoteRepository->save($oQuote); |
||
161 | |||
162 | $oPayment = $oQuote->getPayment()->getMethodInstance(); |
||
163 | $sWorkorderId = $this->checkoutSession->getPayoneWorkorderId(); |
||
164 | if ($oPayment instanceof AmazonPayV2) { |
||
165 | $this->updateCheckoutSession->sendRequest($oPayment, $oQuote, $sWorkorderId); |
||
166 | } |
||
167 | } |
||
168 | } |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * Disable validation to make sure addresses will always be saved |
||
173 | * |
||
174 | * @param Quote $oQuote |
||
175 | * @return void |
||
176 | */ |
||
177 | protected function ignoreAddressValidation(Quote $oQuote) |
||
178 | { |
||
179 | $oQuote->getBillingAddress()->setShouldIgnoreValidation(true); |
||
180 | if (!$oQuote->getIsVirtual()) { |
||
181 | $oQuote->getShippingAddress()->setShouldIgnoreValidation(true); |
||
182 | } |
||
183 | } |
||
184 | } |
||
185 |
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