Completed
Push — master ( 10b564...94d3ee )
by recca
03:03
created

QueryTrade   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 32
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B CheckOut() 0 29 4
1
<?php
2
3
/**
4
 * 付款方式。
5
 */
6
abstract class PaymentMethod {
7
8
    /**
9
     * 不指定付款方式。
10
     */
11
    const ALL = 'ALL';
12
13
    /**
14
     * 信用卡付費。
15
     */
16
    const Credit = 'Credit';
17
18
    /**
19
     * 網路 ATM。
20
     */
21
    const WebATM = 'WebATM';
22
23
    /**
24
     * 自動櫃員機。
25
     */
26
    const ATM = 'ATM';
27
28
    /**
29
     * 超商代碼。
30
     */
31
    const CVS = 'CVS';
32
33
    /**
34
     * 財付通。
35
     */
36
    const Tenpay = 'Tenpay';
37
38
    /**
39
     * 儲值消費。
40
     */
41
    const TopUpUsed = 'TopUpUsed';
42
43
}
44
45
/**
46
 * 付款方式子項目。
47
 */
48
abstract class PaymentMethodItem {
49
50
    /**
51
     * 不指定。
52
     */
53
    const None = '';
54
    // WebATM 類(001~100)
55
    /**
56
     * 台新銀行。
57
     */
58
    const WebATM_TAISHIN = 'TAISHIN';
59
60
    /**
61
     * 玉山銀行。
62
     */
63
    const WebATM_ESUN = 'ESUN';
64
65
    /**
66
     * 華南銀行。
67
     */
68
    const WebATM_HUANAN = 'HUANAN';
69
70
    /**
71
     * 台灣銀行。
72
     */
73
    const WebATM_BOT = 'BOT';
74
75
    /**
76
     * 台北富邦。
77
     */
78
    const WebATM_FUBON = 'FUBON';
79
80
    /**
81
     * 中國信託。
82
     */
83
    const WebATM_CHINATRUST = 'CHINATRUST';
84
85
    /**
86
     * 第一銀行。
87
     */
88
    const WebATM_FIRST = 'FIRST';
89
90
    /**
91
     * 國泰世華。
92
     */
93
    const WebATM_CATHAY = 'CATHAY';
94
95
    /**
96
     * 兆豐銀行。
97
     */
98
    const WebATM_MEGA = 'MEGA';
99
100
    /**
101
     * 元大銀行。
102
     */
103
    const WebATM_YUANTA = 'YUANTA';
104
105
    /**
106
     * 土地銀行。
107
     */
108
    const WebATM_LAND = 'LAND';
109
    // ATM 類(101~200)
110
    /**
111
     * 台新銀行。
112
     */
113
    const ATM_TAISHIN = 'TAISHIN';
114
115
    /**
116
     * 玉山銀行。
117
     */
118
    const ATM_ESUN = 'ESUN';
119
120
    /**
121
     * 華南銀行。
122
     */
123
    const ATM_HUANAN = 'HUANAN';
124
125
    /**
126
     * 台灣銀行。
127
     */
128
    const ATM_BOT = 'BOT';
129
130
    /**
131
     * 台北富邦。
132
     */
133
    const ATM_FUBON = 'FUBON';
134
135
    /**
136
     * 中國信託。
137
     */
138
    const ATM_CHINATRUST = 'CHINATRUST';
139
140
    /**
141
     * 土地銀行。
142
     */
143
    const ATM_LAND = 'LAND';
144
145
    /**
146
     * 國泰世華銀行。
147
     */
148
    const ATM_CATHAY = 'CATHAY';
149
150
    /**
151
     * 大眾銀行。
152
     */
153
    const ATM_Tachong = 'Tachong';
154
155
    /**
156
     * 永豐銀行。
157
     */
158
    const ATM_Sinopac = 'Sinopac';
159
160
    /**
161
     * 彰化銀行。
162
     */
163
    const ATM_CHB = 'CHB';
164
165
    /**
166
     * 第一銀行。
167
     */
168
    const ATM_FIRST = 'FIRST';
169
170
    // 超商類(201~300)
171
    /**
172
     * 超商代碼繳款。
173
     */
174
    const CVS = 'CVS';
175
176
    /**
177
     * OK超商代碼繳款。
178
     */
179
    const CVS_OK = 'OK';
180
181
    /**
182
     * 全家超商代碼繳款。
183
     */
184
    const CVS_FAMILY = 'FAMILY';
185
186
    /**
187
     * 萊爾富超商代碼繳款。
188
     */
189
    const CVS_HILIFE = 'HILIFE';
190
191
    /**
192
     * 7-11 ibon代碼繳款。
193
     */
194
    const CVS_IBON = 'IBON';
195
    // 其他第三方支付類(301~400)
196
197
    /**
198
     * 財付通。
199
     */
200
    const Tenpay = 'Tenpay';
201
    // 儲值/餘額消費類(401~500)
202
    /**
203
     * 儲值/餘額消費(歐付寶)
204
     */
205
    const TopUpUsed_AllPay = 'AllPay';
206
207
    /**
208
     * 儲值/餘額消費(玉山)
209
     */
210
    const TopUpUsed_ESUN = 'ESUN';
211
    // 其他類(901~999)
212
213
    /**
214
     * 信用卡(MasterCard/JCB/VISA)。
215
     */
216
    const Credit = 'Credit';
217
218
    /**
219
     * 貨到付款。
220
     */
221
    const COD = 'COD';
222
223
}
224
225
/**
226
 * 額外付款資訊。
227
 */
228
abstract class ExtraPaymentInfo {
229
230
    /**
231
     * 需要額外付款資訊。
232
     */
233
    const Yes = 'Y';
234
235
    /**
236
     * 不需要額外付款資訊。
237
     */
238
    const No = 'N';
239
240
}
241
242
/**
243
 * 額外付款資訊。
244
 */
245
abstract class DeviceType {
246
247
    /**
248
     * 桌機版付費頁面。
249
     */
250
    const PC = 'P';
251
252
    /**
253
     * 行動裝置版付費頁面。
254
     */
255
    const Mobile = 'M';
256
257
}
258
259
/**
260
 * 信用卡訂單處理動作資訊。
261
 */
262
abstract class ActionType {
263
264
    /**
265
     * 關帳
266
     */
267
    const C = 'C';
268
269
    /**
270
     * 退刷
271
     */
272
    const R = 'R';
273
274
    /**
275
     * 取消
276
     */
277
    const E = 'E';
278
279
    /**
280
     * 放棄
281
     */
282
    const N = 'N';
283
284
}
285
286
/**
287
 * 定期定額的週期種類。
288
 */
289
abstract class PeriodType {
290
291
    /**
292
     * 無
293
     */
294
    const None = '';
295
296
    /**
297
     * 年
298
     */
299
    const Year = 'Y';
300
301
    /**
302
     * 月
303
     */
304
    const Month = 'M';
305
306
    /**
307
     * 日
308
     */
309
    const Day = 'D';
310
311
}
312
313
/**
314
 * 電子發票開立註記。
315
 */
316
abstract class InvoiceState {
317
    /**
318
     * 需要開立電子發票。
319
     */
320
    const Yes = 'Y';
321
322
    /**
323
     * 不需要開立電子發票。
324
     */
325
    const No = '';
326
}
327
328
/**
329
 * 電子發票載具類別
330
 */
331
abstract class CarruerType {
332
  // 無載具
333
  const None = '';
334
335
  // 會員載具
336
  const Member = '1';
337
338
  // 買受人自然人憑證
339
  const Citizen = '2';
340
341
  // 買受人手機條碼
342
  const Cellphone = '3';
343
}
344
345
/**
346
 * 電子發票列印註記
347
 */
348
abstract class PrintMark {
349
  // 不列印
350
  const No = '0';
351
352
  // 列印
353
  const Yes = '1';
354
}
355
356
/**
357
 * 電子發票捐贈註記
358
 */
359
abstract class Donation {
360
  // 捐贈
361
  const Yes = '1';
362
363
  // 不捐贈
364
  const No = '2';
365
}
366
367
/**
368
 * 通關方式
369
 */
370
abstract class ClearanceMark {
371
  // 經海關出口
372
  const Yes = '1';
373
374
  // 非經海關出口
375
  const No = '2';
376
}
377
378
/**
379
 * 課稅類別
380
 */
381
abstract class TaxType {
382
  // 應稅
383
  const Dutiable = '1';
384
385
  // 零稅率
386
  const Zero = '2';
387
388
  // 免稅
389
  const Free = '3';
390
391
  // 應稅與免稅混合(限收銀機發票無法分辦時使用,且需通過申請核可)
392
  const Mix = '9';
393
}
394
395
/**
396
 * 字軌類別
397
 */
398
abstract class InvType {
399
  // 一般稅額
400
  const General = '07';
401
402
  // 特種稅額
403
  const Special = '08';
404
}
405
406
abstract class EncryptType {
407
    // MD5(預設)
408
    const ENC_MD5 = 0;
409
410
    // SHA256
411
    const ENC_SHA256 = 1;
412
}
413
414
abstract class UseRedeem{
415
    //使用紅利/購物金
416
    const Yes = 'Y' ;
417
418
    //不使用紅利/購物金
419
    const No = 'N' ;
420
}
421
422
class AllInOne {
423
424
    public $ServiceURL = 'ServiceURL';
425
    public $ServiceMethod = 'ServiceMethod';
426
    public $HashKey = 'HashKey';
427
    public $HashIV = 'HashIV';
428
    public $MerchantID = 'MerchantID';
429
    public $PaymentType = 'PaymentType';
430
    public $Send = 'Send';
431
    public $SendExtend = 'SendExtend';
432
    public $Query = 'Query';
433
    public $Action = 'Action';
434
    public $ChargeBack = 'ChargeBack';
435
    public $EncryptType = EncryptType::ENC_MD5;
436
437
    function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
438
439
        $this->PaymentType = 'aio';
440
        $this->Send = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('ReturnURL' => '',... => 0, 'StoreID' => '') of type array<string,string|arra...r","StoreID":"string"}> is incompatible with the declared type string of property $Send.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
441
            "ReturnURL"         => '',
442
            "ClientBackURL"     => '',
443
            "OrderResultURL"    => '',
444
            "MerchantTradeNo"   => '',
445
            "MerchantTradeDate" => '',
446
            "PaymentType"       => 'aio',
447
            "TotalAmount"       => '',
448
            "TradeDesc"         => '',
449
            "ChoosePayment"     => PaymentMethod::ALL,
450
            "Remark"            => '',
451
            "ChooseSubPayment"  => PaymentMethodItem::None,
452
            "NeedExtraPaidInfo" => ExtraPaymentInfo::No,
453
            "DeviceSource"      => '',
454
            "IgnorePayment"     => '',
455
            "PlatformID"        => '',
456
            "InvoiceMark"       => InvoiceState::No,
457
            "Items"             => array(),
458
            "UseRedeem"         => UseRedeem::No,
459
            "HoldTradeAMT"      => 0,
460
            "StoreID"           => ''
461
        );
462
463
        $this->SendExtend = array();
0 ignored issues
show
Documentation Bug introduced by
It seems like array() of type array is incompatible with the declared type string of property $SendExtend.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
464
465
        $this->Query = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('MerchantTradeNo' => '', 'TimeStamp' => '') of type array<string,string,{"Me...,"TimeStamp":"string"}> is incompatible with the declared type string of property $Query.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
466
            'MerchantTradeNo' => '',
467
            'TimeStamp' => ''
468
        );
469
        $this->Action = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('MerchantTradeNo' ...:C, 'TotalAmount' => 0) of type array<string,string|inte...otalAmount":"integer"}> is incompatible with the declared type string of property $Action.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
470
            'MerchantTradeNo' => '',
471
            'TradeNo' => '',
472
            'Action' => ActionType::C,
473
            'TotalAmount' => 0
474
        );
475
        $this->ChargeBack = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('MerchantTradeNo' ...' => 0, 'Remark' => '') of type array<string,string|inte...er","Remark":"string"}> is incompatible with the declared type string of property $ChargeBack.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
476
            'MerchantTradeNo' => '',
477
            'TradeNo' => '',
478
            'ChargeBackTotalAmount' => 0,
479
            'Remark' => ''
480
        );
481
        $this->Capture = array(
0 ignored issues
show
Bug introduced by
The property Capture does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
482
            'MerchantTradeNo' => '',
483
            'CaptureAMT' => 0,
484
            'UserRefundAMT' => 0,
485
            'PlatformID' => ''
486
        );
487
488
        $this->TradeNo = array(
0 ignored issues
show
Bug introduced by
The property TradeNo does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
489
            'DateType' => '',
490
            'BeginDate' => '',
491
            'EndDate' => '',
492
            'MediaFormated' => ''
493
        );
494
495
        $this->Trade = array(
0 ignored issues
show
Bug introduced by
The property Trade does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
496
            'CreditRefundId' => '',
497
            'CreditAmount' => '',
498
            'CreditCheckCode' => ''
499
        );
500
501
        $this->Funding = array(
0 ignored issues
show
Bug introduced by
The property Funding does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
502
            "PayDateType" => '',
503
            "StartDate" => '',
504
            "EndDate" => ''
505
        );
506
507
    }
508
509
    //產生訂單
510
    function CheckOut($target = "_self") {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
511
        $arParameters = array_merge( array('MerchantID' => $this->MerchantID, 'EncryptType' => $this->EncryptType) ,$this->Send);
512
        Send::CheckOut($target,$arParameters,$this->SendExtend,$this->HashKey,$this->HashIV,$this->ServiceURL);
513
    }
514
515
    //產生訂單html code
516
    function CheckOutString($paymentButton = null, $target = "_self") {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
517
        $arParameters = array_merge( array('MerchantID' => $this->MerchantID, 'EncryptType' => $this->EncryptType) ,$this->Send);
518
        return Send::CheckOutString($paymentButton,$target = "_self",$arParameters,$this->SendExtend,$this->HashKey,$this->HashIV,$this->ServiceURL);
519
    }
520
521
    //取得付款結果通知的方法
522
    function CheckOutFeedback() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
CheckOutFeedback uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
523
        return $arFeedback = CheckOutFeedback::CheckOut(array_merge($_POST, array('EncryptType' => $this->EncryptType)),$this->HashKey,$this->HashIV,0);
0 ignored issues
show
Unused Code introduced by
The call to CheckOutFeedback::CheckOut() has too many arguments starting with 0.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
$arFeedback is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
524
    }
525
526
    //訂單查詢作業
527
    function QueryTradeInfo() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
528
        return $arFeedback = QueryTradeInfo::CheckOut(array_merge($this->Query,array("MerchantID" => $this->MerchantID, 'EncryptType' => $this->EncryptType)) ,$this->HashKey ,$this->HashIV ,$this->ServiceURL) ;
0 ignored issues
show
Unused Code introduced by
$arFeedback is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
529
    }
530
531
    //信用卡定期定額訂單查詢的方法
532
    function QueryPeriodCreditCardTradeInfo() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
533
        return $arFeedback = QueryPeriodCreditCardTradeInfo::CheckOut(array_merge($this->Query,array("MerchantID" => $this->MerchantID, 'EncryptType' => $this->EncryptType)) ,$this->HashKey ,$this->HashIV ,$this->ServiceURL);
0 ignored issues
show
Unused Code introduced by
$arFeedback is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
534
    }
535
536
    //信用卡關帳/退刷/取消/放棄的方法
537
    function DoAction() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
538
        return $arFeedback = DoAction::CheckOut(array_merge($this->Action,array("MerchantID" => $this->MerchantID, 'EncryptType' => $this->EncryptType)) ,$this->HashKey ,$this->HashIV ,$this->ServiceURL);
0 ignored issues
show
Unused Code introduced by
$arFeedback is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
539
    }
540
541
    //廠商通知退款
542
    function AioChargeback() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
543
        return $arFeedback = AioChargeback::CheckOut(array_merge($this->ChargeBack,array("MerchantID" => $this->MerchantID, 'EncryptType' => $this->EncryptType)) ,$this->HashKey ,$this->HashIV ,$this->ServiceURL);
0 ignored issues
show
Unused Code introduced by
$arFeedback is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
544
    }
545
546
    //會員申請撥款/退款
547
    function AioCapture(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
548
        return $arFeedback = AioCapture::Capture(array_merge($this->Capture,array("MerchantID" => $this->MerchantID, 'EncryptType' => $this->EncryptType)) ,$this->HashKey ,$this->HashIV ,$this->ServiceURL);
0 ignored issues
show
Unused Code introduced by
$arFeedback is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
549
    }
550
551
    //下載會員對帳媒體檔
552
    function TradeNoAio($target = "_self"){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
553
        $arParameters = array_merge( array('MerchantID' => $this->MerchantID, 'EncryptType' => $this->EncryptType) ,$this->TradeNo);
554
        TradeNoAio::CheckOut($target,$arParameters,$this->HashKey,$this->HashIV,$this->ServiceURL);
555
    }
556
557
    //查詢信用卡單筆明細紀錄
558
    function QueryTrade(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
559
        return $arFeedback = QueryTrade::CheckOut(array_merge($this->Trade,array("MerchantID" => $this->MerchantID, 'EncryptType' => $this->EncryptType)) ,$this->HashKey ,$this->HashIV ,$this->ServiceURL);
0 ignored issues
show
Unused Code introduced by
$arFeedback is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
560
    }
561
562
    //下載信用卡撥款對帳資料檔
563
    function FundingReconDetail($target = "_self"){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
564
        $arParameters = array_merge( array('MerchantID' => $this->MerchantID, 'EncryptType' => $this->EncryptType) ,$this->Funding);
565
        FundingReconDetail::CheckOut($target,$arParameters,$this->HashKey,$this->HashIV,$this->ServiceURL);
566
    }
567
}
568
569
/**
570
* 抽象類
571
*/
572
abstract class Aio
573
{
574
575
    protected static function ServerPost($parameters ,$ServiceURL) {
576
		$ch = curl_init();
577
578
		if (FALSE === $ch) {
579
			throw new Exception('curl failed to initialize');
580
		}
581
582
		curl_setopt($ch, CURLOPT_URL, $ServiceURL);
583
		curl_setopt($ch, CURLOPT_HEADER, FALSE);
584
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
585
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
586
		curl_setopt($ch, CURLOPT_POST, TRUE);
587
		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parameters));
588
		$rs = curl_exec($ch);
589
590
		if (FALSE === $rs) {
591
			throw new Exception(curl_error($ch), curl_errno($ch));
592
		}
593
594
		curl_close($ch);
595
596
		return $rs;
597
    }
598
599
}
600
601
/**
602
*  產生訂單
603
*/
604
class Send extends Aio
605
{
606
    //付款方式物件
607
    public static $PaymentObj ;
608
609
    protected static function process($arParameters = array(),$arExtend = array())
610
    {
611
        //宣告付款方式物件
612
        $PaymentMethod    = 'allPay_'.$arParameters['ChoosePayment'];
613
        self::$PaymentObj = new $PaymentMethod;
614
615
        //檢查參數
616
        $arParameters = self::$PaymentObj->check_string($arParameters);
617
618
        //檢查商品
619
        $arParameters = self::$PaymentObj->check_goods($arParameters);
620
621
        //檢查各付款方式的額外參數&電子發票參數
622
        $arExtend = self::$PaymentObj->check_extend_string($arExtend,$arParameters['InvoiceMark']);
623
624
        //過濾
625
        $arExtend = self::$PaymentObj->filter_string($arExtend,$arParameters['InvoiceMark']);
626
627
        //合併共同參數及延伸參數
628
        return array_merge($arParameters,$arExtend) ;
629
    }
630
631
632 View Code Duplication
    static function CheckOut($target = "_self",$arParameters = array(),$arExtend = array(),$HashKey='',$HashIV='',$ServiceURL=''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
633
634
        $arParameters = self::process($arParameters,$arExtend);
635
636
        //產生檢查碼
637
        $szCheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$arParameters["EncryptType"]);
638
639
        //生成表單,自動送出
640
        $szHtml =  '<!DOCTYPE html>';
641
        $szHtml .= '<html>';
642
        $szHtml .=     '<head>';
643
        $szHtml .=         '<meta charset="utf-8">';
644
        $szHtml .=     '</head>';
645
        $szHtml .=     '<body>';
646
        $szHtml .=         "<form id=\"__allpayForm\" method=\"post\" target=\"{$target}\" action=\"{$ServiceURL}\">";
647
648
        foreach ($arParameters as $keys => $value) {
649
            $szHtml .=         "<input type=\"hidden\" name=\"{$keys}\" value=\"{$value}\" />";
650
        }
651
652
        $szHtml .=             "<input type=\"hidden\" name=\"CheckMacValue\" value=\"{$szCheckMacValue}\" />";
653
        $szHtml .=         '</form>';
654
        $szHtml .=         '<script type="text/javascript">document.getElementById("__allpayForm").submit();</script>';
655
        $szHtml .=     '</body>';
656
        $szHtml .= '</html>';
657
658
        echo $szHtml ;
659
        exit;
660
    }
661
662 View Code Duplication
    static function CheckOutString($paymentButton,$target = "_self",$arParameters = array(),$arExtend = array(),$HashKey='',$HashIV='',$ServiceURL=''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
663
664
        $arParameters = self::process($arParameters,$arExtend);
665
666
        //產生檢查碼
667
        $szCheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$arParameters["EncryptType"]);
668
669
        $szHtml =  '<!DOCTYPE html>';
670
        $szHtml .= '<html>';
671
        $szHtml .=     '<head>';
672
        $szHtml .=         '<meta charset="utf-8">';
673
        $szHtml .=     '</head>';
674
        $szHtml .=     '<body>';
675
        $szHtml .=         "<form id=\"__allpayForm\" method=\"post\" target=\"{$target}\" action=\"{$ServiceURL}\">";
676
677
        foreach ($arParameters as $keys => $value) {
678
            $szHtml .=         "<input type=\"hidden\" name=\"{$keys}\" value=\"{$value}\" />";
679
        }
680
681
        $szHtml .=             "<input type=\"hidden\" name=\"CheckMacValue\" value=\"{$szCheckMacValue}\" />";
682
        $szHtml .=             "<input type=\"submit\" id=\"__paymentButton\" value=\"{$paymentButton}\" />";
683
        $szHtml .=         '</form>';
684
        $szHtml .=     '</body>';
685
        $szHtml .= '</html>';
686
        return  $szHtml ;
687
    }
688
689
}
690
691
692
class CheckOutFeedback extends Aio
693
{
694
    static function CheckOut($arParameters = array(),$HashKey = '' ,$HashIV = ''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
695
        // 變數宣告。
696
        $arErrors = array();
697
        $arFeedback = array();
698
        $szCheckMacValue = '';
0 ignored issues
show
Unused Code introduced by
$szCheckMacValue is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
699
700
        $EncryptType = $arParameters["EncryptType"];
701
        unset($arParameters["EncryptType"]);
702
703
        // 重新整理回傳參數。
704
        foreach ($arParameters as $keys => $value) {
705
            if ($keys != 'CheckMacValue') {
706
                if ($keys == 'PaymentType') {
707
                    $value = str_replace('_CVS', '', $value);
708
                    $value = str_replace('_Tenpay', '', $value);
709
                    $value = str_replace('_CreditCard', '', $value);
710
                }
711
                if ($keys == 'PeriodType') {
712
                    $value = str_replace('Y', 'Year', $value);
713
                    $value = str_replace('M', 'Month', $value);
714
                    $value = str_replace('D', 'Day', $value);
715
                }
716
                $arFeedback[$keys] = $value;
717
            }
718
        }
719
720
        $CheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$EncryptType);
721
722
        if ($CheckMacValue != $arParameters['CheckMacValue']) {
723
            array_push($arErrors, 'CheckMacValue verify fail.');
724
        }
725
726
        if (sizeof($arErrors) > 0) {
727
            throw new Exception(join('- ', $arErrors));
728
        }
729
730
        return $arFeedback;
731
    }
732
}
733
734
735
class QueryTradeInfo extends Aio
736
{
737
    static function CheckOut($arParameters = array(),$HashKey ='',$HashIV ='',$ServiceURL = ''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
738
        $arErrors = array();
739
        $arParameters['TimeStamp'] = time();
740
        $arFeedback = array();
741
        $arConfirmArgs = array();
742
743
        $EncryptType = $arParameters["EncryptType"];
744
        unset($arParameters["EncryptType"]);
745
746
        // 呼叫查詢。
747
        if (sizeof($arErrors) == 0) {
748
            $arParameters["CheckMacValue"] = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$EncryptType);
749
750
            // 送出查詢並取回結果。
751
            $szResult = parent::ServerPost($arParameters,$ServiceURL);
752
            $szResult = str_replace(' ', '%20', $szResult);
753
            $szResult = str_replace('+', '%2B', $szResult);
754
755
            // 轉結果為陣列。
756
            parse_str($szResult, $arResult);
757
758
            // 重新整理回傳參數。
759
            foreach ($arResult as $keys => $value) {
0 ignored issues
show
Bug introduced by
The expression $arResult of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
760
                if ($keys == 'CheckMacValue') {
761
                    $szCheckMacValue = $value;
762
                } else {
763
                    $arFeedback[$keys] = $value;
764
                    $arConfirmArgs[$keys] = $value;
765
                }
766
            }
767
768
            // 驗證檢查碼。
769
            if (sizeof($arFeedback) > 0) {
770
                $szConfirmMacValue = CheckMacValue::generate($arConfirmArgs,$HashKey,$HashIV,$EncryptType);
771
                if ($szCheckMacValue != $szConfirmMacValue) {
772
                    array_push($arErrors, 'CheckMacValue verify fail.');
773
                }
774
            }
775
        }
776
777
        if (sizeof($arErrors) > 0) {
778
            throw new Exception(join('- ', $arErrors));
779
        }
780
781
        return $arFeedback ;
782
783
    }
784
}
785
786
787
class QueryPeriodCreditCardTradeInfo extends Aio
788
{
789
    static function CheckOut($arParameters = array(),$HashKey ='',$HashIV ='',$ServiceURL = ''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
790
        $arErrors = array();
791
        $arParameters['TimeStamp'] = time();
792
        $arFeedback = array();
793
        $arConfirmArgs = array();
0 ignored issues
show
Unused Code introduced by
$arConfirmArgs is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
794
795
        $EncryptType = $arParameters["EncryptType"];
796
        unset($arParameters["EncryptType"]);
797
798
        // 呼叫查詢。
799
        if (sizeof($arErrors) == 0) {
800
            $arParameters["CheckMacValue"] = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$EncryptType);
801
            // 送出查詢並取回結果。
802
            $szResult = parent::ServerPost($arParameters,$ServiceURL);
803
            $szResult = str_replace(' ', '%20', $szResult);
804
            $szResult = str_replace('+', '%2B', $szResult);
805
806
            // 轉結果為陣列。
807
            $arResult = json_decode($szResult,true);
808
            // 重新整理回傳參數。
809
            foreach ($arResult as $keys => $value) {
810
                $arFeedback[$keys] = $value;
811
            }
812
        }
813
814
        if (sizeof($arErrors) > 0) {
815
            throw new Exception(join('- ', $arErrors));
816
        }
817
818
        return $arFeedback ;
819
    }
820
}
821
822
823
class DoAction extends Aio
824
{
825
    static function CheckOut($arParameters = array(),$HashKey ='',$HashIV ='',$ServiceURL = ''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
826
        // 變數宣告。
827
        $arErrors = array();
828
        $arFeedback = array();
829
830
        $EncryptType = $arParameters["EncryptType"];
831
        unset($arParameters["EncryptType"]);
832
833
        //產生驗證碼
834
        $szCheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$EncryptType);
835
        $arParameters["CheckMacValue"] = $szCheckMacValue;
836
        // 送出查詢並取回結果。
837
        $szResult = self::ServerPost($arParameters,$ServiceURL);
838
        // 轉結果為陣列。
839
        parse_str($szResult, $arResult);
840
        // 重新整理回傳參數。
841
        foreach ($arResult as $keys => $value) {
0 ignored issues
show
Bug introduced by
The expression $arResult of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
842
            if ($keys == 'CheckMacValue') {
843
                $szCheckMacValue = $value;
844
            } else {
845
                $arFeedback[$keys] = $value;
846
            }
847
        }
848
849
        if (array_key_exists('RtnCode', $arFeedback) && $arFeedback['RtnCode'] != '1') {
850
            array_push($arErrors, vsprintf('#%s: %s', array($arFeedback['RtnCode'], $arFeedback['RtnMsg'])));
851
        }
852
853
        if (sizeof($arErrors) > 0) {
854
            throw new Exception(join('- ', $arErrors));
855
        }
856
857
        return $arFeedback ;
858
859
    }
860
}
861
862
863
864
class AioChargeback extends Aio
865
{
866
    static function CheckOut($arParameters = array(), $HashKey='',$HashIV='',$ServiceURL=''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
867
868
        // 變數宣告。
869
        $arErrors = array();
870
        $arFeedback = array();
871
872
        $EncryptType = $arParameters["EncryptType"];
873
        unset($arParameters["EncryptType"]);
874
875
        $szCheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$EncryptType);
876
        $arParameters["CheckMacValue"] = $szCheckMacValue;
877
        // 送出查詢並取回結果。
878
        $szResult = self::ServerPost($arParameters,$ServiceURL);
879
        // 檢查結果資料。
880
        if ($szResult == '1|OK') {
881
            $arFeedback['RtnCode'] = '1';
882
            $arFeedback['RtnMsg'] = 'OK';
883
        } else {
884
            array_push($arErrors, str_replace('-', ': ', $szResult));
885
        }
886
887
        if (sizeof($arErrors) > 0) {
888
            throw new Exception(join('- ', $arErrors));
889
        }
890
891
        return $arFeedback;
892
893
    }
894
}
895
896
897
class AioCapture extends Aio
898
{
899
    static function Capture($arParameters=array(),$HashKey='',$HashIV='',$ServiceURL=''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
900
901
        $arErrors   = array();
902
        $arFeedback = array();
903
904
        $EncryptType = $arParameters["EncryptType"];
905
        unset($arParameters["EncryptType"]);
906
907
        $szCheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$EncryptType);
908
        $arParameters["CheckMacValue"] = $szCheckMacValue;
909
910
        // 送出查詢並取回結果。
911
        $szResult = self::ServerPost($arParameters,$ServiceURL);
912
913
        // 轉結果為陣列。
914
        parse_str($szResult, $arResult);
915
916
        // 重新整理回傳參數。
917
        foreach ($arResult as $keys => $value) {
0 ignored issues
show
Bug introduced by
The expression $arResult of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
918
            $arFeedback[$keys] = $value;
919
        }
920
921
        if (sizeof($arErrors) > 0) {
922
            throw new Exception(join('- ', $arErrors));
923
        }
924
925
        return $arFeedback;
926
927
    }
928
}
929
930 View Code Duplication
class TradeNoAio extends Aio
0 ignored issues
show
Duplication introduced by
This class 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...
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
931
{
932
    static function CheckOut($target = "_self",$arParameters = array(),$HashKey='',$HashIV='',$ServiceURL=''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
933
        //產生檢查碼
934
        $EncryptType = $arParameters['EncryptType'];
935
        unset($arParameters['EncryptType']);
936
937
        $szCheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$EncryptType);
938
939
        //生成表單,自動送出
940
        $szHtml =  '<!DOCTYPE html>';
941
        $szHtml .= '<html>';
942
        $szHtml .=     '<head>';
943
        $szHtml .=         '<meta charset="utf-8">';
944
        $szHtml .=     '</head>';
945
        $szHtml .=     '<body>';
946
        $szHtml .=         "<form id=\"__allpayForm\" method=\"post\" target=\"{$target}\" action=\"{$ServiceURL}\">";
947
948
        foreach ($arParameters as $keys => $value) {
949
            $szHtml .=         "<input type=\"hidden\" name=\"{$keys}\" value=\"{$value}\" />";
950
        }
951
952
        $szHtml .=             "<input type=\"hidden\" name=\"CheckMacValue\" value=\"{$szCheckMacValue}\" />";
953
        $szHtml .=         '</form>';
954
        $szHtml .=         '<script type="text/javascript">document.getElementById("__allpayForm").submit();</script>';
955
        $szHtml .=     '</body>';
956
        $szHtml .= '</html>';
957
958
        echo $szHtml ;
959
        exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method CheckOut() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
960
    }
961
}
962
963
class QueryTrade extends Aio
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
964
{
965
    static function CheckOut($arParameters = array(),$HashKey ='',$HashIV ='',$ServiceURL = ''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
966
        $arErrors = array();
967
        $arFeedback = array();
968
        $arConfirmArgs = array();
0 ignored issues
show
Unused Code introduced by
$arConfirmArgs is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
969
970
        $EncryptType = $arParameters["EncryptType"];
971
        unset($arParameters["EncryptType"]);
972
973
        // 呼叫查詢。
974
        if (sizeof($arErrors) == 0) {
975
            $arParameters["CheckMacValue"] = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$EncryptType);
976
            // 送出查詢並取回結果。
977
            $szResult = parent::ServerPost($arParameters,$ServiceURL);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (ServerPost() instead of CheckOut()). Are you sure this is correct? If so, you might want to change this to $this->ServerPost().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
978
979
            // 轉結果為陣列。
980
            $arResult = json_decode($szResult,true);
981
982
            // 重新整理回傳參數。
983
            foreach ($arResult as $keys => $value) {
984
                $arFeedback[$keys] = $value;
985
            }
986
        }
987
988
        if (sizeof($arErrors) > 0) {
989
            throw new Exception(join('- ', $arErrors));
990
        }
991
992
        return $arFeedback ;
993
    }
994
}
995
996 View Code Duplication
class FundingReconDetail extends Aio
0 ignored issues
show
Duplication introduced by
This class 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...
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
997
{
998
    static function CheckOut($target = "_self",$arParameters = array(),$HashKey='',$HashIV='',$ServiceURL=''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
999
        //產生檢查碼
1000
        $EncryptType = $arParameters['EncryptType'];
1001
        unset($arParameters['EncryptType']);
1002
1003
        $szCheckMacValue = CheckMacValue::generate($arParameters,$HashKey,$HashIV,$EncryptType);
1004
1005
        //生成表單,自動送出
1006
        $szHtml =  '<!DOCTYPE html>';
1007
        $szHtml .= '<html>';
1008
        $szHtml .=     '<head>';
1009
        $szHtml .=         '<meta charset="utf-8">';
1010
        $szHtml .=     '</head>';
1011
        $szHtml .=     '<body>';
1012
        $szHtml .=         "<form id=\"__allpayForm\" method=\"post\" target=\"{$target}\" action=\"{$ServiceURL}\">";
1013
1014
        foreach ($arParameters as $keys => $value) {
1015
            $szHtml .=         "<input type=\"hidden\" name=\"{$keys}\" value=\"{$value}\" />";
1016
        }
1017
1018
        $szHtml .=             "<input type=\"hidden\" name=\"CheckMacValue\" value=\"{$szCheckMacValue}\" />";
1019
        $szHtml .=         '</form>';
1020
        $szHtml .=         '<script type="text/javascript">document.getElementById("__allpayForm").submit();</script>';
1021
        $szHtml .=     '</body>';
1022
        $szHtml .= '</html>';
1023
1024
        echo $szHtml ;
1025
        exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method CheckOut() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1026
    }
1027
}
1028
1029
1030
1031
1032
1033
1034
Abstract class Verification
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
1035
{
1036
    // 付款方式延伸參數
1037
    public $arPayMentExtend = array();
1038
1039
    // 電子發票延伸參數。
1040
    public $arInvoice = array(
1041
            "RelateNumber",
1042
            "CustomerIdentifier",
1043
            "CarruerType" ,
1044
            "CustomerID" ,
1045
            "Donation" ,
1046
            "Print" ,
1047
            "TaxType",
1048
            "CustomerName" ,
1049
            "CustomerAddr" ,
1050
            "CustomerPhone" ,
1051
            "CustomerEmail" ,
1052
            "ClearanceMark" ,
1053
            "CarruerNum" ,
1054
            "LoveCode" ,
1055
            "InvoiceRemark" ,
1056
            "DelayDay",
1057
            "InvoiceItemName",
1058
            "InvoiceItemCount",
1059
            "InvoiceItemWord",
1060
            "InvoiceItemPrice",
1061
            "InvoiceItemTaxType",
1062
            "InvType"
1063
        );
1064
1065
    //檢查共同參數
1066
    public function check_string($arParameters = array())
1067
    {
1068
        $arErrors = array();
1069
1070
        if (strlen($arParameters['MerchantID']) == 0) {
1071
            array_push($arErrors, 'MerchantID is required.');
1072
        }
1073
        if (strlen($arParameters['MerchantID']) > 10) {
1074
            array_push($arErrors, 'MerchantID max langth as 10.');
1075
        }
1076
        if (strlen($arParameters['ReturnURL']) == 0) {
1077
            array_push($arErrors, 'ReturnURL is required.');
1078
        }
1079
        if (strlen($arParameters['ClientBackURL']) > 200) {
1080
            array_push($arErrors, 'ClientBackURL max langth as 10.');
1081
        }
1082
        if (strlen($arParameters['OrderResultURL']) > 200) {
1083
            array_push($arErrors, 'OrderResultURL max langth as 10.');
1084
        }
1085
        if (strlen($arParameters['MerchantTradeNo']) == 0) {
1086
            array_push($arErrors, 'MerchantTradeNo is required.');
1087
        }
1088
        if (strlen($arParameters['MerchantTradeNo']) > 20) {
1089
            array_push($arErrors, 'MerchantTradeNo max langth as 20.');
1090
        }
1091
        if (strlen($arParameters['MerchantTradeDate']) == 0) {
1092
            array_push($arErrors, 'MerchantTradeDate is required.');
1093
        }
1094
        if (strlen($arParameters['TotalAmount']) == 0) {
1095
            array_push($arErrors, 'TotalAmount is required.');
1096
        }
1097
        if (strlen($arParameters['TradeDesc']) == 0) {
1098
            array_push($arErrors, 'TradeDesc is required.');
1099
        }
1100
        if (strlen($arParameters['TradeDesc']) > 200) {
1101
            array_push($arErrors, 'TradeDesc max langth as 200.');
1102
        }
1103
        if (strlen($arParameters['ChoosePayment']) == 0) {
1104
            array_push($arErrors, 'ChoosePayment is required.');
1105
        }
1106
        if (strlen($arParameters['NeedExtraPaidInfo']) == 0) {
1107
            array_push($arErrors, 'NeedExtraPaidInfo is required.');
1108
        }
1109
        if (sizeof($arParameters['Items']) == 0) {
1110
            array_push($arErrors, 'Items is required.');
1111
        }
1112
1113
        // 檢查CheckMacValue加密方式
1114
        if (strlen($arParameters['EncryptType']) > 1) {
1115
            array_push($arErrors, 'EncryptType max langth as 1.');
1116
        }
1117
1118
        if (sizeof($arErrors)>0) throw new Exception(join('<br>', $arErrors));
1119
1120
        if (!$arParameters['PlatformID']) {
1121
            unset($arParameters['PlatformID']);
1122
        }
1123
1124
        if ($arParameters['ChoosePayment']!=='ALL') {
1125
            unset($arParameters['IgnorePayment']);
1126
        }
1127
1128
        return $arParameters ;
1129
    }
1130
1131
    //檢查商品
1132
    public function check_goods($arParameters = array())
1133
    {
1134
        // 檢查產品名稱。
1135
        $arErrors = array();
1136
        $szItemName = '';
1137
1138
        if (sizeof($arParameters['Items']) > 0) {
1139
            foreach ($arParameters['Items'] as $keys => $value) {
1140
                $szItemName .= vsprintf('#%s %d %s x %u', $arParameters['Items'][$keys]);
1141
                if (!array_key_exists('ItemURL', $arParameters)) {
1142
                    $arParameters['ItemURL'] = $arParameters['Items'][$keys]['URL'];
1143
                }
1144
            }
1145
1146
            if (strlen($szItemName) > 0) {
1147
                $szItemName = mb_substr($szItemName, 1, 200);
1148
                $arParameters['ItemName'] = $szItemName ;
1149
            }
1150
        } else {
1151
            array_push($arErrors, "Goods information not found.");
1152
        }
1153
1154
        if (sizeof($arErrors)>0) throw new Exception(join('<br>', $arErrors));
1155
1156
        unset($arParameters['Items']);
1157
1158
        return $arParameters ;
1159
    }
1160
1161
    //過濾多餘參數
1162
    public function filter_string($arExtend = array(),$InvoiceMark = '')
1163
    {
1164
        $arPayMentExtend = array_merge(array_keys($this->arPayMentExtend), ($InvoiceMark == '') ? array() : $this->arInvoice);
1165
1166
        foreach ($arExtend as $key => $value) {
1167
            if (!in_array($key,$arPayMentExtend )) {
1168
                unset($arExtend[$key]);
1169
            }
1170
        }
1171
1172
        return $arExtend ;
1173
    }
1174
1175
    //檢查預設參數
1176
    public function check_extend_string($arExtend = array(),$InvoiceMark = '')
1177
    {
1178
        //沒設定參數的話,就給預設參數
1179
        foreach ($this->arPayMentExtend as $key => $value) {
1180
            if (!isset($arExtend[$key])) $arExtend[$key] = $value;
1181
        }
1182
1183
        //若有開發票,檢查一下發票參數
1184
        if ($InvoiceMark == 'Y') $arExtend = $this->check_invoiceString($arExtend);
1185
1186
        return $arExtend ;
1187
    }
1188
1189
    //檢查電子發票參數
1190
    public function check_invoiceString($arExtend = array()){
1191
        $arErrors = array();
1192
1193
        // 廠商自訂編號RelateNumber(不可為空)
1194 View Code Duplication
        if(!array_key_exists('RelateNumber', $arExtend)){
1195
            array_push($arErrors, 'RelateNumber is required.');
1196
        }else{
1197
            if (strlen($arExtend['RelateNumber']) > 30) {
1198
                array_push($arErrors, "RelateNumber max length as 30.");
1199
            }
1200
        }
1201
1202
        // 統一編號CustomerIdentifier(預設為空字串)
1203 View Code Duplication
        if(!array_key_exists('CustomerIdentifier', $arExtend)){
1204
            $arExtend['CustomerIdentifier'] = '';
1205
        }else{
1206
            //統編長度只能為8
1207
            if(strlen($arExtend['CustomerIdentifier']) != 8){
1208
                array_push($arErrors, "CustomerIdentifier length should be 8.");
1209
            }
1210
        }
1211
1212
        // 載具類別CarruerType(預設為None)
1213
        if(!array_key_exists('CarruerType', $arExtend)){
1214
            $arExtend['CarruerType'] = CarruerType::None ;
1215
        }else{
1216
            //有設定統一編號的話,載具類別不可為合作特店載具或自然人憑證載具。
1217
            $notPrint = array(CarruerType::Member, CarruerType::Citizen);
1218
            if(strlen($arExtend['CustomerIdentifier']) > 0 && in_array($arExtend['CarruerType'], $notPrint)){
1219
                array_push($arErrors, "CarruerType should NOT be Member or Citizen.");
1220
            }
1221
        }
1222
1223
        // 客戶代號CustomerID(預設為空字串)
1224 View Code Duplication
        if(!array_key_exists('CustomerID', $arExtend)) {
1225
            $arExtend['CustomerID'] = '';
1226
        }else{
1227
            if($arExtend['CarruerType'] == CarruerType::Member && strlen($arExtend['CustomerID']) == 0){
1228
                array_push($arErrors, "CustomerID is required.");
1229
            }
1230
        }
1231
        // 捐贈註記 Donation(預設為No)
1232 View Code Duplication
        if(!array_key_exists('Donation', $arExtend)){
1233
            $arExtend['Donation'] = Donation::No ;
1234
        }else{
1235
            //若有帶統一編號,不可捐贈
1236
            if(strlen($arExtend['CustomerIdentifier']) > 0 && $arExtend['Donation'] != Donation::No  ){
1237
                array_push($arErrors, "Donation should be No.");
1238
            }
1239
        }
1240
1241
        // 列印註記Print(預設為No)
1242 View Code Duplication
        if(!array_key_exists('Print', $arExtend)){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
1243
            $arExtend['Print'] = PrintMark::No ;
1244
        }else{
1245
            //捐贈註記為捐贈(Yes)時,請設定不列印(No)
1246
            if($arExtend['Donation'] == Donation::Yes && $arExtend['Print'] != PrintMark::No){
1247
                array_push($arErrors, "Print should be No.");
1248
            }
1249
            // 統一編號不為空字串時,請設定列印(Yes)
1250
            if(strlen($arExtend['CustomerIdentifier']) > 0 && $arExtend['Print'] != PrintMark::Yes){
1251
                array_push($arErrors, "Print should be Yes.");
1252
            }
1253
        }
1254
        // 客戶名稱CustomerName(UrlEncode, 預設為空字串)
1255 View Code Duplication
        if(!array_key_exists('CustomerName', $arExtend)){
1256
            $arExtend['CustomerName'] = '';
1257
        }else{
1258
            if (mb_strlen($arExtend['CustomerName'], 'UTF-8') > 20) {
1259
                  array_push($arErrors, "CustomerName max length as 20.");
1260
            }
1261
            // 列印註記為列印(Yes)時,此參數不可為空字串
1262
            if($arExtend['Print'] == PrintMark::Yes && strlen($arExtend['CustomerName']) == 0){
1263
                array_push($arErrors, "CustomerName is required.");
1264
            }
1265
        }
1266
1267
        // 客戶地址CustomerAddr(UrlEncode, 預設為空字串)
1268 View Code Duplication
        if(!array_key_exists('CustomerAddr', $arExtend)){
1269
            $arExtend['CustomerAddr'] = '';
1270
        }else{
1271
            if (mb_strlen($arExtend['CustomerAddr'], 'UTF-8') > 200) {
1272
                  array_push($arErrors, "CustomerAddr max length as 200.");
1273
            }
1274
            // 列印註記為列印(Yes)時,此參數不可為空字串
1275
            if($arExtend['Print'] == PrintMark::Yes && strlen($arExtend['CustomerAddr']) == 0){
1276
                array_push($arErrors, "CustomerAddr is required.");
1277
            }
1278
        }
1279
        // 客戶電話CustomerPhone
1280 View Code Duplication
        if(!array_key_exists('CustomerPhone', $arExtend)){
1281
            $arExtend['CustomerPhone'] = '';
1282
        }else{
1283
            if (strlen($arExtend['CustomerPhone']) > 20) array_push($arErrors, "CustomerPhone max length as 20.");
1284
        }
1285
1286
        // 客戶信箱CustomerEmail
1287 View Code Duplication
        if(!array_key_exists('CustomerEmail', $arExtend)){
1288
            $arExtend['CustomerEmail'] = '';
1289
        }else{
1290
            if (strlen($arExtend['CustomerEmail']) > 200) array_push($arErrors, "CustomerEmail max length as 200.");
1291
        }
1292
1293
        //(CustomerEmail與CustomerPhone擇一不可為空)
1294
        if (strlen($arExtend['CustomerPhone']) == 0 and strlen($arExtend['CustomerEmail']) == 0) array_push($arErrors, "CustomerPhone or CustomerEmail is required.");
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
1295
1296
        //課稅類別 TaxType(不可為空)
1297
        if (strlen($arExtend['TaxType']) == 0) array_push($arErrors, "TaxType is required.");
1298
1299
        //通關方式 ClearanceMark(預設為空字串)
1300 View Code Duplication
        if(!array_key_exists('ClearanceMark', $arExtend)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
1301
            $arExtend['ClearanceMark'] = '';
1302
        }else{
1303
            //課稅類別為零稅率(Zero)時,ClearanceMark不可為空字串
1304
            if($arExtend['TaxType'] == TaxType::Zero && ($arExtend['ClearanceMark'] != ClearanceMark::Yes || $arExtend['ClearanceMark'] != ClearanceMark::No)) {
1305
                array_push($arErrors, "ClearanceMark is required.");
1306
            }
1307
            if (strlen($arExtend['ClearanceMark']) > 0 && $arExtend['TaxType'] != TaxType::Zero) {
1308
                array_push($arErrors, "Please remove ClearanceMark.");
1309
            }
1310
        }
1311
1312
        // CarruerNum(預設為空字串)
1313
        if (!array_key_exists('CarruerNum', $arExtend)) {
1314
            $arExtend['CarruerNum'] = '';
1315
        } else {
1316
            switch ($arExtend['CarruerType']) {
1317
                // 載具類別為無載具(None)或會員載具(Member)時,系統自動忽略載具編號
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1318
                case CarruerType::None:
1319
                case CarruerType::Member:
1320
                break;
1321
                // 載具類別為買受人自然人憑證(Citizen)時,請設定自然人憑證號碼,前2碼為大小寫英文,後14碼為數字
1322 View Code Duplication
                case CarruerType::Citizen:
1323
                    if (!preg_match('/^[a-zA-Z]{2}\d{14}$/', $arExtend['CarruerNum'])){
1324
                        array_push($arErrors, "Invalid CarruerNum.");
1325
                    }
1326
                break;
1327
                // 載具類別為買受人手機條碼(Cellphone)時,請設定手機條碼,第1碼為「/」,後7碼為大小寫英文、數字、「+」、「-」或「.」
1328 View Code Duplication
                case CarruerType::Cellphone:
1329
                    if (!preg_match('/^\/{1}[0-9a-zA-Z+-.]{7}$/', $arExtend['CarruerNum'])) {
1330
                        array_push($arErrors, "Invalid CarruerNum.");
1331
                    }
1332
                break;
1333
1334
                default:
1335
                    array_push($arErrors, "Please remove CarruerNum.");
1336
            }
1337
        }
1338
1339
        // 愛心碼 LoveCode(預設為空字串)
1340
        if(!array_key_exists('LoveCode', $arExtend)) $arExtend['LoveCode'] = '';
1341
        // 捐贈註記為捐贈(Yes)時,參數長度固定3~7碼,請設定全數字或第1碼大小寫「X」,後2~6碼全數字
1342
        if ($arExtend['Donation'] == Donation::Yes) {
1343
            if (!preg_match('/^([xX]{1}[0-9]{2,6}|[0-9]{3,7})$/', $arExtend['LoveCode'])) {
1344
                array_push($arErrors, "Invalid LoveCode.");
1345
            }
1346
        }
1347
1348
        //備註 InvoiceRemark(UrlEncode, 預設為空字串)
1349
        if(!array_key_exists('InvoiceRemark', $arExtend)) $arExtend['InvoiceRemark'] = '';
1350
1351
        // 延遲天數 DelayDay(不可為空, 預設為0) 延遲天數,範圍0~15,設定為0時,付款完成後立即開立發票
1352
        if(!array_key_exists('DelayDay', $arExtend)) $arExtend['DelayDay'] = 0 ;
1353
        if ($arExtend['DelayDay'] < 0 or $arExtend['DelayDay'] > 15) array_push($arErrors, "DelayDay should be 0 ~ 15.");
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
1354
1355
1356
        // 字軌類別 InvType(不可為空)
1357
        if (!array_key_exists('InvType', $arExtend)) array_push($arErrors, "InvType is required.");
1358
1359
        //商品相關整理
1360
        if(!array_key_exists('InvoiceItems', $arExtend)){
1361
            array_push($arErrors, "Invoice Goods information not found.");
1362
        }else{
1363
            $InvSptr = '|';
1364
            $tmpItemName = array();
1365
            $tmpItemCount = array();
1366
            $tmpItemWord = array();
1367
            $tmpItemPrice = array();
1368
            $tmpItemTaxType = array();
1369
            foreach ($arExtend['InvoiceItems'] as $tmpItemInfo) {
1370
                if (mb_strlen($tmpItemInfo['Name'], 'UTF-8') > 0) {
1371
                    array_push($tmpItemName, $tmpItemInfo['Name']);
1372
                }
1373
                if (strlen($tmpItemInfo['Count']) > 0) {
1374
                    array_push($tmpItemCount, $tmpItemInfo['Count']);
1375
                }
1376
                if (mb_strlen($tmpItemInfo['Word'], 'UTF-8') > 0) {
1377
                    array_push($tmpItemWord, $tmpItemInfo['Word']);
1378
                }
1379
                if (strlen($tmpItemInfo['Price']) > 0) {
1380
                    array_push($tmpItemPrice, $tmpItemInfo['Price']);
1381
                }
1382
                if (strlen($tmpItemInfo['TaxType']) > 0) {
1383
                    array_push($tmpItemTaxType, $tmpItemInfo['TaxType']);
1384
                }
1385
            }
1386
1387
            if ($arExtend['TaxType'] == TaxType::Mix) {
1388
                if (in_array(TaxType::Dutiable, $tmpItemTaxType) and in_array(TaxType::Free, $tmpItemTaxType)) {
1389
                    // Do nothing
1390
                }  else {
1391
                    $tmpItemTaxType = array();
1392
                }
1393
            }
1394
            if ((count($tmpItemName) + count($tmpItemCount) + count($tmpItemWord) + count($tmpItemPrice) + count($tmpItemTaxType)) == (count($tmpItemName) * 5)) {
1395
                $arExtend['InvoiceItemName']    = implode($InvSptr, $tmpItemName);
1396
                $arExtend['InvoiceItemCount']   = implode($InvSptr, $tmpItemCount);
1397
                $arExtend['InvoiceItemWord']    = implode($InvSptr, $tmpItemWord);
1398
                $arExtend['InvoiceItemPrice']   = implode($InvSptr, $tmpItemPrice);
1399
                $arExtend['InvoiceItemTaxType'] = implode($InvSptr, $tmpItemTaxType);
1400
            }
1401
1402
            unset($arExtend['InvoiceItems']);
1403
        }
1404
1405
1406
        $encode_fields = array(
1407
                'CustomerName',
1408
                'CustomerAddr',
1409
                'CustomerEmail',
1410
                'InvoiceItemName',
1411
                'InvoiceItemWord',
1412
                'InvoiceRemark'
1413
            );
1414
        foreach ($encode_fields as $tmp_field) {
1415
            $arExtend[$tmp_field] = urlencode($arExtend[$tmp_field]);
1416
        }
1417
1418
        if (sizeof($arErrors) > 0) {
1419
            throw new Exception(join('<br>', $arErrors));
1420
        }
1421
1422
        return $arExtend ;
1423
    }
1424
1425
}
1426
1427
1428
/**
1429
*  付款方式:超商代碼
1430
*/
1431
class allPay_CVS extends Verification
1432
{
1433
    public  $arPayMentExtend = array(
1434
                            'Desc_1'           =>'',
1435
                            'Desc_2'           =>'',
1436
                            'Desc_3'           =>'',
1437
                            'Desc_4'           =>'',
1438
                            'PaymentInfoURL'   =>'',
1439
                            'ClientRedirectURL'=>'',
1440
                            'StoreExpireDate'  =>''
1441
                        );
1442
    //過濾多餘參數
1443
    function filter_string($arExtend = array(),$InvoiceMark = '')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1444
    {
1445
        $arExtend = parent::filter_string($arExtend, $InvoiceMark);
1446
        return $arExtend ;
1447
    }
1448
1449
}
1450
1451
/**
1452
*  付款方式 ATM
1453
*/
1454
1455
class allPay_ATM extends Verification
1456
{
1457
    public  $arPayMentExtend = array(
1458
                            'ExpireDate'       => 3,
1459
                            'PaymentInfoURL'   => '',
1460
                            'ClientRedirectURL'=> '',
1461
                        );
1462
    //過濾多餘參數
1463
    function filter_string($arExtend = array(),$InvoiceMark = '')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1464
    {
1465
        $arExtend = parent::filter_string($arExtend, $InvoiceMark);
1466
        return $arExtend ;
1467
    }
1468
1469
}
1470
1471
/**
1472
*  付款方式 WebATM
1473
*/
1474
class allPay_WebATM extends Verification
1475
{
1476
    public  $arPayMentExtend = array();
1477
1478
    //過濾多餘參數
1479
    function filter_string($arExtend = array(),$InvoiceMark = '')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1480
    {
1481
        $arExtend = parent::filter_string($arExtend, $InvoiceMark);
1482
        return $arExtend ;
1483
    }
1484
1485
}
1486
1487
/**
1488
* 付款方式:Tenpay
1489
*/
1490
class allPay_Tenpay extends Verification
1491
{
1492
    public  $arPayMentExtend = array('ExpireTime' => '');
1493
1494
    //過濾多餘參數
1495
    function filter_string($arExtend = array(),$InvoiceMark = '')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1496
    {
1497
        $arExtend = parent::filter_string($arExtend, $InvoiceMark);
1498
        return $arExtend ;
1499
    }
1500
1501
}
1502
1503
/**
1504
* 付款方式 : 信用卡
1505
*/
1506
class allPay_Credit extends Verification
1507
{
1508
    public $arPayMentExtend = array(
1509
                                    "CreditInstallment" => '',
1510
                                    "InstallmentAmount" => 0,
1511
                                    "Redeem"            => FALSE,
1512
                                    "PeriodAmount"      => '',
1513
                                    "PeriodType"        => '',
1514
                                    "Frequency"         => '',
1515
                                    "ExecTimes"         => '',
1516
                                    "PeriodReturnURL"   => ''
1517
                                );
1518
1519
    //過濾多餘參數
1520
    function filter_string($arExtend = array(),$InvoiceMark = ''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1521
        $arExtend = parent::filter_string($arExtend, $InvoiceMark);
1522
        return $arExtend ;
1523
    }
1524
1525
}
1526
1527
/**
1528
* 付款方式:TopUpUsed
1529
*/
1530
class allPay_TopUpUsed extends Verification
1531
{
1532
    public  $arPayMentExtend = array();
1533
1534
    //過濾多餘參數
1535
    function filter_string($arExtend = array(),$InvoiceMark = ''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1536
        return $arExtend ;
1537
    }
1538
1539
}
1540
1541
/**
1542
*  付款方式:全功能
1543
*/
1544
class allPay_ALL extends Verification
1545
{
1546
    public  $arPayMentExtend = array();
1547
1548
    //過濾多餘參數
1549
    function filter_string($arExtend = array(),$InvoiceMark = ''){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1550
        return $arExtend ;
1551
    }
1552
1553
}
1554
1555
1556
/**
1557
*  檢查碼
1558
*/
1559
class CheckMacValue{
1560
1561
    static function generate($arParameters = array(),$HashKey = '' ,$HashIV = '',$encType = 0){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1562
        $sMacValue = '' ;
1563
1564
        if(isset($arParameters))
1565
        {
1566
            unset($arParameters['CheckMacValue']);
1567
            uksort($arParameters, array('CheckMacValue','merchantSort'));
1568
1569
            // 組合字串
1570
            $sMacValue = 'HashKey=' . $HashKey ;
1571
            foreach($arParameters as $key => $value)
1572
            {
1573
                $sMacValue .= '&' . $key . '=' . $value ;
1574
            }
1575
1576
            $sMacValue .= '&HashIV=' . $HashIV ;
1577
1578
            // URL Encode編碼
1579
            $sMacValue = urlencode($sMacValue);
1580
1581
            // 轉成小寫
1582
            $sMacValue = strtolower($sMacValue);
1583
1584
            // 取代為與 dotNet 相符的字元
1585
            $sMacValue = str_replace('%2d', '-', $sMacValue);
1586
            $sMacValue = str_replace('%5f', '_', $sMacValue);
1587
            $sMacValue = str_replace('%2e', '.', $sMacValue);
1588
            $sMacValue = str_replace('%21', '!', $sMacValue);
1589
            $sMacValue = str_replace('%2a', '*', $sMacValue);
1590
            $sMacValue = str_replace('%28', '(', $sMacValue);
1591
            $sMacValue = str_replace('%29', ')', $sMacValue);
1592
1593
            // 編碼
1594
            switch ($encType) {
1595
                case EncryptType::ENC_SHA256:
1596
                    // SHA256 編碼
1597
                    $sMacValue = hash('sha256', $sMacValue);
1598
                break;
1599
1600
                case EncryptType::ENC_MD5:
1601
                default:
1602
                // MD5 編碼
1603
                    $sMacValue = md5($sMacValue);
1604
            }
1605
1606
                $sMacValue = strtoupper($sMacValue);
1607
        }
1608
1609
        return $sMacValue ;
1610
    }
1611
    /**
1612
    * 自訂排序使用
1613
    */
1614
    private static function merchantSort($a,$b)
1615
    {
1616
        return strcasecmp($a, $b);
1617
    }
1618
1619
}
1620
1621
1622
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
1623