|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PayumTW\Ecpay\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 StatusLogisticsAction 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 |
|
if (isset($details['ErrorMessage']) === true) { |
|
24
|
1 |
|
$request->markFailed(); |
|
25
|
|
|
|
|
26
|
1 |
|
return; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
6 |
|
if (isset($details['ResCode']) === true) { |
|
30
|
2 |
|
if ($details['ResCode'] === '0') { |
|
31
|
1 |
|
$request->markFailed(); |
|
32
|
|
|
|
|
33
|
1 |
|
return; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
1 |
|
$request->markCaptured(); |
|
37
|
|
|
|
|
38
|
1 |
|
return; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
6 |
|
if (isset($details['RtnCode']) === true) { |
|
42
|
5 |
|
if ($details['RtnCode'] === '0') { |
|
43
|
1 |
|
$request->markFailed(); |
|
44
|
|
|
|
|
45
|
1 |
|
return; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
4 |
|
if ($details['RtnCode'] === '1') { |
|
49
|
3 |
|
if (isset($details['RtnMerchantTradeNo']) === true) { |
|
50
|
1 |
|
$request->markRefunded(); |
|
51
|
|
|
|
|
52
|
1 |
|
return; |
|
53
|
|
|
} |
|
54
|
|
|
// 取消訂單(統一超商C2C). |
|
55
|
3 |
|
if (isset($details['CVSPaymentNo']) === true && isset($details['MerchantTradeDate']) === false) { |
|
56
|
1 |
|
$request->markCanceled(); |
|
57
|
|
|
|
|
58
|
1 |
|
return; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
// 宅配逆物流訂單產生 |
|
62
|
2 |
|
if (isset($details['AllPayLogisticsID']) === true && isset($details['MerchantTradeDate']) === false) { |
|
63
|
1 |
|
$request->markRefunded(); |
|
64
|
|
|
|
|
65
|
1 |
|
return; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
1 |
|
$request->markCaptured(); |
|
69
|
|
|
|
|
70
|
1 |
|
return; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
$request->markUnknown(); |
|
74
|
|
|
|
|
75
|
1 |
|
return; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
// 超商取貨逆物流訂單(全家超商B2C). |
|
79
|
3 |
|
if (isset($details['RtnMerchantTradeNo']) === true && isset($details['RtnOrderNo']) === true) { |
|
80
|
1 |
|
$request->markRefunded(); |
|
81
|
|
|
|
|
82
|
1 |
|
return; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
2 |
|
if (isset($details['CVSStoreID']) === true) { |
|
86
|
1 |
|
$request->markCaptured(); |
|
87
|
|
|
|
|
88
|
1 |
|
return; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
1 |
|
$request->markNew(); |
|
92
|
1 |
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* {@inheritdoc} |
|
96
|
|
|
*/ |
|
97
|
6 |
|
public function supports($request) |
|
98
|
|
|
{ |
|
99
|
|
|
return |
|
100
|
6 |
|
$request instanceof GetStatusInterface && |
|
101
|
6 |
|
$request->getModel() instanceof \ArrayAccess; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|