PAYONE-GmbH /
magento-2
| 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\Block\Onepage; |
||||
| 28 | |||||
| 29 | use Magento\Checkout\Model\Session; |
||||
|
0 ignored issues
–
show
|
|||||
| 30 | use Magento\Framework\Pricing\PriceCurrencyInterface; |
||||
|
0 ignored issues
–
show
The type
Magento\Framework\Pricing\PriceCurrencyInterface 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 Loading history...
|
|||||
| 31 | use Magento\Quote\Model\Quote\Address\Rate; |
||||
|
0 ignored issues
–
show
The type
Magento\Quote\Model\Quote\Address\Rate 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 Loading history...
|
|||||
| 32 | use Magento\Quote\Model\Quote\Address; |
||||
|
0 ignored issues
–
show
The type
Magento\Quote\Model\Quote\Address 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 Loading history...
|
|||||
| 33 | use Magento\Framework\DataObject; |
||||
|
0 ignored issues
–
show
The type
Magento\Framework\DataObject 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 Loading history...
|
|||||
| 34 | use Payone\Core\Model\PayoneConfig; |
||||
| 35 | |||||
| 36 | /** |
||||
| 37 | * Order review block |
||||
| 38 | */ |
||||
| 39 | class Review extends \Magento\Framework\View\Element\Template |
||||
|
0 ignored issues
–
show
The type
Magento\Framework\View\Element\Template 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 Loading history...
|
|||||
| 40 | { |
||||
| 41 | /** |
||||
| 42 | * Template |
||||
| 43 | * |
||||
| 44 | * @var string |
||||
| 45 | */ |
||||
| 46 | protected $_template = 'Payone_Core::onepage/review.phtml'; |
||||
| 47 | |||||
| 48 | /** |
||||
| 49 | * @var \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 Loading history...
|
|||||
| 50 | */ |
||||
| 51 | protected $_quote; |
||||
| 52 | |||||
| 53 | /** |
||||
| 54 | * @var \Magento\Quote\Model\Quote\Address |
||||
| 55 | */ |
||||
| 56 | protected $_address; |
||||
| 57 | |||||
| 58 | /** |
||||
| 59 | * @var \Magento\Customer\Model\Address\Config |
||||
|
0 ignored issues
–
show
The type
Magento\Customer\Model\Address\Config 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 Loading history...
|
|||||
| 60 | */ |
||||
| 61 | protected $_addressConfig; |
||||
| 62 | |||||
| 63 | /** |
||||
| 64 | * Currently selected shipping rate |
||||
| 65 | * |
||||
| 66 | * @var Rate |
||||
| 67 | */ |
||||
| 68 | protected $_currentShippingRate = null; |
||||
| 69 | |||||
| 70 | /** |
||||
| 71 | * Paypal controller path |
||||
| 72 | * |
||||
| 73 | * @var string |
||||
| 74 | */ |
||||
| 75 | protected $_controllerPath = 'payone/onepage'; |
||||
| 76 | |||||
| 77 | /** |
||||
| 78 | * @var \Magento\Tax\Helper\Data |
||||
|
0 ignored issues
–
show
The type
Magento\Tax\Helper\Data 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 Loading history...
|
|||||
| 79 | */ |
||||
| 80 | protected $_taxHelper; |
||||
| 81 | |||||
| 82 | /** |
||||
| 83 | * @var PriceCurrencyInterface |
||||
| 84 | */ |
||||
| 85 | protected $priceCurrency; |
||||
| 86 | |||||
| 87 | /** |
||||
| 88 | * Checkout session object |
||||
| 89 | * |
||||
| 90 | * @var Session |
||||
| 91 | */ |
||||
| 92 | protected $checkoutSession; |
||||
| 93 | |||||
| 94 | /** |
||||
| 95 | * @var \Payone\Core\Helper\Shop |
||||
| 96 | */ |
||||
| 97 | protected $shopHelper; |
||||
| 98 | |||||
| 99 | /** |
||||
| 100 | * @var \Payone\Core\Helper\Database |
||||
| 101 | */ |
||||
| 102 | protected $databaseHelper; |
||||
| 103 | |||||
| 104 | /** |
||||
| 105 | * @param \Magento\Framework\View\Element\Template\Context $context |
||||
| 106 | * @param \Magento\Tax\Helper\Data $taxHelper |
||||
| 107 | * @param \Magento\Customer\Model\Address\Config $addressConfig |
||||
| 108 | * @param PriceCurrencyInterface $priceCurrency |
||||
| 109 | * @param Session $checkoutSession |
||||
| 110 | * @param \Payone\Core\Helper\Shop $shopHelper |
||||
| 111 | * @param \Payone\Core\Helper\Database $databaseHelper |
||||
| 112 | * @param array $data |
||||
| 113 | */ |
||||
| 114 | public function __construct( |
||||
| 115 | \Magento\Framework\View\Element\Template\Context $context, |
||||
|
0 ignored issues
–
show
The type
Magento\Framework\View\Element\Template\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 Loading history...
|
|||||
| 116 | \Magento\Tax\Helper\Data $taxHelper, |
||||
| 117 | \Magento\Customer\Model\Address\Config $addressConfig, |
||||
| 118 | PriceCurrencyInterface $priceCurrency, |
||||
| 119 | Session $checkoutSession, |
||||
| 120 | \Payone\Core\Helper\Shop $shopHelper, |
||||
| 121 | \Payone\Core\Helper\Database $databaseHelper, |
||||
| 122 | array $data = [] |
||||
| 123 | ) { |
||||
| 124 | parent::__construct($context, $data); |
||||
| 125 | $this->priceCurrency = $priceCurrency; |
||||
| 126 | $this->_taxHelper = $taxHelper; |
||||
| 127 | $this->_addressConfig = $addressConfig; |
||||
| 128 | $this->checkoutSession = $checkoutSession; |
||||
| 129 | $this->shopHelper = $shopHelper; |
||||
| 130 | $this->databaseHelper = $databaseHelper; |
||||
| 131 | $this->getQuote(); // fill quote property |
||||
| 132 | } |
||||
| 133 | |||||
| 134 | /** |
||||
| 135 | * Return checkout quote object |
||||
| 136 | * |
||||
| 137 | * @return \Magento\Quote\Model\Quote |
||||
| 138 | */ |
||||
| 139 | protected function getQuote() |
||||
| 140 | { |
||||
| 141 | if (!$this->_quote) { |
||||
| 142 | $this->_quote = $this->checkoutSession->getQuote(); |
||||
| 143 | } |
||||
| 144 | return $this->_quote; |
||||
| 145 | } |
||||
| 146 | |||||
| 147 | /** |
||||
| 148 | * Return quote billing address |
||||
| 149 | * |
||||
| 150 | * @return Address |
||||
| 151 | */ |
||||
| 152 | public function getBillingAddress() |
||||
| 153 | { |
||||
| 154 | $oBillingAddress = $this->_quote->getBillingAddress(); |
||||
| 155 | return $oBillingAddress; |
||||
| 156 | } |
||||
| 157 | |||||
| 158 | /** |
||||
| 159 | * Return quote shipping address |
||||
| 160 | * |
||||
| 161 | * @return false|Address |
||||
| 162 | */ |
||||
| 163 | public function getShippingAddress() |
||||
| 164 | { |
||||
| 165 | if ($this->_quote->getIsVirtual()) { |
||||
| 166 | return false; |
||||
| 167 | } |
||||
| 168 | return $this->_quote->getShippingAddress(); |
||||
| 169 | } |
||||
| 170 | |||||
| 171 | /** |
||||
| 172 | * Get HTML output for specified address |
||||
| 173 | * |
||||
| 174 | * @param Address $address |
||||
| 175 | * @return string |
||||
| 176 | */ |
||||
| 177 | public function renderAddress(Address $address) |
||||
| 178 | { |
||||
| 179 | /** @var \Magento\Customer\Block\Address\Renderer\RendererInterface $renderer */ |
||||
| 180 | $renderer = $this->_addressConfig->getFormatByCode('html')->getRenderer(); |
||||
| 181 | $addressData = \Magento\Framework\Convert\ConvertArray::toFlatArray($address->getData()); |
||||
|
0 ignored issues
–
show
The type
Magento\Framework\Convert\ConvertArray 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 Loading history...
|
|||||
| 182 | return $renderer->renderArray($addressData); |
||||
| 183 | } |
||||
| 184 | |||||
| 185 | /** |
||||
| 186 | * Return carrier name from config, base on carrier code |
||||
| 187 | * |
||||
| 188 | * @param string $carrierCode |
||||
| 189 | * @return string |
||||
| 190 | */ |
||||
| 191 | public function getCarrierName($carrierCode) |
||||
| 192 | { |
||||
| 193 | if ($name = $this->_scopeConfig->getValue("carriers/{$carrierCode}/title", \Magento\Store\Model\ScopeInterface::SCOPE_STORES)) { |
||||
|
0 ignored issues
–
show
The type
Magento\Store\Model\ScopeInterface 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 Loading history...
|
|||||
| 194 | return $name; |
||||
| 195 | } |
||||
| 196 | return $carrierCode; |
||||
| 197 | } |
||||
| 198 | |||||
| 199 | /** |
||||
| 200 | * Get either shipping rate code or empty value on error |
||||
| 201 | * |
||||
| 202 | * @param DataObject $rate |
||||
| 203 | * @return string |
||||
| 204 | */ |
||||
| 205 | public function renderShippingRateValue(DataObject $rate) |
||||
| 206 | { |
||||
| 207 | if ($rate->getErrorMessage()) { |
||||
| 208 | return ''; |
||||
| 209 | } |
||||
| 210 | return $rate->getCode(); |
||||
| 211 | } |
||||
| 212 | |||||
| 213 | /** |
||||
| 214 | * Get shipping rate code title and its price or error message |
||||
| 215 | * |
||||
| 216 | * @param DataObject $rate |
||||
| 217 | * @param string $format |
||||
| 218 | * @param string $inclTaxFormat |
||||
| 219 | * @return string |
||||
| 220 | */ |
||||
| 221 | public function renderShippingRateOption(DataObject $rate, $format = '%s - %s%s', $inclTaxFormat = ' (%s %s)') |
||||
| 222 | { |
||||
| 223 | $renderedInclTax = ''; |
||||
| 224 | if ($rate->getErrorMessage()) { |
||||
| 225 | $price = $rate->getErrorMessage(); |
||||
| 226 | } else { |
||||
| 227 | $price = $this->_getShippingPrice( |
||||
| 228 | $rate->getPrice(), |
||||
| 229 | $this->_taxHelper->displayShippingPriceIncludingTax() |
||||
| 230 | ); |
||||
| 231 | |||||
| 232 | $incl = $this->_getShippingPrice($rate->getPrice(), true); |
||||
| 233 | if ($incl != $price && $this->_taxHelper->displayShippingBothPrices()) { |
||||
| 234 | $renderedInclTax = sprintf($inclTaxFormat, $this->escapeHtml(__('Incl. Tax')), $incl); |
||||
|
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 235 | } |
||||
| 236 | } |
||||
| 237 | return sprintf($format, $this->escapeHtml($rate->getMethodTitle()), $price, $renderedInclTax); |
||||
| 238 | } |
||||
| 239 | |||||
| 240 | /** |
||||
| 241 | * Getter for current shipping rate |
||||
| 242 | * |
||||
| 243 | * @return Rate |
||||
| 244 | */ |
||||
| 245 | public function getCurrentShippingRate() |
||||
| 246 | { |
||||
| 247 | return $this->_currentShippingRate; |
||||
| 248 | } |
||||
| 249 | |||||
| 250 | /** |
||||
| 251 | * Get quote email |
||||
| 252 | * |
||||
| 253 | * @return string |
||||
| 254 | */ |
||||
| 255 | public function getEmail() |
||||
| 256 | { |
||||
| 257 | $billingAddress = $this->getBillingAddress(); |
||||
| 258 | return $billingAddress ? $billingAddress->getEmail() : ''; |
||||
|
0 ignored issues
–
show
|
|||||
| 259 | } |
||||
| 260 | |||||
| 261 | /** |
||||
| 262 | * Return formatted shipping price |
||||
| 263 | * |
||||
| 264 | * @param float $price |
||||
| 265 | * @param bool $isInclTax |
||||
| 266 | * @return string |
||||
| 267 | */ |
||||
| 268 | protected function _getShippingPrice($price, $isInclTax) |
||||
| 269 | { |
||||
| 270 | return $this->_formatPrice($this->_taxHelper->getShippingPrice($price, $isInclTax, $this->_address)); |
||||
| 271 | } |
||||
| 272 | |||||
| 273 | /** |
||||
| 274 | * Format price base on store convert price method |
||||
| 275 | * |
||||
| 276 | * @param float $price |
||||
| 277 | * @return string |
||||
| 278 | */ |
||||
| 279 | protected function _formatPrice($price) |
||||
| 280 | { |
||||
| 281 | return $this->priceCurrency->convertAndFormat( |
||||
| 282 | $price, |
||||
| 283 | true, |
||||
| 284 | PriceCurrencyInterface::DEFAULT_PRECISION, |
||||
| 285 | $this->_quote->getStore() |
||||
| 286 | ); |
||||
| 287 | } |
||||
| 288 | |||||
| 289 | /** |
||||
| 290 | * Returns payment method display title |
||||
| 291 | * |
||||
| 292 | * @return string |
||||
| 293 | */ |
||||
| 294 | public function getPaymentMethodTitle() |
||||
| 295 | { |
||||
| 296 | return $this->shopHelper->getConfigParam('title', $this->_quote->getPayment()->getMethod(), 'payment'); |
||||
| 297 | } |
||||
| 298 | |||||
| 299 | /** |
||||
| 300 | * Check if paypal express is used |
||||
| 301 | * |
||||
| 302 | * @return bool |
||||
| 303 | */ |
||||
| 304 | public function isPayPalExpress() |
||||
| 305 | { |
||||
| 306 | if ($this->_quote->getPayment()->getMethod() == PayoneConfig::METHOD_PAYPAL) { |
||||
| 307 | return true; |
||||
| 308 | } |
||||
| 309 | return false; |
||||
| 310 | } |
||||
| 311 | |||||
| 312 | /** |
||||
| 313 | * Generate URL to the fingerprint.js Javascript file |
||||
| 314 | * |
||||
| 315 | * @return string |
||||
| 316 | */ |
||||
| 317 | public function getFingerprintJsUrl() |
||||
| 318 | { |
||||
| 319 | $params = [ |
||||
| 320 | 'theme' => 'Magento/luma', |
||||
| 321 | 'area' => 'frontend', |
||||
| 322 | ]; |
||||
| 323 | $asset = $this->_assetRepo->createAsset('Payone_Core::js/fingerprint2.min.js', $params); |
||||
| 324 | return $asset->getUrl(); |
||||
| 325 | } |
||||
| 326 | |||||
| 327 | /** |
||||
| 328 | * Retrieve payment method and assign additional template values |
||||
| 329 | * |
||||
| 330 | * @return $this |
||||
| 331 | */ |
||||
| 332 | protected function _beforeToHtml() |
||||
| 333 | { |
||||
| 334 | $this->setShippingRateRequired(true); |
||||
| 335 | if ($this->_quote->getIsVirtual()) { |
||||
| 336 | $this->setShippingRateRequired(false); |
||||
| 337 | } else { |
||||
| 338 | // prepare shipping rates |
||||
| 339 | $this->_address = $this->_quote->getShippingAddress(); |
||||
| 340 | $this->_address->setCollectShippingRates(true); |
||||
| 341 | $groups = $this->_address->getGroupedAllShippingRates(); |
||||
| 342 | if ($groups && $this->_address) { |
||||
| 343 | $this->setShippingRateGroups($groups); |
||||
| 344 | // determine current selected code & name |
||||
| 345 | foreach ($groups as $code => $rates) { |
||||
| 346 | foreach ($rates as $rate) { |
||||
| 347 | if ($this->_address->getShippingMethod() == $rate->getCode()) { |
||||
| 348 | $this->_currentShippingRate = $rate; |
||||
| 349 | break 2; |
||||
| 350 | } |
||||
| 351 | } |
||||
| 352 | } |
||||
| 353 | } |
||||
| 354 | |||||
| 355 | // misc shipping parameters |
||||
| 356 | $this->setShippingMethodSubmitUrl( |
||||
| 357 | $this->getUrl("{$this->_controllerPath}/review", ['_secure' => true]) |
||||
| 358 | ); |
||||
| 359 | } |
||||
| 360 | |||||
| 361 | $this->setEditUrl( |
||||
| 362 | $this->getUrl("{$this->_controllerPath}/edit") |
||||
| 363 | )->setPlaceOrderUrl( |
||||
| 364 | $this->getUrl("{$this->_controllerPath}/placeOrder", ['_secure' => true]) |
||||
| 365 | ); |
||||
| 366 | |||||
| 367 | return parent::_beforeToHtml(); |
||||
| 368 | } |
||||
| 369 | } |
||||
| 370 |
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