BaseResponse::setReceivedAt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
namespace Getnet\API;
3
4
/**
5
 * Class BaseResponse
6
 *
7
 * @package Getnet\API
8
 */
9
class BaseResponse implements \JsonSerializable
10
{
11
    public $payment_id;
12
13
    public $seller_id;
14
15
    public $amount;
16
17
    public $currency;
18
19
    public $order_id;
20
21
    public $status;
22
23
    public $received_at;
24
25
    public $error_message;
26
27
    public $description;
28
29
    public $description_detail;
30
31
    public $status_code;
32
33
    public $responseJSON;
34
35
    public $status_label;
36
37
    /**
38
     * @return array|mixed
39
     */
40
    public function jsonSerialize()
41
    {
42
        return get_object_vars($this);
43
    }
44
45
    /**
46
     * @return mixed
47
     */
48
    public function getErrorMessage()
49
    {
50
        return $this->error_message;
51
    }
52
53
    /**
54
     * @param $error_message
55
     * @return $this
56
     */
57
    public function setErrorMessage($error_message)
58
    {
59
        $this->error_message = $error_message;
60
61
        return $this;
62
    }
63
64
    /**
65
     * @return mixed
66
     */
67
    public function getStatusCode()
68
    {
69
        return $this->status_code;
70
    }
71
72
    /**
73
     * @param $status_code
74
     * @return $this
75
     */
76
    public function setStatusCode($status_code)
77
    {
78
        $this->status_code = $status_code;
79
80
        return $this;
81
    }
82
83
    /**
84
     * @return mixed
85
     */
86
    public function getDescriptionDetail()
87
    {
88
        return $this->description_detail;
89
    }
90
91
    /**
92
     * @param $description_detail
93
     * @return $this
94
     */
95
    public function setDescriptionDetail($description_detail)
96
    {
97
        $this->description_detail = $description_detail;
98
99
        return $this;
100
    }
101
102
    /**
103
     * @return string
104
     */
105
    public function getErrorDescription()
106
    {
107
        return $this->description."\n";
108
    }
109
110
    /**
111
     * @param $description
112
     * @return $this
113
     */
114
    public function setErrorDescription($description)
115
    {
116
        $this->description = $description;
117
118
        return $this;
119
    }
120
121
    /**
122
     * @return mixed
123
     */
124
    public function getPaymentId()
125
    {
126
        return $this->payment_id;
127
    }
128
129
    /**
130
     * @param $payment_id
131
     * @return $this
132
     */
133
    public function setPaymentId($payment_id)
134
    {
135
        $this->payment_id = $payment_id;
136
137
        return $this;
138
    }
139
140
    /**
141
     * @return mixed
142
     */
143
    public function getSellerId()
144
    {
145
        return $this->seller_id;
146
    }
147
148
    /**
149
     * @param $seller_id
150
     * @return $this
151
     */
152
    public function setSellerId($seller_id)
153
    {
154
        $this->seller_id = $seller_id;
155
156
        return $this;
157
    }
158
159
    /**
160
     * @return mixed
161
     */
162
    public function getAmount()
163
    {
164
        return $this->amount;
165
    }
166
167
    /**
168
     * @param $amount
169
     * @return $this
170
     */
171
    public function setAmount($amount)
172
    {
173
        $this->amount = $amount;
174
175
        return $this;
176
    }
177
178
    /**
179
     * @return mixed
180
     */
181
    public function getCurrency()
182
    {
183
        return $this->currency;
184
    }
185
186
    /**
187
     * @param $currency
188
     * @return $this
189
     */
190
    public function setCurrency($currency)
191
    {
192
        $this->currency = $currency;
193
194
        return $this;
195
    }
196
197
    /**
198
     * @return mixed
199
     */
200
    public function getOrderId()
201
    {
202
        return $this->order_id;
203
    }
204
205
    /**
206
     * @param $order_id
207
     * @return $this
208
     */
209
    public function setOrderId($order_id)
210
    {
211
        $this->order_id = $order_id;
212
213
        return $this;
214
    }
215
216
    /**
217
     * @return mixed
218
     */
219
    public function getStatus()
220
    {
221
        if ($this->status_code == 201) {
222
            $this->status = Transaction::STATUS_AUTHORIZED;
223
        } elseif ($this->status_code == 202) {
224
            $this->status = Transaction::STATUS_AUTHORIZED;
225
        } elseif ($this->status_code == 402) {
226
            $this->status = Transaction::STATUS_DENIED;
227
        } elseif ($this->status_code == 400) {
228
            $this->status = Transaction::STATUS_ERROR;
229
        } elseif ($this->status_code == 402) {
230
            $this->status = Transaction::STATUS_ERROR;
231
        } elseif ($this->status_code == 500) {
232
            $this->status = Transaction::STATUS_ERROR;
233
        } elseif (isset($this->redirect_url)) {
234
            $this->status = Transaction::STATUS_PENDING;
235
        } elseif (isset($this->status_label)) {
236
            $this->status = $this->status_label;
237
        }
238
239
        return $this->status;
240
    }
241
242
    /**
243
     * @param $status
244
     * @return $this
245
     */
246
    public function setStatus($status)
247
    {
248
        $this->status = $status;
249
250
        return $this;
251
    }
252
253
    /**
254
     * @return mixed
255
     */
256
    public function getReceivedAt()
257
    {
258
        return $this->received_at;
259
    }
260
261
    /**
262
     * @param $received_at
263
     * @return $this
264
     */
265
    public function setReceivedAt($received_at)
266
    {
267
        $this->received_at = $received_at;
268
269
        return $this;
270
    }
271
272
    /**
273
     * @param $json
274
     * @return $this
275
     */
276
    public function mapperJson($json)
277
    {
278
        array_walk_recursive($json, function ($value, $key) {
279
            if (property_exists($this, $key)) {
280
                $this->$key = $value;
281
            }
282
        });
283
284
        $this->setResponseJSON($json);
285
286
        return $this;
287
    }
288
289
    /**
290
     * @return mixed
291
     */
292
    public function getResponseJSON()
293
    {
294
        return $this->responseJSON;
295
    }
296
297
    /**
298
     * @param $array
299
     * @return $this
300
     */
301
    public function setResponseJSON($array)
302
    {
303
        $this->responseJSON = json_encode($array, JSON_PRETTY_PRINT);
304
305
        return $this;
306
    }
307
}
308