|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PayumTW\Collect\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
|
8 |
|
public function execute($request) |
|
18
|
|
|
{ |
|
19
|
8 |
|
RequestNotSupportedException::assertSupports($this, $request); |
|
20
|
|
|
|
|
21
|
8 |
|
$details = ArrayObject::ensureArrayObject($request->getModel()); |
|
22
|
|
|
|
|
23
|
8 |
|
if ($details['ret'] === 'OK') { |
|
24
|
1 |
|
$request->markCaptured(); |
|
25
|
|
|
|
|
26
|
1 |
|
return; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
8 |
|
if ($details['ret'] === 'FAIL') { |
|
30
|
1 |
|
$request->markFailed(); |
|
31
|
|
|
|
|
32
|
1 |
|
return; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
8 |
|
if (isset($details['link_id']) === true) { |
|
36
|
4 |
|
if ($details['status'] === 'OK') { |
|
37
|
3 |
|
if (isset($details['refund_amount']) === true) { |
|
38
|
1 |
|
$request->markRefunded(); |
|
39
|
|
|
|
|
40
|
1 |
|
return; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
2 |
|
if (isset($details['order_detail']) === false) { |
|
44
|
1 |
|
$request->markCanceled(); |
|
45
|
|
|
|
|
46
|
1 |
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
1 |
|
$request->markCaptured(); |
|
50
|
|
|
|
|
51
|
1 |
|
return; |
|
52
|
|
|
} |
|
53
|
1 |
|
} |
|
54
|
|
|
|
|
55
|
8 |
|
if ($details['status'] === 'ERROR') { |
|
56
|
1 |
|
$request->markFailed(); |
|
57
|
|
|
|
|
58
|
1 |
|
return; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
// CVS |
|
62
|
8 |
|
if (isset($details['link_id']) === false && $details['status'] === 'OK') { |
|
63
|
1 |
|
$request->markPending(); |
|
64
|
|
|
|
|
65
|
1 |
|
return; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$statusMap = [ |
|
69
|
|
|
// B 授權完成 |
|
70
|
7 |
|
'B' => 'markCaptured', |
|
71
|
|
|
// O 請款作業中(請款作業中,無法進行取消授權) |
|
72
|
7 |
|
'O' => 'markSuspended', |
|
73
|
|
|
// E 請款完成 |
|
74
|
7 |
|
'E' => 'markCaptured', |
|
75
|
|
|
// F 授權失敗 |
|
76
|
7 |
|
'F' => 'markFailed', |
|
77
|
|
|
// D 訂單逾期 |
|
78
|
7 |
|
'D' => 'markExpired', |
|
79
|
|
|
// P 請款失敗 |
|
80
|
7 |
|
'P' => 'markFailed', |
|
81
|
|
|
// M 取消交易完成 |
|
82
|
7 |
|
'M' => 'markCanceled', |
|
83
|
|
|
// N 取消交易失敗 |
|
84
|
7 |
|
'N' => 'markFailed', |
|
85
|
|
|
// Q 取消授權完成 |
|
86
|
7 |
|
'Q' => 'markRefunded', |
|
87
|
|
|
// R 取消授權失敗 |
|
88
|
7 |
|
'R' => 'markFailed', |
|
89
|
7 |
|
]; |
|
90
|
|
|
|
|
91
|
7 |
|
if (isset($statusMap[$details['status']]) === true) { |
|
92
|
6 |
|
call_user_func([$request, $statusMap[$details['status']]]); |
|
93
|
|
|
|
|
94
|
6 |
|
return; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
1 |
|
$request->markNew(); |
|
98
|
1 |
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* {@inheritdoc} |
|
102
|
|
|
*/ |
|
103
|
8 |
|
public function supports($request) |
|
104
|
|
|
{ |
|
105
|
|
|
return |
|
106
|
8 |
|
$request instanceof GetStatusInterface && |
|
107
|
8 |
|
$request->getModel() instanceof \ArrayAccess; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|