Issues (547)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Model/Api/Request/Debit.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
use Magento\Sales\Model\Order;
30
use Payone\Core\Model\Methods\PayoneMethod;
31
use Magento\Payment\Model\InfoInterface;
32
33
/**
34
 * Class for the PAYONE Server API request "debit"
35
 */
36
class Debit extends Base
37
{
38
    /**
39
     * @var \Payone\Core\Model\Api\Invoice $invoiceGenerator
40
     */
41
    protected $invoiceGenerator;
42
43
    /**
44
     * PAYONE database helper
45
     *
46
     * @var \Payone\Core\Helper\Database
47
     */
48
    protected $databaseHelper;
49
50
    /**
51
     * PAYONE toolkit helper
52
     *
53
     * @var \Payone\Core\Helper\Toolkit
54
     */
55
    protected $toolkitHelper;
56
57
    /**
58
     * Constructor
59
     *
60
     * @param \Payone\Core\Helper\Shop                $shopHelper
61
     * @param \Payone\Core\Helper\Environment         $environmentHelper
62
     * @param \Payone\Core\Helper\Api                 $apiHelper
63
     * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
64
     * @param \Payone\Core\Model\Api\Invoice          $invoiceGenerator
65
     * @param \Payone\Core\Helper\Database            $databaseHelper
66
     * @param \Payone\Core\Helper\Toolkit             $toolkitHelper
67
     */
68
    public function __construct(
69
        \Payone\Core\Helper\Shop $shopHelper,
70
        \Payone\Core\Helper\Environment $environmentHelper,
71
        \Payone\Core\Helper\Api $apiHelper,
72
        \Payone\Core\Model\ResourceModel\ApiLog $apiLog,
73
        \Payone\Core\Model\Api\Invoice $invoiceGenerator,
74
        \Payone\Core\Helper\Database $databaseHelper,
75
        \Payone\Core\Helper\Toolkit $toolkitHelper
76
    ) {
77
        parent::__construct($shopHelper, $environmentHelper, $apiHelper, $apiLog);
78
        $this->invoiceGenerator = $invoiceGenerator;
79
        $this->databaseHelper = $databaseHelper;
80
        $this->toolkitHelper = $toolkitHelper;
81
    }
82
83
    /**
84
     * Generate position list for invoice data transmission
85
     *
86
     * @param Order $oOrder
87
     * @return array|false
88
     */
89
    protected function getInvoiceList(Order $oOrder)
90
    {
91
        $aCreditmemo = $this->shopHelper->getRequestParameter('creditmemo');
92
93
        $aPositions = [];
94
        $blFull = true;
95
        if ($aCreditmemo && array_key_exists('items', $aCreditmemo) !== false) {
96
            foreach ($oOrder->getAllItems() as $oItem) {
97
                if (isset($aCreditmemo['items'][$oItem->getItemId()]) && $aCreditmemo['items'][$oItem->getItemId()]['qty'] > 0) {
98
                    $aPositions[$oItem->getProductId()] = $aCreditmemo['items'][$oItem->getItemId()]['qty'];
99
                    if ($aCreditmemo['items'][$oItem->getItemId()]['qty'] != $oItem->getQtyOrdered()) {
100
                        $blFull = false;
101
                    }
102
                } else {
103
                    $blFull = false;
104
                }
105
            }
106
        }
107
        if (isset($aCreditmemo['shipping_amount']) && $aCreditmemo['shipping_amount'] != 0) {
108
            $aPositions['delcost'] = $aCreditmemo['shipping_amount'];
109
        }
110
        if ($blFull === true && (!isset($aCreditmemo['shipping_amount']) || $aCreditmemo['shipping_amount'] == $oOrder->getBaseShippingInclTax())) {
111
            $aPositions = false; // false = full debit
112
        }
113
        return $aPositions;
114
    }
115
116
    /**
117
     * Send request "debit" to PAYONE server API
118
     *
119
     * @param  PayoneMethod  $oPayment
120
     * @param  InfoInterface $oPaymentInfo
121
     * @param  float         $dAmount
122
     * @return array
123
     */
124
    public function sendRequest(PayoneMethod $oPayment, InfoInterface $oPaymentInfo, $dAmount)
125
    {
126
        $oOrder = $oPaymentInfo->getOrder();
127
128
        $aPositions = $this->getInvoiceList($oOrder);
129
130
        $iTxid = $oPaymentInfo->getParentTransactionId();
131
        if (strpos($iTxid, '-') !== false) {
132
            $iTxid = substr($iTxid, 0, strpos($iTxid, '-')); // clean the txid from the magento-suffixes
133
        }
134
135
        $this->setOrderId($oOrder->getRealOrderId());
136
137
        $this->addParameter('request', 'debit'); // Request method
138
        $this->addParameter('mode', $oPayment->getOperationMode()); // PayOne Portal Operation Mode (live or test)
139
        $this->addParameter('txid', $iTxid); // PayOne Transaction ID
140
        $this->addParameter('sequencenumber', $this->databaseHelper->getSequenceNumber($iTxid));
141
142
        // Total order sum in smallest currency unit
143
        $this->addParameter('amount', number_format((-1 * $dAmount), 2, '.', '') * 100);
144
        $this->addParameter('currency', $oOrder->getOrderCurrencyCode()); // Currency
145
        $this->addParameter('transactiontype', 'GT');
146
147
        $sRefundAppendix = $this->getRefundAppendix($oOrder, $oPayment);
148
        if (!empty($sRefundAppendix)) {
149
            $this->addParameter('invoiceappendix', $sRefundAppendix);
150
        }
151
152
        if ($this->apiHelper->isInvoiceDataNeeded($oPayment)) {
153
            $this->invoiceGenerator->addProductInfo($this, $oOrder, $aPositions, true); // add invoice parameters
154
        }
155
156
        // Add debit bank data given - see oxid integration
157
158
        $aResponse = $this->send($oPayment);
159
160
        return $aResponse;
161
    }
162
163
    /**
164
     * Get substituted refund appendix text
165
     *
166
     * @param  Order        $oOrder
167
     * @param  PayoneMethod $oPayment
168
     * @return string
169
     */
170
    protected function getRefundAppendix(Order $oOrder, PayoneMethod $oPayment)
171
    {
172
        $sText = $this->shopHelper->getConfigParam('invoice_appendix_refund', 'invoicing');
173
        $sCreditMemoIncrId = '';
174
        $sInvoiceIncrementId = '';
175
        $sInvoiceId = '';
176
177
        $oCreditmemo = $oPayment->getCreditmemo();
178
        if ($oCreditmemo) {
179
            $sCreditMemoIncrId = $oCreditmemo->getIncrementId();
180
            $oInvoice = $oCreditmemo->getInvoice();
181
            if ($oInvoice) {
182
                $sInvoiceIncrementId = $oInvoice->getIncrementId();
183
                $sInvoiceId = $oInvoice->getId();
184
            }
185
        }
186
187
        $aSubstitutionArray = [
188
            '{{order_increment_id}}' => $oOrder->getIncrementId(),
189
            '{{order_id}}' => $oOrder->getId(),
190
            '{{customer_id}}' => $oOrder->getCustomerId(),
191
            '{{creditmemo_increment_id}}' => $sCreditMemoIncrId,
192
            '{{invoice_increment_id}}' => $sInvoiceIncrementId,
193
            '{{invoice_id}}' => $sInvoiceId,
194
        ];
195
        $sRefundAppendix = $this->toolkitHelper->handleSubstituteReplacement($sText, $aSubstitutionArray, 255);
0 ignored issues
show
$aSubstitutionArray is of type array<string,?,{"{{order...,"{{invoice_id}}":"?"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
196
        return $sRefundAppendix;
197
    }
198
}
199