StatusAction::execute()   B
last analyzed

Complexity

Conditions 6
Paths 7

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 6

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 29
ccs 16
cts 16
cp 1
rs 8.439
cc 6
eloc 15
nc 7
nop 1
crap 6
1
<?php
2
3
namespace PayumTW\Esunbank\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 5
    public function execute($request)
18
    {
19 5
        RequestNotSupportedException::assertSupports($this, $request);
20
21 5
        $details = ArrayObject::ensureArrayObject($request->getModel());
22
23 5
        if (isset($details['RC']) === false) {
24 1
            $request->markNew();
25
26 1
            return;
27
        }
28
29 4
        if ($details['RC'] === '00') {
30 3
            if (isset($details['RRN']) === true) {
31
                // TXNAMOUNT 單筆查詢
32 2
                isset($details['MACD']) === true || isset($details['TXNAMOUNT']) === true
33 2
                    ? $request->markCaptured()
34 2
                    : $request->markCanceled();
35
36 2
                return;
37
            }
38
39 1
            $request->markRefunded();
40
41 1
            return;
42
        }
43
44 1
        $request->markFailed();
45 1
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 5
    public function supports($request)
51
    {
52
        return
53 5
            $request instanceof GetStatusInterface &&
54 5
            $request->getModel() instanceof \ArrayAccess;
55
    }
56
}
57