Issues (305)

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.

src/EcpayLogisticsApi.php (2 issues)

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
namespace PayumTW\Ecpay;
4
5
use Device;
6
use Distance;
7
use Temperature;
8
use IsCollection;
9
use LogisticsType;
10
use Specification;
11
use LogisticsSubType;
12
use ScheduledPickupTime;
13
use Http\Message\MessageFactory;
14
use Payum\Core\HttpClientInterface;
15
use PayumTW\Ecpay\Sdk\EcpayLogistics;
16
17
class EcpayLogisticsApi extends Api
18
{
19
    /**
20
     * $client.
21
     *
22
     * @var \Payum\Core\HttpClientInterface
23
     */
24
    protected $client;
25
26
    /**
27
     * MessageFactory.
28
     *
29
     * @var MessageFactory
30
     */
31
    protected $messageFactory;
32
33
    /**
34
     * $options.
35
     *
36
     * @var array
37
     */
38
    protected $options = [];
39
40
    /**
41
     * $sdk.
42
     *
43
     * @var \PayumTW\Ecpay\Sdk\EcpayLogistics
44
     */
45
    protected $sdk;
46
47
    /**
48
     * @var array
49
     */
50
    protected $code = [];
51
52
    /**
53
     * @param array $options
54
     * @param \Payum\Core\HttpClientInterface $client
55
     * @param MessageFactory $messageFactory
56
     * @param \PayumTW\Ecpay\Sdk\EcpayLogistics $sdk
57
     *
58
     * @throws \Payum\Core\Exception\InvalidArgumentException if an option is invalid
59
     */
60 3 View Code Duplication
    public function __construct(array $options, HttpClientInterface $client, MessageFactory $messageFactory, EcpayLogistics $sdk = null)
61
    {
62 3
        $this->options = $options;
63 3
        $this->client = $client;
64 3
        $this->messageFactory = $messageFactory;
65 3
        $this->sdk = $sdk ?: new EcpayLogistics();
66 3
        $this->sdk->HashKey = $this->options['HashKey'];
67 3
        $this->sdk->HashIV = $this->options['HashIV'];
68 3
        $this->sdk->Send['MerchantID'] = $this->options['MerchantID'];
69 3
    }
70
71
    /**
72
     * getApiEndpoint.
73
     *
74
     * @return string
75
     */
76
    public function getApiEndpoint()
77
    {
78
        return $this->sdk->ServiceURL;
79
    }
80
81
    /**
82
     * createTransaction.
83
     *
84
     * @param array $params
85
     * @return array
86
     */
87 1
    public function createCvsMapTransaction(array $params)
88
    {
89 1
        $this->sdk->Send = array_merge($this->sdk->Send, [
90 1
            'MerchantTradeNo' => '',
91 1
            'LogisticsSubType' => LogisticsSubType::UNIMART,
92 1
            'IsCollection' => IsCollection::NO,
93 1
            'ServerReplyURL' => '',
94 1
            'ExtraData' => '',
95 1
            'Device' => $this->isMobile() ? Device::MOBILE : Device::PC,
96 1
        ]);
97
98 1
        $this->sdk->Send = array_replace(
99 1
            $this->sdk->Send,
100 1
            array_intersect_key($params, $this->sdk->Send)
101 1
        );
102
103 1
        return $this->sdk->formToArray(
104 1
            $this->sdk->CvsMap()
105 1
        );
106
    }
107
108
    /**
109
     * 產生托運單(宅配)/一段標(超商取貨).
110
     *
111
     * @param array $params
112
     * @return array
113
     */
114
    public function createPrintTradeTransaction(array $params)
115
    {
116
        // 參數初始化
117
        $this->sdk->Send = array_merge($this->sdk->Send, [
118
            'AllPayLogisticsID' => '',
119
            'PlatformID' => '',
120
        ]);
121
122
        $this->sdk->Send = array_replace(
123
            $this->sdk->Send,
124
            array_intersect_key($params, $this->sdk->Send)
125
        );
126
127
        return $this->sdk->formToArray(
128
            $this->sdk->PrintTradeDoc()
129
        );
130
    }
131
132
    /**
133
     * 列印繳款單(統一超商C2C).
134
     *
135
     * @param array $params
136
     * @return array
137
     */
138 View Code Duplication
    public function createPrintUnimartC2CBillTransaction(array $params)
0 ignored issues
show
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...
139
    {
140
        // 參數初始化
141
        $this->sdk->Send = array_merge($this->sdk->Send, [
142
            'AllPayLogisticsID' => '',
143
            'CVSPaymentNo' => '',
144
            'CVSValidationNo' => '',
145
            'PlatformID' => '',
146
        ]);
147
148
        $this->sdk->Send = array_replace(
149
            $this->sdk->Send,
150
            array_intersect_key($params, $this->sdk->Send)
151
        );
152
153
        return $this->sdk->formToArray(
154
            $this->sdk->PrintUnimartC2CBill()
155
        );
156
    }
157
158
    /**
159
     * 全家列印小白單(全家超商C2C).
160
     *
161
     * @param array $params
162
     * @return array
163
     */
164 View Code Duplication
    public function createPrintFamilyC2CBillTransaction(array $params)
0 ignored issues
show
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...
165
    {
166
        // 參數初始化
167
        $this->sdk->Send = array_merge($this->sdk->Send, [
168
            'AllPayLogisticsID' => '',
169
            'CVSPaymentNo' => '',
170
            'PlatformID' => '',
171
        ]);
172
173
        $this->sdk->Send = array_replace(
174
            $this->sdk->Send,
175
            array_intersect_key($params, $this->sdk->Send)
176
        );
177
178
        return $this->sdk->formToArray(
179
            $this->sdk->PrintUnimartC2CBill()
180
        );
181
    }
182
183
    /**
184
     * createTransaction.
185
     *
186
     * @param array $params
187
     * @return array
188
     */
189 1
    public function createTransaction(array $params)
190
    {
191 1
        $this->sdk->Send = array_merge($this->sdk->Send, [
192 1
            'MerchantTradeNo' => '',
193 1
            'MerchantTradeDate' => date('Y/m/d H:i:s'),
194 1
            'LogisticsType' => '',
195 1
            'LogisticsSubType' => LogisticsSubType::UNIMART,
196 1
            'GoodsAmount' => 0,
197 1
            'CollectionAmount' => 0,
198 1
            'IsCollection' => IsCollection::NO,
199 1
            'GoodsName' => '',
200 1
            'SenderName' => '',
201 1
            'SenderPhone' => '',
202 1
            'SenderCellPhone' => '',
203 1
            'ReceiverName' => '',
204 1
            'ReceiverPhone' => '',
205 1
            'ReceiverCellPhone' => '',
206 1
            'ReceiverEmail' => '',
207 1
            'TradeDesc' => '',
208 1
            'ServerReplyURL' => '',
209 1
            'LogisticsC2CReplyURL' => '',
210 1
            'Remark' => '',
211 1
            'PlatformID' => '',
212 1
        ]);
213
214 1
        $this->sdk->SendExtend = [];
215
216 1
        $this->sdk->Send = array_replace(
217 1
            $this->sdk->Send,
218 1
            array_intersect_key($params, $this->sdk->Send)
219 1
        );
220
221 1
        $this->sdk->Send['GoodsAmount'] = (int) $this->sdk->Send['GoodsAmount'];
222 1
        $this->sdk->Send['CollectionAmount'] = (int) $this->sdk->Send['CollectionAmount'];
223
224 1
        if (empty($this->sdk->Send['LogisticsType']) === true) {
225
            $this->sdk->Send['LogisticsType'] = LogisticsType::CVS;
226
            switch ($this->sdk->Send['LogisticsSubType']) {
227
                case LogisticsSubType::TCAT:
228
                    $this->sdk->Send['LogisticsType'] = LogisticsType::HOME;
229
                    break;
230
            }
231
        }
232
233 1
        if ($this->sdk->Send['IsCollection'] === IsCollection::NO) {
234
            $this->sdk->Send['CollectionAmount'] = 0;
235 1
        } elseif (isset($this->sdk->Send['CollectionAmount']) === false) {
236
            $this->sdk->Send['CollectionAmount'] = (int) $this->sdk->Send['GoodsAmount'];
237
        }
238
239 1
        switch ($this->sdk->Send['LogisticsType']) {
240 1
            case LogisticsType::HOME:
241
                $this->sdk->SendExtend = array_merge($this->sdk->SendExtend, [
242
                    'SenderZipCode' => '',
243
                    'SenderAddress' => '',
244
                    'ReceiverZipCode' => '',
245
                    'ReceiverAddress' => '',
246
                    'Temperature' => '',
247
                    'Distance' => '',
248
                    'Specification' => '',
249
                    'ScheduledDeliveryTime' => '',
250
                ]);
251
                break;
252 1
            case LogisticsType::CVS:
253
                $this->sdk->SendExtend = array_merge($this->sdk->SendExtend, [
254
                    'ReceiverStoreID' => '',
255
                    'ReturnStoreID' => '',
256
                ]);
257
                break;
258 1
        }
259
260 1
        $this->sdk->SendExtend = array_replace(
261 1
            $this->sdk->SendExtend,
262 1
            array_intersect_key($params, $this->sdk->SendExtend)
263 1
        );
264
265 1
        return $this->sdk->BGCreateShippingOrder();
266
    }
267
268
    /**
269
     * refundTransaction.
270
     *
271
     * @param array $params
272
     * @return array
273
     */
274
    public function refundTransaction($params)
275
    {
276
        if ($params['LogisticsSubType'] === LogisticsSubType::TCAT) {
277
            // 宅配逆物流訂單產生
278
            $method = 'CreateHomeReturnOrder';
279
            $supportedParams = [
280
                'AllPayLogisticsID' => '',
281
                'LogisticsSubType' => '',
282
                'ServerReplyURL' => '',
283
                'SenderName' => '',
284
                'SenderPhone' => '',
285
                'SenderCellPhone' => '',
286
                'SenderZipCode' => '',
287
                'SenderAddress' => '',
288
                'ReceiverName' => '',
289
                'ReceiverPhone' => '',
290
                'ReceiverCellPhone' => '',
291
                'ReceiverZipCode' => '',
292
                'ReceiverAddress' => '',
293
                'GoodsAmount' => '',
294
                'GoodsName' => '',
295
                'Temperature' => Temperature::ROOM,
296
                'Distance' => Distance::SAME,
297
                'Specification' => Specification::CM_60,
298
                'ScheduledPickupTime' => ScheduledPickupTime::UNLIMITED,
299
                'ScheduledDeliveryTime' => '',
300
                'Remark' => '',
301
                'PlatformID' => '',
302
            ];
303
        } elseif (isset($params['LogisticsSubType']) === true) {
304
            // LogisticsSubType::FAMILY = 'FAMI'; // 全家
305
            // LogisticsSubType::UNIMART = 'UNIMART'; // 統一超商
306
            // LogisticsSubType::FAMILY_C2C = 'FAMIC2C'; // 全家店到店
307
            // LogisticsSubType::UNIMART_C2C = 'UNIMARTC2C'; // 統一超商寄貨便
308
309
            // 超商取貨逆物流訂單(全家超商B2C).
310
            $method = 'CreateFamilyB2CReturnOrder';
311
            $supportedParams = [
312
                'AllPayLogisticsID' => '',
313
                'ServerReplyURL' => '',
314
                'GoodsName' => '',
315
                'GoodsAmount' => 0,
316
                'SenderName' => '',
317
                'SenderPhone' => '',
318
                'Remark' => '',
319
                'Quantity' => '',
320
                'Cost' => '',
321
                'PlatformID' => '',
322
            ];
323
        } else {
324
            // 全家逆物流核帳(全家超商B2C).
325
            $method = 'CheckFamilyB2CLogistics';
326
            $supportedParams = [
327
                'RtnMerchantTradeNo' => '',
328
                'PlatformID' => '',
329
            ];
330
        }
331
332
        $this->sdk->Send = array_merge($this->sdk->Send, $supportedParams);
333
334
        $this->sdk->Send = array_replace(
335
            $this->sdk->Send,
336
            array_intersect_key($params, $this->sdk->Send)
337
        );
338
339
        return call_user_func_array([$this->sdk, $method]);
340
    }
341
342
    /**
343
     * cancelTransaction.
344
     *
345
     * @param array $params
346
     * @return array
347
     */
348
    public function cancelTransaction($params)
349
    {
350
        $supportedParams = [];
351
        $method = '';
352
        if (isset($params['LogisticsSubType']) === true) {
353
            // LogisticsSubType::FAMILY = 'FAMI'; // 全家
354
            // LogisticsSubType::UNIMART = 'UNIMART'; // 統一超商
355
            // LogisticsSubType::FAMILY_C2C = 'FAMIC2C'; // 全家店到店
356
            // LogisticsSubType::UNIMART_C2C = 'UNIMARTC2C'; // 統一超商寄貨便
357
358
            // 取消訂單(統一超商C2C).
359
            $method = 'CancelUnimartLogisticsOrder';
360
            $supportedParams = [
361
                'AllPayLogisticsID' => '',
362
                'CVSPaymentNo' => '',
363
                'CVSValidationNo' => '',
364
                'PlatformID' => '',
365
            ];
366
        }
367
368
        $this->sdk->Send = array_merge($this->sdk->Send, $supportedParams);
369
370
        $this->sdk->Send = array_replace(
371
            $this->sdk->Send,
372
            array_intersect_key($params, $this->sdk->Send)
373
        );
374
375
        return empty($method) === true ?
376
            [] : call_user_func_array([$this->sdk, $method]);
377
    }
378
379
    /**
380
     * getTransactionData.
381
     *
382
     * @param mixed $params
383
     * @return array
384
     */
385
    public function getTransactionData($params)
386
    {
387
        $supportedParams = [
388
            'AllPayLogisticsID' => '',
389
            'PlatformID' => '',
390
        ];
391
392
        $this->sdk->Send = array_merge($this->sdk->Send, $supportedParams);
393
394
        $this->sdk->Send = array_replace(
395
            $this->sdk->Send,
396
            array_intersect_key($params, $this->sdk->Send)
397
        );
398
399
        return $this->sdk->QueryLogisticsInfo();
400
    }
401
}
402