1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PayumTW\Mypay\Action; |
4
|
|
|
|
5
|
|
|
use Payum\Core\Action\ActionInterface; |
6
|
|
|
use Payum\Core\Bridge\Spl\ArrayObject; |
7
|
|
|
use Payum\Core\Request\GetStatusInterface; |
8
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
9
|
|
|
|
10
|
|
|
class StatusAction implements ActionInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* {@inheritdoc} |
14
|
|
|
* |
15
|
|
|
* @param GetStatusInterface $request |
16
|
|
|
*/ |
17
|
6 |
|
public function execute($request) |
18
|
|
|
{ |
19
|
6 |
|
RequestNotSupportedException::assertSupports($this, $request); |
20
|
|
|
|
21
|
6 |
|
$details = ArrayObject::ensureArrayObject($request->getModel()); |
22
|
|
|
|
23
|
6 |
|
$code = null; |
24
|
6 |
|
if (isset($details['prc']) === true) { |
25
|
4 |
|
$code = $details['prc']; |
26
|
6 |
|
} elseif (isset($details['code']) === true) { |
27
|
4 |
|
$code = $details['code']; |
28
|
|
|
} |
29
|
|
|
|
30
|
6 |
|
if (is_null($code) === false) { |
31
|
|
|
|
32
|
|
|
/* |
33
|
|
|
* 290 交易成功,但資訊不符 交易成功,但資訊不符(包含金額、已逾期...等) |
34
|
|
|
*/ |
35
|
4 |
|
if (in_array($code, ['250', '290', '600'], true) === true) { |
36
|
1 |
|
$request->markCaptured(); |
37
|
|
|
|
38
|
1 |
|
return; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/* |
42
|
|
|
* 280 儲值/WEBATM線上待付款,但需要等到使用者線上確認交易 |
43
|
|
|
*/ |
44
|
3 |
|
if (in_array($code, ['200', '260', '270', '280', 'A0002'], true) === true) { |
45
|
1 |
|
$request->markPending(); |
46
|
|
|
|
47
|
1 |
|
return; |
48
|
|
|
} |
49
|
|
|
|
50
|
2 |
|
if ($code === '380') { |
51
|
1 |
|
$request->markExpired(); |
52
|
|
|
|
53
|
1 |
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
$request->markFailed(); |
57
|
|
|
|
58
|
1 |
|
return; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if ( |
62
|
2 |
|
isset($details['SysCode']) === true && |
63
|
2 |
|
isset($details['ResultCode']) === true && |
64
|
2 |
|
$details['ResultCode'] == '100' |
65
|
|
|
) { |
66
|
1 |
|
$request->markFailed(); |
67
|
|
|
|
68
|
1 |
|
return; |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
$request->markNew(); |
72
|
1 |
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
6 |
|
public function supports($request) |
78
|
|
|
{ |
79
|
|
|
return |
80
|
6 |
|
$request instanceof GetStatusInterface && |
81
|
6 |
|
$request->getModel() instanceof \ArrayAccess; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|