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 - 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\Helper; |
||||
| 28 | |||||
| 29 | use Magento\Quote\Model\Quote\Address as QuoteAddress; |
||||
|
0 ignored issues
–
show
|
|||||
| 30 | use Magento\Sales\Model\Order\Address as OrderAddress; |
||||
|
0 ignored issues
–
show
The type
Magento\Sales\Model\Order\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...
|
|||||
| 31 | use Magento\Directory\Model\Region; |
||||
|
0 ignored issues
–
show
The type
Magento\Directory\Model\Region 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 | |||||
| 33 | /** |
||||
| 34 | * Helper class for everything that has to do with customers |
||||
| 35 | */ |
||||
| 36 | class Customer extends \Payone\Core\Helper\Base |
||||
| 37 | { |
||||
| 38 | /** |
||||
| 39 | * Checkout session |
||||
| 40 | * |
||||
| 41 | * @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 Loading history...
|
|||||
| 42 | */ |
||||
| 43 | protected $checkoutSession; |
||||
| 44 | |||||
| 45 | /** |
||||
| 46 | * Region factory |
||||
| 47 | * |
||||
| 48 | * @var \Magento\Directory\Model\RegionFactory |
||||
|
0 ignored issues
–
show
The type
Magento\Directory\Model\RegionFactory 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...
|
|||||
| 49 | */ |
||||
| 50 | protected $regionFactory; |
||||
| 51 | |||||
| 52 | /** |
||||
| 53 | * Constructor |
||||
| 54 | * |
||||
| 55 | * @param \Magento\Framework\App\Helper\Context $context |
||||
| 56 | * @param \Magento\Store\Model\StoreManagerInterface $storeManager |
||||
| 57 | * @param \Payone\Core\Helper\Shop $shopHelper |
||||
| 58 | * @param \Magento\Framework\App\State $state |
||||
| 59 | * @param \Magento\Checkout\Model\Session $checkoutSession |
||||
| 60 | * @param \Magento\Directory\Model\RegionFactory $regionFactory |
||||
| 61 | */ |
||||
| 62 | public function __construct( |
||||
| 63 | \Magento\Framework\App\Helper\Context $context, |
||||
|
0 ignored issues
–
show
The type
Magento\Framework\App\Helper\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...
|
|||||
| 64 | \Magento\Store\Model\StoreManagerInterface $storeManager, |
||||
|
0 ignored issues
–
show
The type
Magento\Store\Model\StoreManagerInterface 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...
|
|||||
| 65 | \Payone\Core\Helper\Shop $shopHelper, |
||||
| 66 | \Magento\Framework\App\State $state, |
||||
|
0 ignored issues
–
show
The type
Magento\Framework\App\State 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...
|
|||||
| 67 | \Magento\Checkout\Model\Session $checkoutSession, |
||||
| 68 | \Magento\Directory\Model\RegionFactory $regionFactory |
||||
| 69 | ) { |
||||
| 70 | parent::__construct($context, $storeManager, $shopHelper, $state); |
||||
| 71 | $this->checkoutSession = $checkoutSession; |
||||
| 72 | $this->regionFactory = $regionFactory; |
||||
| 73 | } |
||||
| 74 | |||||
| 75 | /** |
||||
| 76 | * Get customer gender |
||||
| 77 | * |
||||
| 78 | * @return string|null |
||||
| 79 | */ |
||||
| 80 | public function getCustomerGender() |
||||
| 81 | { |
||||
| 82 | $sGender = null; |
||||
| 83 | if (!empty($this->checkoutSession->getPayoneGuestGender())) { |
||||
| 84 | $sGender = $this->checkoutSession->getPayoneGuestGender(); |
||||
| 85 | } else { |
||||
| 86 | $oCustomer = $this->checkoutSession->getQuote()->getCustomer(); |
||||
| 87 | if ($oCustomer && $oCustomer->getGender()) { |
||||
| 88 | $sGender = $oCustomer->getGender(); |
||||
| 89 | } |
||||
| 90 | } |
||||
| 91 | |||||
| 92 | if (!empty($sGender)) { |
||||
| 93 | switch ($sGender) { |
||||
| 94 | case 1: |
||||
| 95 | $sGender = "m"; |
||||
| 96 | break; |
||||
| 97 | case 2: |
||||
| 98 | $sGender = "f"; |
||||
| 99 | break; |
||||
| 100 | case 3: |
||||
| 101 | $sGender = "d"; |
||||
| 102 | break; |
||||
| 103 | } |
||||
| 104 | } |
||||
| 105 | return $sGender; |
||||
| 106 | } |
||||
| 107 | |||||
| 108 | /** |
||||
| 109 | * Get customer birthday |
||||
| 110 | * |
||||
| 111 | * @return string|null |
||||
| 112 | */ |
||||
| 113 | public function getCustomerBirthday() |
||||
| 114 | { |
||||
| 115 | $sBirthday = null; |
||||
| 116 | if (!empty($this->checkoutSession->getPayoneGuestDateofbirth())) { |
||||
| 117 | $sBirthday = $this->checkoutSession->getPayoneGuestDateofbirth(); |
||||
| 118 | } else { |
||||
| 119 | $oCustomer = $this->checkoutSession->getQuote()->getCustomer(); |
||||
| 120 | if ($oCustomer && $oCustomer->getDob()) { |
||||
| 121 | $sBirthday = $oCustomer->getDob(); |
||||
| 122 | } |
||||
| 123 | } |
||||
| 124 | |||||
| 125 | if (!empty($sBirthday)) { |
||||
| 126 | $sBirthday = date('Ymd', strtotime($sBirthday)); |
||||
| 127 | } |
||||
| 128 | return $sBirthday; |
||||
| 129 | } |
||||
| 130 | |||||
| 131 | /** |
||||
| 132 | * Get the region object for the state and country given by PayPal |
||||
| 133 | * |
||||
| 134 | * @param string $sCountry |
||||
| 135 | * @param string $sState |
||||
| 136 | * @return Region|bool |
||||
| 137 | */ |
||||
| 138 | public function getRegion($sCountry, $sState) |
||||
| 139 | { |
||||
| 140 | $oRegion = false; |
||||
| 141 | if (!empty($sState) && $sState != 'Empty') { |
||||
| 142 | $oRegion = $this->regionFactory->create(); |
||||
| 143 | $oRegion->loadByCode( |
||||
| 144 | $sState, |
||||
| 145 | $sCountry |
||||
| 146 | ); |
||||
| 147 | if (!$oRegion->getId()) {// Region not found |
||||
| 148 | $oRegion = false; |
||||
| 149 | } |
||||
| 150 | } |
||||
| 151 | return $oRegion; |
||||
| 152 | } |
||||
| 153 | |||||
| 154 | /** |
||||
| 155 | * Get region code by address |
||||
| 156 | * |
||||
| 157 | * @param QuoteAddress|OrderAddress $oAddress |
||||
| 158 | * @return string |
||||
| 159 | */ |
||||
| 160 | public function getRegionCode($oAddress) |
||||
| 161 | { |
||||
| 162 | $sRegionCode = $oAddress->getRegionCode(); |
||||
| 163 | if (strlen($sRegionCode) != 2) { |
||||
| 164 | $sRegionCode = str_ireplace($oAddress->getCountryId().'-', '', $sRegionCode); // MAG2-266 |
||||
| 165 | } |
||||
| 166 | if (strlen($sRegionCode) != 2) { |
||||
| 167 | $oRegion = $this->regionFactory->create(); |
||||
| 168 | $oRegion->loadByName($sRegionCode, $oAddress->getCountryId()); |
||||
| 169 | if ($oRegion->getId()) { |
||||
| 170 | $sRegionCode = $oRegion->getCode(); |
||||
| 171 | } |
||||
| 172 | } |
||||
| 173 | return $sRegionCode; |
||||
| 174 | } |
||||
| 175 | |||||
| 176 | /** |
||||
| 177 | * Map magento gender to PAYONE gender parameter |
||||
| 178 | * |
||||
| 179 | * @param int $iGender |
||||
| 180 | * @return string |
||||
| 181 | */ |
||||
| 182 | public function getGenderParameter($iGender) |
||||
| 183 | { |
||||
| 184 | $sGender = ''; |
||||
| 185 | if ($iGender == '1') { |
||||
| 186 | $sGender = 'm'; |
||||
| 187 | } elseif ($iGender == '2') { |
||||
| 188 | $sGender = 'f'; |
||||
| 189 | } |
||||
| 190 | return $sGender; |
||||
| 191 | } |
||||
| 192 | |||||
| 193 | /** |
||||
| 194 | * Map magento gender to PAYONE salutation parameter |
||||
| 195 | * |
||||
| 196 | * @param int $iGender |
||||
| 197 | * @return string |
||||
| 198 | */ |
||||
| 199 | public function getSalutationParameter($iGender) |
||||
| 200 | { |
||||
| 201 | $sSalutation = ''; |
||||
| 202 | if ($iGender == '1') { |
||||
| 203 | $sSalutation = (string)__('Mr'); |
||||
|
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...
|
|||||
| 204 | } elseif ($iGender == '2') { |
||||
| 205 | $sSalutation = (string)__('Mrs'); |
||||
| 206 | } |
||||
| 207 | return $sSalutation; |
||||
| 208 | } |
||||
| 209 | } |
||||
| 210 |
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