Completed
Push — master ( e9e4a5...b10356 )
by Florian
14s
created

Payment::isMandateManagementActive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
use Magento\Framework\Phrase;
31
use Payone\Core\Model\Source\CreditcardTypes;
32
33
/**
34
 * Helper class for everything that has to do with payment
35
 */
36
class Payment extends \Payone\Core\Helper\Base
37
{
38
    /**
39
     * List of all currently available PAYONE payment types
40
     *
41
     * @var array
42
     */
43
    protected $aAvailablePayments = [
44
        PayoneConfig::METHOD_CREDITCARD,
45
        PayoneConfig::METHOD_DEBIT,
46
        PayoneConfig::METHOD_PAYPAL,
47
        PayoneConfig::METHOD_CASH_ON_DELIVERY,
48
        PayoneConfig::METHOD_ADVANCE_PAYMENT,
49
        PayoneConfig::METHOD_INVOICE,
50
        PayoneConfig::METHOD_OBT_SOFORTUEBERWEISUNG,
51
        PayoneConfig::METHOD_OBT_GIROPAY,
52
        PayoneConfig::METHOD_OBT_EPS,
53
        PayoneConfig::METHOD_OBT_POSTFINANCE_EFINANCE,
54
        PayoneConfig::METHOD_OBT_POSTFINANCE_CARD,
55
        PayoneConfig::METHOD_OBT_IDEAL,
56
        PayoneConfig::METHOD_OBT_PRZELEWY,
57
        PayoneConfig::METHOD_BARZAHLEN,
58
        PayoneConfig::METHOD_PAYDIREKT,
59
        PayoneConfig::METHOD_SAFE_INVOICE,
60
        PayoneConfig::METHOD_PAYOLUTION_INVOICE,
61
        PayoneConfig::METHOD_PAYOLUTION_DEBIT,
62
        PayoneConfig::METHOD_PAYOLUTION_INSTALLMENT,
63
        PayoneConfig::METHOD_ALIPAY
64
    ];
65
66
    /**
67
     * Mapping of payment method code to payment abbreviation
68
     *
69
     * @var array
70
     */
71
    protected $aPaymentAbbreviation = [
72
        PayoneConfig::METHOD_CREDITCARD => 'cc',
73
        PayoneConfig::METHOD_CASH_ON_DELIVERY => 'cod',
74
        PayoneConfig::METHOD_DEBIT => 'elv',
75
        PayoneConfig::METHOD_ADVANCE_PAYMENT => 'vor',
76
        PayoneConfig::METHOD_INVOICE => 'rec',
77
        PayoneConfig::METHOD_OBT_SOFORTUEBERWEISUNG => 'sb',
78
        PayoneConfig::METHOD_OBT_GIROPAY => 'sb',
79
        PayoneConfig::METHOD_OBT_EPS => 'sb',
80
        PayoneConfig::METHOD_OBT_POSTFINANCE_EFINANCE => 'sb',
81
        PayoneConfig::METHOD_OBT_POSTFINANCE_CARD => 'sb',
82
        PayoneConfig::METHOD_OBT_IDEAL => 'sb',
83
        PayoneConfig::METHOD_OBT_PRZELEWY => 'sb',
84
        PayoneConfig::METHOD_PAYPAL => 'wlt',
85
        PayoneConfig::METHOD_PAYDIREKT => 'wlt',
86
        PayoneConfig::METHOD_BILLSAFE => 'fnc',
87
        PayoneConfig::METHOD_KLARNA => 'fnc',
88
        PayoneConfig::METHOD_BARZAHLEN => 'csh',
89
        PayoneConfig::METHOD_SAFE_INVOICE => 'rec',
90
        PayoneConfig::METHOD_PAYOLUTION_INVOICE => 'fnc',
91
        PayoneConfig::METHOD_PAYOLUTION_DEBIT => 'fnc',
92
        PayoneConfig::METHOD_PAYOLUTION_INSTALLMENT => 'fnc',
93
        PayoneConfig::METHOD_ALIPAY => 'wlt',
94
    ];
95
96
    /**
97
     * Return available payment types
98
     *
99
     * @return array
100
     */
101
    public function getAvailablePaymentTypes()
102
    {
103
        return $this->aAvailablePayments;
104
    }
105
106
    /**
107
     * Get all activated creditcard types
108
     *
109
     * @return array
110
     */
111 View Code Duplication
    public function getAvailableCreditcardTypes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
112
    {
113
        $aReturn = [];
114
115
        $sCreditcardTypes = $this->getConfigParam('types', PayoneConfig::METHOD_CREDITCARD, 'payone_payment');
116
        if ($sCreditcardTypes) {
117
            $aAllTypes = CreditcardTypes::getCreditcardTypes();
118
119
            $aCreditcardTypes = explode(',', $sCreditcardTypes);
120
            foreach ($aCreditcardTypes as $sType) {
121
                $aReturn[] = [
122
                    'id' => $sType,
123
                    'title' => $aAllTypes[$sType],
124
                ];
125
            }
126
        }
127
        return $aReturn;
128
    }
129
130
    /**
131
     * Return if cvc has to be checked
132
     *
133
     * @return bool
134
     */
135
    public function isCheckCvcActive()
136
    {
137
        return (bool)$this->getConfigParam('check_cvc', PayoneConfig::METHOD_CREDITCARD, 'payone_payment');
138
    }
139
140
    /**
141
     * Return if mandate management is activated
142
     *
143
     * @return bool
144
     */
145
    public function isMandateManagementActive()
146
    {
147
        return (bool)$this->getConfigParam('sepa_mandate_enabled', PayoneConfig::METHOD_DEBIT, 'payone_payment');
148
    }
149
150
    /**
151
     * Return if mandate download is activated
152
     *
153
     * @return bool
154
     */
155
    public function isMandateManagementDownloadActive()
156
    {
157
        return (bool)$this->getConfigParam('sepa_mandate_download_enabled', PayoneConfig::METHOD_DEBIT, 'payone_payment');
158
    }
159
160
    /**
161
     * Get status mapping configuration for given payment type
162
     *
163
     * @param  string $sPaymentCode
164
     * @return array
165
     */
166
    public function getStatusMappingByCode($sPaymentCode)
167
    {
168
        $sStatusMapping = $this->getConfigParam($sPaymentCode, 'statusmapping');
169
        $aStatusMapping = $this->unserialize($sStatusMapping);
170
        $aCleanMapping = [];
171
        if ($aStatusMapping) {
172
            foreach ($aStatusMapping as $aMap) {
173
                if (isset($aMap['txaction']) && isset($aMap['state_status'])) {
174
                    $aCleanMapping[$aMap['txaction']] = $aMap['state_status'];
175
                }
176
            }
177
        }
178
        return $aCleanMapping;
179
    }
180
181
    /**
182
     * Return display-message for the case that the bankaccount check
183
     * returned, that the given bankaccount was blocked
184
     *
185
     * @return Phrase
186
     */
187
    public function getBankaccountCheckBlockedMessage()
188
    {
189
        $sMessage = $this->getConfigParam('message_response_blocked', PayoneConfig::METHOD_DEBIT, 'payone_payment');
190
        if (empty($sMessage)) {
191
            $sMessage = 'Bankdata invalid.';
192
        }
193
        return __($sMessage);
194
    }
195
196
    /**
197
     * Return is PayPal Express is activated in the configuration
198
     *
199
     * @return bool
200
     */
201
    public function isPayPalExpressActive()
202
    {
203
        return (bool)$this->getConfigParam('express_active', PayoneConfig::METHOD_PAYPAL, 'payone_payment');
204
    }
205
206
    /**
207
     * Get abbreviation for the given payment type
208
     *
209
     * @param  string $sPaymentCode
210
     * @return string
211
     */
212
    public function getPaymentAbbreviation($sPaymentCode)
213
    {
214
        if (isset($this->aPaymentAbbreviation[$sPaymentCode])) {
215
            return $this->aPaymentAbbreviation[$sPaymentCode];
216
        }
217
        return 'unknown';
218
    }
219
220
    /**
221
     * Collect the Klarna store ids from the config and format it for frontend-use
222
     *
223
     * @return array
224
     */
225
    public function getKlarnaStoreIds()
226
    {
227
        $aStoreIds = [];
228
        $aKlarnaConfig = $this->unserialize($this->getConfigParam('klarna_config', PayoneConfig::METHOD_KLARNA, 'payone_payment'));
229
        foreach ($aKlarnaConfig as $aItem) {
230
            if (!empty($aItem['store_id']) && isset($aItem['countries'])) {
231
                foreach ($aItem['countries'] as $sCountry) {
232
                    $aStoreIds[$sCountry] = $aItem['store_id'];
233
                }
234
            }
235
        }
236
        return $aStoreIds;
237
    }
238
}
239