PurchaseResponse::getTransactionId()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Omnipay\Emp\Message;
4
5
use Omnipay\Common\Message\AbstractResponse;
6
use Omnipay\Common\Message\RequestInterface;
7
8
/**
9
 * @author    Ivan Kerin <[email protected]>
10
 * @copyright 2014, Clippings Ltd.
11
 * @license   http://spdx.org/licenses/BSD-3-Clause
12
 */
13
class PurchaseResponse extends AbstractResponse
14
{
15
    /**
16
     * @return boolean
17
     */
18 2
    public function isSuccessful()
19
    {
20 2
        return ($this->getTransactionResponse() === 'A' and ! $this->getErrors());
21
    }
22
23
    /**
24
     * @return array|null
25
     */
26 2
    public function getErrors()
27
    {
28 2
        if (isset($this->data['errors']['error'])) {
29 1
            $errors = $this->data['errors']['error'];
30
31 1
            return isset($errors['code']) ? array($errors) : $errors;
32
        }
33 1
    }
34
35
    /**
36
     * @return string|null
37
     */
38 2
    public function getErrorMessage()
39
    {
40 2
        $errors = $this->getErrors();
41
42 2
        if ($errors) {
43 1
            return join(', ', array_map(function ($item) {
44 1
                return "{$item['text']} ({$item['code']})";
45 1
            }, $errors));
46
        }
47 1
    }
48
49
    /**
50
     * @return string|null
51
     */
52 2
    public function getTransactionId()
53
    {
54 2
        if (isset($this->data['order_id'])) {
55 1
            return $this->data['order_id'];
56
        }
57 1
    }
58
59
    /**
60
     * @return string|null
61
     */
62 2
    public function getTransactionReference()
63
    {
64 2
        if (isset($this->data['transaction']['trans_id'])) {
65 1
            return $this->data['transaction']['trans_id'];
66
        }
67 1
    }
68
69
    /**
70
     * @return string|null
71
     */
72 2
    public function getTransactionResponse()
73
    {
74 2
        if (isset($this->data['transaction']['response'])) {
75 1
            return $this->data['transaction']['response'];
76
        }
77 1
    }
78
79
    /**
80
     * @return string|null
81
     */
82 3
    public function getCode()
83
    {
84 3
        $errors = $this->getErrors();
85
86 3
        if ($errors) {
87 1
            return $errors[0]['code'];
88
        }
89
90 2
        if (isset($this->data['transaction']['response_code'])) {
91 1
            return $this->data['transaction']['response_code'];
92
        }
93 1
    }
94
95
    /**
96
     * @return string|null
97
     */
98 3
    public function getMessage()
99
    {
100 3
        if ($this->getErrors()) {
101 1
            return $this->getErrorMessage();
102
        }
103
104 2
        if (isset($this->data['transaction']['response_text'])) {
105 1
            return $this->data['transaction']['response_text'];
106
        }
107 1
    }
108
}
109