1 | <?php |
||
9 | class Response extends AbstractResponse |
||
10 | { |
||
11 | /** |
||
12 | * The raw data contained in the response. |
||
13 | * |
||
14 | * @var mixed |
||
15 | */ |
||
16 | protected $rawData; |
||
17 | |||
18 | 40 | public function __construct(RequestInterface $request, $data) |
|
24 | |||
25 | /** |
||
26 | * Is the response successful? |
||
27 | * |
||
28 | * @return boolean |
||
29 | */ |
||
30 | 34 | public function isSuccessful() |
|
31 | { |
||
32 | // Check for succeeded parameter |
||
33 | 34 | $succeeded = Arr::get($this->data, 'succeeded'); |
|
34 | 34 | if (!is_null($succeeded)) { |
|
35 | 22 | return $succeeded == true; |
|
36 | } |
||
37 | |||
38 | // Check for state parameter |
||
39 | 12 | $state = Arr::get($this->data, 'state'); |
|
40 | 12 | if (!is_null($state)) { |
|
41 | 4 | return $state == 'retained'; |
|
42 | } |
||
43 | |||
44 | // Check for errors array |
||
45 | 8 | $errors = Arr::get($this->data, 'errors'); |
|
46 | 8 | if (is_array($errors)) { |
|
47 | 4 | return !count($errors); |
|
48 | } |
||
49 | |||
50 | // Check if it's an indexed array (lists) |
||
51 | 4 | if (array_values($this->data) === $this->data) { |
|
52 | 2 | return true; |
|
53 | } |
||
54 | |||
55 | 2 | return false; |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * Raw data |
||
60 | * |
||
61 | * @return array Response raw data |
||
62 | */ |
||
63 | 2 | public function getRawData() |
|
67 | |||
68 | /** |
||
69 | * Response Message |
||
70 | * |
||
71 | * @return null|string A response message from the payment gateway |
||
72 | */ |
||
73 | 2 | public function getMessage() |
|
77 | |||
78 | /** |
||
79 | * Response code |
||
80 | * |
||
81 | * @return null|string A response code from the payment gateway |
||
82 | */ |
||
83 | 22 | public function getCode() |
|
87 | |||
88 | /** |
||
89 | * Gateway Reference |
||
90 | * |
||
91 | * @return null|string A reference provided by the gateway to represent this transaction |
||
92 | */ |
||
93 | 28 | public function getTransactionReference() |
|
97 | |||
98 | /** |
||
99 | * Get the transaction ID as generated by the merchant website. |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | 2 | public function getTransactionId() |
|
107 | |||
108 | /** |
||
109 | * Amount |
||
110 | * |
||
111 | * @return null|integer The transaction amount |
||
112 | */ |
||
113 | 12 | public function getAmount() |
|
123 | |||
124 | /** |
||
125 | * Integer Amount |
||
126 | * |
||
127 | * @return null|integer The transaction integer amount |
||
128 | */ |
||
129 | 6 | public function getAmountInteger() |
|
133 | |||
134 | /** |
||
135 | * Payment method token |
||
136 | * |
||
137 | * @return null|string The payment method token |
||
138 | */ |
||
139 | 14 | public function getPaymentMethodToken() |
|
143 | |||
144 | /** |
||
145 | * Payment method type |
||
146 | * |
||
147 | * @return null|string The payment method type |
||
148 | */ |
||
149 | 2 | public function getPaymentMethodType() |
|
153 | |||
154 | /** |
||
155 | * Since token |
||
156 | * |
||
157 | * @return null|string The since token of a paginated list |
||
158 | */ |
||
159 | 4 | public function getSinceToken() |
|
169 | |||
170 | /** |
||
171 | * @return array|null |
||
172 | */ |
||
173 | public function getErrors() |
||
177 | |||
178 | } |
||
179 |