Completed
Push — master ( f0d480...72b83a )
by Gabriel
08:08 queued 04:14
created

Response::getRiskAnalysis()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Omnipay\Ebanx\Message;
4
5
use Omnipay\Common\Message\AbstractResponse;
6
use Omnipay\Common\Message\RequestInterface;
7
8
/**
9
 * Ebanx Response
10
 *
11
 * This is the response class for all Ebanx requests.
12
 *
13
 * @see \Omnipay\Ebanx\Gateway
14
 */
15
class Response extends AbstractResponse
16
{
17 75
    public function __construct(RequestInterface $request, $data)
18
    {
19 75
        $this->request = $request;
20 75
        $this->data = $data;
21 75
    }
22
23
    /**
24
     * Is the transaction a redirect?
25
     *
26
     * @return bool
27
     */
28 15
    public function isRedirect()
29
    {
30 15
        return isset($this->data['redirect_url']);
31
    }
32
33
    /**
34
     * Get the redirect url from the response.
35
     *
36
     * Returns null if the request was not a redirect.
37
     *
38
     * @return string|null
39
     */
40 9
    public function getRedirectUrl()
41
    {
42 9
        if (isset($this->data['redirect_url'])) {
43 6
            return $this->data['redirect_url'];
44
        }
45
46 3
        return null;
47
    }
48
49
    /**
50
     * Is the transaction successful?
51
     *
52
     * @return bool
53
     */
54 30
    public function isSuccessful()
55
    {
56
57 30
        return $this->data['status'] == "SUCCESS";
58
    }
59
60
    /**
61
     * Get the transaction reference.
62
     *
63
     * @return string|null
64
     */
65 12 View Code Duplication
    public function getTransactionReference()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67 12
        if (isset($this->data['payment']['hash'])) {
68 9
            return $this->data['payment']['hash'];
69
        }
70
71 3
        return null;
72
    }
73
    /**
74
     * Get the transaction id.
75
     *
76
     * @return string|null
77
     */
78 12 View Code Duplication
    public function getTransactionId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
    {
80 12
        if (isset($this->data['payment']['merchant_payment_code'])) {
81 9
            return $this->data['payment']['merchant_payment_code'];
82
        }
83
84 3
        return null;
85
    }
86
87
    /**
88
     * Get the error message from the response.
89
     *
90
     * Returns null if the request was successful.
91
     *
92
     * @return string|null
93
     */
94 15
    public function getMessage()
95
    {
96 15
        if (!$this->isSuccessful()) {
97 6
            return '[' . $this->data['status_code'] . '] ' . $this->data['status_message'];
98 9
        } elseif ($boletoData = $this->getBoleto()) {
99 3
            return $boletoData['boleto_barcode'];
100 6
        } elseif ($transactionStatus = $this->getTransactionStatus()) {
101 3
            return '[' . $transactionStatus['code'] . '] ' .$transactionStatus['description'];
102
        }
103
104 3
        return null;
105
    }
106
107
    /**
108
     * Get a cardReference, from the createCard requests.
109
     *
110
     * @return string|null
111
     */
112 6
    public function getCardReference()
113
    {
114 6
        if (isset($this->data['token'])) {
115 3
            return $this->data['token'];
116
        }
117
118 3
        return null;
119
    }
120
121
    /**
122
     * Get all paymentData, from the requests.
123
     *
124
     * @return string|null
125
     */
126 27
    public function getPaymentData($key = null)
127
    {
128 27
        if (isset($this->data['payment'])) {
129 24
            if ($key) {
130 24
                if (isset($this->data['payment'][$key])) {
131 21
                    return $this->data['payment'][$key];
132
                } else {
133 6
                    return null;
134
                }
135
            }
136
137 3
            return $this->data['payment'];
138
        }
139
140 3
        return null;
141
    }
142
143
    /**
144
     * Get the boleto_url, boleto_barcode and boleto_expiration_date in the
145
     * transaction object.
146
     *
147
     * @return array|null the boleto_url, boleto_barcode and boleto_expiration_date
148
     */
149 12
    public function getBoleto()
150
    {
151 12
        $data = null;
152
153 12
        if (isset($this->data['payment']['boleto_url'])) {
154
            $data = array(
155 6
                'boleto_url'             => $this->data['payment']['boleto_url'],
156 6
                'boleto_barcode'         => $this->data['payment']['boleto_barcode'],
157 6
                'boleto_expiration_date' => $this->data['payment']['due_date'],
158
            );
159
        }
160
161 12
        return $data;
162
    }
163
164
    /**
165
     * Get the payment status out of the response array
166
     *
167
     * @return string
168
     */
169 9
    public function getPaymentStatus()
170
    {
171
172 9
        return $this->getPaymentData('status');
173
    }
174
175
    /**
176
     * Get the transaction status out of the response array
177
     *
178
     * @return array|null
179
     */
180 9
    public function getTransactionStatus()
181
    {
182
183 9
        return $this->getPaymentData('transaction_status');
184
    }
185
186
    /**
187
     * Get the refunds propeties out of the response array
188
     *
189
     * @return array|null
190
     */
191 3
    public function getRefunds()
192
    {
193
194 3
        return $this->getPaymentData('refunds');
195
    }
196
197
198
    /**
199
     * Get the risk analysis in the transaction object.
200
     *
201
     * @return array|null the boleto_url, boleto_barcode and boleto_expiration_date
202
     */
203 6
    public function getRiskAnalysis()
204
    {
205 6
        $data = null;
206
207 6
        if (isset($this->data['payment']['risk_analysis'])) {
208 3
            $data = $this->data['payment']['risk_analysis'];
209
        }
210
211 6
        return $data;
212
    }
213
214
}
215