Completed
Push — master ( 43f247...a0bde3 )
by Vladimir
03:04
created

Response::getStatus()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 5
cp 0.6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
crap 2.2559
1
<?php
2
3
namespace Omnipay\AcquiroPay\Message;
4
5
use Omnipay\Common\Message\AbstractResponse;
6
use Omnipay\Common\Message\RedirectResponseInterface;
7
8
/**
9
 * Response.
10
 */
11
class Response extends AbstractResponse implements RedirectResponseInterface
12
{
13
    /**
14
     * Get the response data.
15
     *
16
     * @return mixed
17
     */
18 30
    public function getData()
19
    {
20 30
        $parent = parent::getData();
21
22 30
        return json_decode(json_encode((array) $parent), true);
23
    }
24
25
    /**
26
     * Response Message.
27
     *
28
     * @return null|string A response message from the payment gateway
29
     */
30 4
    public function getMessage()
31
    {
32 4
        $data = $this->getData();
33
34 4
        return isset($data['description']) ? $data['description'] : null;
35
    }
36
37
    /**
38
     * Get status.
39
     *
40
     * @return string|null
41
     */
42 24
    public function getStatus()
43
    {
44 24
        $data = $this->getData();
45
46 24
        return isset($data['extended_status']) ? $data['extended_status'] : null;
47
    }
48
49
    /**
50
     * Is the response successful?
51
     *
52
     * @return bool
53
     */
54 30
    public function isSuccessful()
55
    {
56 30
        $data = $this->getData();
57
58
        return
59 30
            (isset($data['status']) && $data['status'] !== 'KO') &&
60 30
            (isset($data['duplicate']) && $data['duplicate'] !== 'true');
61
    }
62
63
    /**
64
     * Does the response require a redirect?
65
     *
66
     * @return bool
67
     */
68 8
    public function isRedirect()
69
    {
70 8
        $request = $this->request->getData();
71 8
        $response = $this->getData();
72
73
        return
74 8
            $request['opcode'] === 0 &&
75 8
            $response['extended_status'] === '3DSECURE';
76
    }
77
78
    /**
79
     * Gateway Reference.
80
     *
81
     * @return null|string A reference provided by the gateway to represent this transaction
82
     */
83 18
    public function getTransactionReference()
84
    {
85 18
        $data = $this->getData();
86
87 18
        return isset($data['payment_id']) ? $data['payment_id'] : null;
88
    }
89
90
    /**
91
     * Gets the redirect target url.
92
     *
93
     * @return string
94
     */
95 4
    public function getRedirectUrl()
96
    {
97 4
        $data = $this->getData();
98
99 4
        return $data['additional']['secure3d']['auth-form'];
100
    }
101
102
    /**
103
     * Get the required redirect method (either GET or POST).
104
     *
105
     * @return string
106
     */
107 4
    public function getRedirectMethod()
108
    {
109 4
        $data = $this->getData();
110
111 4
        return $data['additional']['secure3d']['auth-form-method'];
112
    }
113
114
    /**
115
     * Gets the redirect form data array, if the redirect method is POST.
116
     *
117
     * @return array
118
     */
119 4
    public function getRedirectData()
120
    {
121 4
        $data = $this->getData();
122 4
        $request = $this->getRequest()->getParameters();
123
124
        return array(
125 4
            'PaReq'   => $data['additional']['secure3d']['retransmit']['PaReq'],
126 4
            'MD'      => $data['additional']['secure3d']['retransmit']['MD'],
127 4
            'TermUrl' => $request['returnUrl'],
128 4
        );
129
    }
130
}
131