Issues (1092)

Model/Methods/AmazonPayV2.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 - 2024 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;
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
use Magento\Framework\DataObject;
0 ignored issues
show
The type Magento\Framework\DataObject 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...
32
33
/**
34
 * Model for Amazon Pay V2 payment method
35
 */
36
class AmazonPayV2 extends PayoneMethod
37
{
38
    const BUTTON_PUBLIC_KEY = 'AE5E5B7B2SAERURYEH6DKDAZ';
39
40
    /**
41
     * Payment method code
42
     *
43
     * @var string
44
     */
45
    protected $_code = PayoneConfig::METHOD_AMAZONPAYV2;
46
47
    /**
48
     * Clearingtype for PAYONE authorization request
49
     *
50
     * @var string
51
     */
52
    protected $sClearingtype = 'wlt';
53
54
    /**
55
     * Wallettype for PAYONE requests
56
     *
57
     * @var string|bool
58
     */
59
    protected $sWallettype = 'AMP';
60
61
    /**
62
     * Determines if the redirect-parameters have to be added
63
     * to the authorization-request
64
     *
65
     * @var bool
66
     */
67
    protected $blNeedsRedirectUrls = true;
68
69
    /**
70
     * @var bool
71
     */
72
    protected $blNeedsReturnedUrl = false;
73
74
    /**
75
     * Keys that need to be assigned to the additionalinformation fields
76
     *
77
     * @var array
78
     */
79
    protected $aAssignKeys = [
80
        'telephone',
81
    ];
82
83
    /**
84
     * @return bool
85
     */
86
    public function isAPBPayment()
87
    {
88
        if ($this->isAmazonPayExpress() === true) {
89
            return false;
90
        }
91
        return true;
92
    }
93
94
    /**
95
     * @return bool
96
     */
97
    public function isAmazonPayExpress()
98
    {
99
        if ($this->checkoutSession->getPayoneIsAmazonPayExpressPayment() === true) {
100
            return true;
101
        }
102
        return false;
103
    }
104
105
    /**
106
     * Returns if the current payment process is a express payment
107
     *
108
     * @return false
109
     */
110
    public function isExpressPayment()
111
    {
112
        return $this->isAmazonPayExpress();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->isAmazonPayExpress() returns the type boolean which is incompatible with the documented return type false.
Loading history...
113
    }
114
115
    /**
116
     * @return string
117
     */
118
    public function getMerchantId()
119
    {
120
        return $this->getCustomConfigParam('merchant_id');
121
    }
122
123
    /**
124
     * @return string
125
     */
126
    public function getButtonColor()
127
    {
128
        return $this->getCustomConfigParam('button_color') ?? 'Gold';
129
    }
130
131
    /**
132
     * @return string
133
     */
134
    public function getButtonLanguage()
135
    {
136
        return str_replace("-", "_", $this->getCustomConfigParam('button_language') ?? 'none');
137
    }
138
139
    /**
140
     * @return bool
141
     */
142
    public function useSandbox()
143
    {
144
        if ($this->getOperationMode() == 'test') {
145
            return true;
146
        }
147
        return false;
148
    }
149
150
    /**
151
     * Return success url for redirect payment types
152
     *
153
     * @param  Order $oOrder
154
     * @return string
155
     */
156
    public function getSuccessUrl(?Order $oOrder = null)
157
    {
158
        if ($this->blNeedsReturnedUrl === true) {
159
            return $this->url->getUrl('payone/amazon/returned');
160
        }
161
        return parent::getSuccessUrl($oOrder);
162
    }
163
164
    /**
165
     * @param  bool $blNeedsReturnedUrl
166
     * @return void
167
     */
168
    public function setNeedsReturnedUrl($blNeedsReturnedUrl)
169
    {
170
        $this->blNeedsReturnedUrl = $blNeedsReturnedUrl;
171
    }
172
173
    /**
174
     * Add the checkout-form-data to the checkout session
175
     *
176
     * @param  DataObject $data
177
     * @return $this
178
     */
179
    public function assignData(DataObject $data)
180
    {
181
        parent::assignData($data);
182
183
        $oInfoInstance = $this->getInfoInstance();
184
        foreach ($this->aAssignKeys as $sKey) {
185
            $sData = $this->toolkitHelper->getAdditionalDataEntry($data, $sKey);
186
            if ($sData) {
187
                $oInfoInstance->setAdditionalInformation($sKey, $sData);
188
            }
189
        }
190
191
        return $this;
192
    }
193
194
    /**
195
     * Return parameters specific to this payment type
196
     *
197
     * @param  Order $oOrder
198
     * @return array
199
     */
200
    public function getPaymentSpecificParameters(Order $oOrder)
201
    {
202
        $aParams = ['wallettype' => $this->getWallettype()];
203
204
        $sWorkorderId = $this->checkoutSession->getPayoneWorkorderId();
205
        if ($sWorkorderId) {
206
            $aParams['workorderid'] = $sWorkorderId;
207
        }
208
209
        if ($this->isAPBPayment() === true) {
210
            $aParams['add_paydata[checkoutMode]'] = 'ProcessOrder';
211
            $aParams['add_paydata[productType]'] = $oOrder->getIsVirtual() ? 'PayOnly' : 'PayAndShip';
212
213
            $sTelephone = $this->getInfoInstance()->getAdditionalInformation('telephone');
214
            if (!empty($sTelephone)) {
215
                $aParams['telephonenumber'] = $sTelephone;
216
            }
217
        }
218
        return $aParams;
219
    }
220
221
    /**
222
     * Perform certain actions with the response
223
     * Extension hook for certain payment methods
224
     *
225
     * @param  array $aResponse
226
     * @param  Order $oOrder
227
     * @param  float $amount
228
     * @return array
229
     */
230
    protected function handleResponse($aResponse, Order $oOrder, $amount)
231
    {
232
        $aResponse = parent::handleResponse($aResponse, $oOrder, $amount);
233
        if ($this->isAPBPayment() === true && isset($aResponse['status'], $aResponse['add_paydata[signature]'], $aResponse['add_paydata[payload]']) && in_array($aResponse['status'], ['OK', 'REDIRECT'])) {
234
            $this->checkoutSession->setPayoneAmazonPaySignature($aResponse['add_paydata[signature]']);
235
            $this->checkoutSession->setPayoneAmazonPayPayload($aResponse['add_paydata[payload]']);
236
        }
237
        return $aResponse;
238
    }
239
240
241
    /**
242
     * @return array
243
     */
244
    public function getFrontendConfig()
245
    {
246
        return [
247
            'buttonPublicKey' => self::BUTTON_PUBLIC_KEY,
248
            'merchantId' => $this->getMerchantId(),
249
            'buttonColor' => $this->getButtonColor(),
250
            'buttonLanguage' => $this->getButtonLanguage(),
251
            'useSandbox' => $this->useSandbox(),
252
        ];
253
    }
254
}
255