Issues (1092)

Model/Methods/Ratepay/Installment.php (3 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 - 2022 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\Methods\Ratepay;
28
29
use Payone\Core\Model\PayoneConfig;
30
use Magento\Sales\Model\Order;
0 ignored issues
show
The type Magento\Sales\Model\Order 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...
31
32
/**
33
 * Model for Ratepay installment payment method
34
 */
35
class Installment extends RatepayBase
36
{
37
    /**
38
     * Payment method code
39
     *
40
     * @var string
41
     */
42
    protected $_code = PayoneConfig::METHOD_RATEPAY_INSTALLMENT;
43
44
    /**
45
     * Payment method sub type
46
     *
47
     * @var string
48
     */
49
    protected $sSubType = self::METHOD_RATEPAY_SUBTYPE_INSTALLMENT;
50
51
    /**
52
     * Keys that need to be assigned to the additionalinformation fields
53
     *
54
     * @var array
55
     */
56
    protected $aAssignKeys = [
57
        'telephone',
58
        'dateofbirth',
59
        'iban',
60
        'bic',
61
        'installment_amount',
62
        'installment_number',
63
        'last_installment_amount',
64
        'interest_rate',
65
        'amount',
66
    ];
67
68
    /**
69
     * Return parameters specific to this payment sub type
70
     *
71
     * @param  Order $oOrder
72
     * @return array
73
     */
74
    public function getSubTypeSpecificParameters(Order $oOrder)
75
    {
76
        $oInfoInstance = $this->getInfoInstance();
77
78
        $sIban = $oInfoInstance->getAdditionalInformation('iban');
79
        $sBic = $oInfoInstance->getAdditionalInformation('bic');
80
81
        $sDebitPayType = "BANK-TRANSFER";
82
        if (!empty($sIban)) {
83
            $sDebitPayType = "DIRECT-DEBIT";
84
        }
85
86
        $aParams = [
87
            'add_paydata[debit_paytype]' => $sDebitPayType,
88
            'add_paydata[installment_number]' => $oInfoInstance->getAdditionalInformation('installment_number'),
89
            'add_paydata[installment_amount]' => $oInfoInstance->getAdditionalInformation('installment_amount') * 100,
90
            'add_paydata[last_installment_amount]' => $oInfoInstance->getAdditionalInformation('last_installment_amount') * 100,
91
            'add_paydata[interest_rate]' => $oInfoInstance->getAdditionalInformation('interest_rate') * 100,
92
            'add_paydata[amount]' => $oInfoInstance->getAdditionalInformation('amount') * 100,
93
            'iban' => $sIban,
94
        ];
95
96
        if (!empty($sBic)) {
97
            $aParams['bic'] = $sBic;
98
        }
99
        return $aParams;
100
    }
101
102
    /**
103
     * Generates allowed installment runtimes array
104
     *
105
     * @param  array  $aProfileConfig
106
     * @param  double $dQuoteTotal
107
     * @return array
108
     */
109
    protected function generateAllowedMonths($aProfileConfig, $dQuoteTotal)
110
    {
111
        $dRateMinNormal = $aProfileConfig['rate_min_normal'];
112
        $aRuntimes = explode(",", $aProfileConfig['month_allowed']);
113
        $dInterestrateMonth = ((float)$aProfileConfig['interestrate_default'] / 12) / 100;
114
115
        $aAllowedRuntimes = [];
116
        if (!empty($aRuntimes)) {
117
            foreach ($aRuntimes as $iRuntime) {
118
                if (!is_numeric($iRuntime)) {
119
                    continue;
120
                }
121
                if ($dInterestrateMonth > 0) { // otherwise division by zero error will happen
122
                    $dRateAmount = $dQuoteTotal * (($dInterestrateMonth * pow((1 + $dInterestrateMonth), $iRuntime)) / (pow((1 + $dInterestrateMonth), $iRuntime) - 1));
0 ignored issues
show
$iRuntime of type string is incompatible with the type double|integer expected by parameter $exp of pow(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

122
                    $dRateAmount = $dQuoteTotal * (($dInterestrateMonth * pow((1 + $dInterestrateMonth), /** @scrutinizer ignore-type */ $iRuntime)) / (pow((1 + $dInterestrateMonth), $iRuntime) - 1));
Loading history...
123
                } else {
124
                    $dRateAmount = $dQuoteTotal / $iRuntime;
125
                }
126
127
                if ($dRateAmount >= $dRateMinNormal) {
128
                    $aAllowedRuntimes[] = $iRuntime;
129
                }
130
            }
131
        }
132
        return $aAllowedRuntimes;
133
    }
134
135
    /**
136
     * Returns allowed installment runtimes in months
137
     *
138
     * @param \Magento\Quote\Api\Data\CartInterface|null $quote
139
     * @return array
140
     */
141
    public function getAllowedMonths(?\Magento\Quote\Api\Data\CartInterface $quote = null)
0 ignored issues
show
The type Magento\Quote\Api\Data\CartInterface 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...
142
    {
143
        if ($quote === null) {
144
            $quote = $this->checkoutSession->getQuote();
145
        }
146
147
        $aConfig = $this->ratepayHelper->getShopConfigByQuote($this->getCode(), $quote);
148
        if (!$aConfig) {
149
            return [];
150
        }
151
        return $this->generateAllowedMonths($aConfig, $quote->getGrandTotal());
152
    }
153
}
154