Completed
Push — master ( 0c2573...0eced7 )
by Dominik
02:01
created

XmlResponse::getData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * w-vision
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the MIT License
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that are distributed with this source code.
10
 *
11
 * @copyright  Copyright (c) 2016 Woche-Pass AG (http://www.w-vision.ch)
12
 * @license    MIT License
13
 */
14
15
namespace Omnipay\Datatrans\Message;
16
17
use Omnipay\Common\Message\RequestInterface;
18
19
/**
20
 * Datatrans XML Response
21
 */
22
class XmlResponse extends AbstractResponse
23
{
24
    /**
25
     * @return array
26
     */
27
    public function getData()
28
    {
29
        return $this->httpRequest->request->all();
0 ignored issues
show
Bug introduced by
The property httpRequest does not seem to exist. Did you mean request?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
30
    }
31
32
    /**
33
     * @return bool
34
     */
35
    public function isRedirect()
36
    {
37
        return false;
38
    }
39
40
    /**
41
     * @return string|null
42
     */
43
    public function getRedirectUrl()
44
    {
45
        return null;
46
    }
47
48
    /**
49
     * Get the required redirect method (either GET or POST).
50
     *
51
     * @return string
52
     */
53
    public function getRedirectMethod()
54
    {
55
        return 'GET';
56
    }
57
58
    /**
59
     * Gets the redirect form data array, if the redirect method is POST.
60
     *
61
     * @return null
62
     */
63
    public function getRedirectData()
64
    {
65
        return null;
66
    }
67
68
    /**
69
     * @return bool
70
     */
71 10
    public function isSuccessful()
72
    {
73 10
        return empty($this->data['error']);
74
    }
75
76
    /**
77
     * @return string|null
78
     */
79
    public function getTransactionReference()
80
    {
81
        // This is usually correct for payments, authorizations, etc
82
        if (!empty($this->data['transactions']) && !empty($this->data['transactions'][0]['related_resources'])) {
83
            foreach (array('sale', 'authorization') as $type) {
84
                if (!empty($this->data['transactions'][0]['related_resources'][0][$type])) {
85
                    return $this->data['transactions'][0]['related_resources'][0][$type]['id'];
86
                }
87
            }
88
        }
89
90
        // This is a fallback, but is correct for fetch transaction and possibly others
91
        if (!empty($this->data['id'])) {
92
            return $this->data['id'];
93
        }
94
95
        return null;
96
    }
97
98
    /**
99
     * @return null
100
     */
101 2
    public function getMessage()
102
    {
103 2
        if (isset($this->data['error'])) {
104
            return $this->data['error']['errorDetail'];
105
        }
106
107 2
        if (isset($this->data['response'])) {
108 2
            return $this->data['response']['responseMessage'];
109
        }
110
111
        return null;
112
    }
113
114
    /**
115
     * @return string
116
     */
117 8
    public function getCode()
118
    {
119 8
        if (isset($this->data['response'])) {
120 5
            return $this->data['response']['responseCode'];
121
        }
122
123 3
        if (isset($this->data['error'])) {
124 3
            return $this->data['error']['errorCode'];
125
        }
126
127
        return '9999';
128
    }
129
}
130