XmlResponse::getTransactionReference()   B
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 10
cp 0
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 8
nc 5
nop 0
crap 42
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->data;
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