1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* w-vision |
4
|
|
|
* |
5
|
|
|
* LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the GNU General Public License version 3 (GPLv3) |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt |
9
|
|
|
* files that are distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @copyright Copyright (c) 2016 Woche-Pass AG (http://www.w-vision.ch) |
12
|
|
|
* @license GNU General Public License version 3 (GPLv3) |
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 bool |
26
|
|
|
*/ |
27
|
|
|
public function isRedirect() |
28
|
|
|
{ |
29
|
|
|
return false; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return string|null |
34
|
|
|
*/ |
35
|
|
|
public function getRedirectUrl() |
36
|
|
|
{ |
37
|
|
|
return null; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get the required redirect method (either GET or POST). |
42
|
|
|
* |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
public function getRedirectMethod() |
46
|
|
|
{ |
47
|
|
|
return 'GET'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Gets the redirect form data array, if the redirect method is POST. |
52
|
|
|
* |
53
|
|
|
* @return null |
54
|
|
|
*/ |
55
|
|
|
public function getRedirectData() |
56
|
|
|
{ |
57
|
|
|
return null; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return bool |
62
|
|
|
*/ |
63
|
|
|
public function isSuccessful() |
64
|
|
|
{ |
65
|
|
|
return empty($this->data['error']); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string|null |
70
|
|
|
*/ |
71
|
|
|
public function getTransactionReference() |
72
|
|
|
{ |
73
|
|
|
// This is usually correct for payments, authorizations, etc |
74
|
|
|
if (!empty($this->data['transactions']) && !empty($this->data['transactions'][0]['related_resources'])) { |
75
|
|
|
foreach (array('sale', 'authorization') as $type) { |
76
|
|
|
if (!empty($this->data['transactions'][0]['related_resources'][0][$type])) { |
77
|
|
|
return $this->data['transactions'][0]['related_resources'][0][$type]['id']; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
// This is a fallback, but is correct for fetch transaction and possibly others |
83
|
|
|
if (!empty($this->data['id'])) { |
84
|
|
|
return $this->data['id']; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return null; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return null |
92
|
|
|
*/ |
93
|
|
|
public function getMessage() |
94
|
|
|
{ |
95
|
|
|
if (isset($this->data['error'])) { |
96
|
|
|
return $this->data['error']['errorDetail']; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if(isset($this->data['response'])) { |
100
|
|
|
return $this->data['response']['responseMessage']; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return null; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getCode() |
110
|
|
|
{ |
111
|
|
|
if(isset($this->data['response'])) { |
112
|
|
|
return $this->data['response']['responseCode']; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
if(isset($this->data['error'])) { |
116
|
|
|
return $this->data['error']['errorCode']; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return '9999'; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|