Issues (1092)

Helper/Country.php (4 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\Helper;
28
29
use Payone\Core\Model\PayoneConfig;
30
31
/**
32
 * Helper class for everything that has to do with countries
33
 */
34
class Country extends \Payone\Core\Helper\Base
35
{
36
    /**
37
     * List of all countries where the state parameter has to be submitted
38
     *
39
     * @var array
40
     */
41
    static protected $aStateNeeded = [
42
        'US',
43
        'CA',
44
        'CN',
45
        'JP',
46
        'MX',
47
        'BR',
48
        'AR',
49
        'ID',
50
        'TH',
51
        'IN',
52
    ];
53
54
    /**
55
     * Country object
56
     *
57
     * @var \Magento\Directory\Model\Country
0 ignored issues
show
The type Magento\Directory\Model\Country 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...
58
     */
59
    protected $country;
60
61
    /**
62
     * Constructor
63
     *
64
     * @param \Magento\Framework\App\Helper\Context      $context
65
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
66
     * @param \Payone\Core\Helper\Shop                   $shopHelper
67
     * @param \Magento\Framework\App\State               $state
68
     * @param \Magento\Directory\Model\Country           $country
69
     */
70
    public function __construct(
71
        \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. 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...
72
        \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. 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...
73
        \Payone\Core\Helper\Shop $shopHelper,
74
        \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. 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...
75
        \Magento\Directory\Model\Country $country
76
    ) {
77
        parent::__construct($context, $storeManager, $shopHelper, $state);
78
        $this->country = $country;
79
    }
80
81
    /**
82
     * Get country name by its ISO2 abbreviation
83
     *
84
     * @param  string $sCountryCode
85
     * @return string|bool
86
     */
87
    public function getCountryNameByIso2($sCountryCode)
88
    {
89
        $oCountry = $this->country->loadByCode($sCountryCode);
90
        if ($oCountry) {
91
            return $oCountry->getName();
92
        }
93
        return false;
94
    }
95
96
    /**
97
     * Get all activated debit SEPA countries
98
     *
99
     * @return array
100
     */
101
    public function getEnabledCountries($sPaymentMethod)
102
    {
103
        $aReturn = [];
104
105
        $sCountries = $this->getConfigParam('sepa_country', $sPaymentMethod, 'payone_payment');
106
        if ($sCountries) {
107
            $aCountries = explode(',', $sCountries);
108
            foreach ($aCountries as $sCountryCode) {
109
                $sCountryName = $this->getCountryNameByIso2($sCountryCode);
110
                if ($sCountryName) {
111
                    $aReturn[] = [
112
                        'id' => $sCountryCode,
113
                        'title' => $sCountryName,
114
                    ];
115
                }
116
            }
117
        }
118
        return $aReturn;
119
    }
120
121
    /**
122
     * Return if state parameter has to be added for the given country
123
     *
124
     * @param  string $sIsoToCountry
125
     * @return bool
126
     */
127
    public static function isStateNeeded($sIsoToCountry)
128
    {
129
        if (array_search($sIsoToCountry, self::$aStateNeeded) !== false) {
130
            return true;
131
        }
132
        return false;
133
    }
134
}
135