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\Model\Api\Request; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Class for the PAYONE Server API request "addresscheck" |
||
| 31 | */ |
||
| 32 | class Addresscheck extends AddressRequest |
||
| 33 | { |
||
| 34 | /* |
||
| 35 | * Array of valid countries for addresscheck basic |
||
| 36 | * |
||
| 37 | * @var array |
||
| 38 | */ |
||
| 39 | protected $aValidCountrys = [ |
||
| 40 | 'BE', |
||
| 41 | 'DK', |
||
| 42 | 'DE', |
||
| 43 | 'FI', |
||
| 44 | 'FR', |
||
| 45 | 'IT', |
||
| 46 | 'CA', |
||
| 47 | 'LU', |
||
| 48 | 'NL', |
||
| 49 | 'NO', |
||
| 50 | 'AT', |
||
| 51 | 'PL', |
||
| 52 | 'PT', |
||
| 53 | 'SE', |
||
| 54 | 'CH', |
||
| 55 | 'SK', |
||
| 56 | 'ES', |
||
| 57 | 'CZ', |
||
| 58 | 'HU', |
||
| 59 | 'US', |
||
| 60 | ]; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Checked addresses resource model |
||
| 64 | * |
||
| 65 | * @var \Payone\Core\Model\ResourceModel\CheckedAddresses |
||
| 66 | */ |
||
| 67 | protected $addressesChecked; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * PAYONE Addresscheck helper |
||
| 71 | * |
||
| 72 | * @var \Payone\Core\Helper\Addresscheck |
||
| 73 | */ |
||
| 74 | protected $addresscheckHelper; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Constructor |
||
| 78 | * |
||
| 79 | * @param \Payone\Core\Helper\Shop $shopHelper |
||
| 80 | * @param \Payone\Core\Helper\Environment $environmentHelper |
||
| 81 | * @param \Payone\Core\Helper\Api $apiHelper |
||
| 82 | * @param \Payone\Core\Helper\Toolkit $toolkitHelper |
||
| 83 | * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog |
||
| 84 | * @param \Payone\Core\Helper\Customer $customerHelper |
||
| 85 | * @param \Payone\Core\Model\ResourceModel\CheckedAddresses $addressesChecked |
||
| 86 | * @param \Payone\Core\Helper\Addresscheck $addresscheckHelper |
||
| 87 | */ |
||
| 88 | public function __construct( |
||
| 89 | \Payone\Core\Helper\Shop $shopHelper, |
||
| 90 | \Payone\Core\Helper\Environment $environmentHelper, |
||
| 91 | \Payone\Core\Helper\Api $apiHelper, |
||
| 92 | \Payone\Core\Helper\Toolkit $toolkitHelper, |
||
| 93 | \Payone\Core\Model\ResourceModel\ApiLog $apiLog, |
||
| 94 | \Payone\Core\Helper\Customer $customerHelper, |
||
| 95 | \Payone\Core\Model\ResourceModel\CheckedAddresses $addressesChecked, |
||
| 96 | \Payone\Core\Helper\Addresscheck $addresscheckHelper |
||
| 97 | ) { |
||
| 98 | parent::__construct($shopHelper, $environmentHelper, $apiHelper, $toolkitHelper, $apiLog, $customerHelper); |
||
| 99 | $this->addressesChecked = $addressesChecked; |
||
| 100 | $this->addresscheckHelper = $addresscheckHelper; |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Get addresscheck type |
||
| 105 | * |
||
| 106 | * @param bool $blIsBillingAddress |
||
| 107 | * @return string |
||
| 108 | */ |
||
| 109 | protected function getAddresscheckType($blIsBillingAddress) |
||
| 110 | { |
||
| 111 | $sConfigField = 'check_billing'; |
||
| 112 | if ($blIsBillingAddress === false) { |
||
| 113 | $sConfigField = 'check_shipping'; |
||
| 114 | } |
||
| 115 | return $this->shopHelper->getConfigParam($sConfigField, 'address_check', 'payone_protect'); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Check if the addresscheck is available for the given check-type and address-country |
||
| 120 | * |
||
| 121 | * @param string $sAddresscheckType |
||
| 122 | * @param \Magento\Quote\Api\Data\AddressInterface $oAddress |
||
| 123 | * @return bool |
||
| 124 | */ |
||
| 125 | protected function validateTypeToCountry($sAddresscheckType, \Magento\Quote\Api\Data\AddressInterface $oAddress) |
||
|
0 ignored issues
–
show
|
|||
| 126 | { |
||
| 127 | if (in_array($sAddresscheckType, ['PE', 'BB', 'PB']) && $oAddress->getCountryId() != 'DE') { |
||
| 128 | //AddressCheck Person only available for germany |
||
| 129 | return false; |
||
| 130 | } |
||
| 131 | if ($sAddresscheckType == 'BA' && array_search($oAddress->getCountryId(), $this->aValidCountrys) === false) { |
||
| 132 | //AddressCheck Basic only available for certain countries |
||
| 133 | return false; |
||
| 134 | } |
||
| 135 | return true; |
||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Send request "addresscheck" to PAYONE server API |
||
| 140 | * |
||
| 141 | * @param \Magento\Quote\Api\Data\AddressInterface $oAddress |
||
| 142 | * @param bool $blIsBillingAddress |
||
| 143 | * @return array|bool |
||
| 144 | */ |
||
| 145 | public function sendRequest(\Magento\Quote\Api\Data\AddressInterface $oAddress, $blIsBillingAddress = false) |
||
| 146 | { |
||
| 147 | if (!$this->addresscheckHelper->isCheckEnabled($blIsBillingAddress)) { // check not needed because of configuration |
||
| 148 | return true; |
||
| 149 | } |
||
| 150 | |||
| 151 | $sType = $this->getAddresscheckType($blIsBillingAddress); |
||
| 152 | if (!$this->validateTypeToCountry($sType, $oAddress)) { |
||
| 153 | return ['wrongCountry' => true]; //Simulate successful check |
||
| 154 | } |
||
| 155 | |||
| 156 | $this->addParameter('request', 'addresscheck'); |
||
| 157 | $this->addParameter('mode', $this->shopHelper->getConfigParam('mode', 'address_check', 'payone_protect')); //Operationmode live or test |
||
| 158 | $this->addParameter('aid', $this->shopHelper->getConfigParam('aid')); //ID of PayOne Sub-Account |
||
| 159 | $this->addParameter('addresschecktype', $sType); |
||
| 160 | $this->addParameter('language', $this->shopHelper->getLocale()); |
||
| 161 | $this->addAddress($oAddress); |
||
| 162 | |||
| 163 | if ($this->addressesChecked->wasAddressCheckedBefore($oAddress, $sType) === false) { |
||
| 164 | $aResponse = $this->send(); |
||
| 165 | if ($aResponse['status'] == 'VALID') { |
||
| 166 | $this->addressesChecked->addCheckedAddress($oAddress, $aResponse, $sType); |
||
| 167 | } |
||
| 168 | return $aResponse; |
||
| 169 | } |
||
| 170 | return true; |
||
| 171 | } |
||
| 172 | } |
||
| 173 |
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