Skip to content

Commit ebe6056

Browse files
committed
Add response values
1 parent bbf2cec commit ebe6056

File tree

1 file changed

+42
-14
lines changed

1 file changed

+42
-14
lines changed

src/Message/Response.php

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
namespace Omnipay\Braintree\Message;
44

55
use Omnipay\Common\Message\AbstractResponse;
6-
use Omnipay\Common\Message\RequestInterface;
76

87
/**
98
* Response
109
*/
1110
class Response extends AbstractResponse
1211
{
13-
public function __construct(RequestInterface $request, $data)
14-
{
15-
$this->request = $request;
16-
$this->data = $data;
17-
}
18-
12+
/**
13+
* @return bool
14+
*/
1915
public function isSuccessful()
2016
{
2117
if (isset($this->data->success)) {
@@ -25,6 +21,9 @@ public function isSuccessful()
2521
return false;
2622
}
2723

24+
/**
25+
* @return string|null
26+
*/
2827
public function getMessage()
2928
{
3029
if (isset($this->data->message) && $this->data->message) {
@@ -34,19 +33,48 @@ public function getMessage()
3433
return null;
3534
}
3635

36+
/**
37+
* @return string
38+
*/
3739
public function getCode()
3840
{
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');
4442
}
4543

44+
/**
45+
* @return string
46+
*/
4647
public function getTransactionReference()
4748
{
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;
5078
}
5179

5280
return null;

0 commit comments

Comments
 (0)