3
3
namespace Omnipay \Braintree \Message ;
4
4
5
5
use Omnipay \Common \Message \AbstractResponse ;
6
- use Omnipay \Common \Message \RequestInterface ;
7
6
8
7
/**
9
8
* Response
10
9
*/
11
10
class Response extends AbstractResponse
12
11
{
13
- public function __construct (RequestInterface $ request , $ data )
14
- {
15
- $ this ->request = $ request ;
16
- $ this ->data = $ data ;
17
- }
18
-
12
+ /**
13
+ * @return bool
14
+ */
19
15
public function isSuccessful ()
20
16
{
21
17
if (isset ($ this ->data ->success )) {
@@ -25,6 +21,9 @@ public function isSuccessful()
25
21
return false ;
26
22
}
27
23
24
+ /**
25
+ * @return string|null
26
+ */
28
27
public function getMessage ()
29
28
{
30
29
if (isset ($ this ->data ->message ) && $ this ->data ->message ) {
@@ -34,19 +33,48 @@ public function getMessage()
34
33
return null ;
35
34
}
36
35
36
+ /**
37
+ * @return string
38
+ */
37
39
public function getCode ()
38
40
{
39
- if (isset ($ this ->data ->transaction ) && $ this ->data ->transaction ) {
40
- return $ this ->data ->transaction ->status ;
41
- }
42
-
43
- return null ;
41
+ return $ this ->transactionValue ('status ' );
44
42
}
45
43
44
+ /**
45
+ * @return string
46
+ */
46
47
public function getTransactionReference ()
47
48
{
48
- if (isset ($ this ->data ->transaction ) && $ this ->data ->transaction ) {
49
- return $ this ->data ->transaction ->id ;
49
+ return $ this ->transactionValue ('id ' );
50
+ }
51
+
52
+ /**
53
+ * @return string|null
54
+ */
55
+ public function getAmount ()
56
+ {
57
+ return $ this ->transactionValue ('amount ' );
58
+ }
59
+
60
+ /**
61
+ * @return string|null
62
+ */
63
+ public function getTransactionId ()
64
+ {
65
+ return $ this ->transactionValue ('orderId ' );
66
+ }
67
+
68
+ /**
69
+ * Return a value from the transaction object
70
+ *
71
+ * @param string $key
72
+ * @return mixed
73
+ */
74
+ protected function transactionValue ($ key )
75
+ {
76
+ if (isset ($ this ->data ->transaction ) && $ this ->data ->transaction && isset ($ this ->data ->transaction ->$ key )) {
77
+ return $ this ->data ->transaction ->$ key ;
50
78
}
51
79
52
80
return null ;
0 commit comments