Transaction::debit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Getnet\API;
4
5
/**
6
 * Class Transaction
7
 *
8
 * @package Getnet\API
9
 */
10
class Transaction
11
{
12
    const STATUS_AUTHORIZED = "AUTHORIZED";
13
    const STATUS_CONFIRMED  = "CONFIRMED";
14
    const STATUS_PENDING    = "PENDING";
15
    const STATUS_APPROVED   = "APPROVED";
16
    const STATUS_CANCELED   = "CANCELED";
17
    const STATUS_DENIED     = "DENIED";
18
    const STATUS_ERROR      = "ERROR";
19
20
    /** @var */
21
    private $seller_id;
22
23
    /** @var */
24
    private $amount;
25
26
    /** @var string */
27
    private $currency = "BRL";
28
29
    /** @var */
30
    private $order;
31
32
    /** @var */
33
    private $customer;
34
35
    /** @var */
36
    private $device;
37
38
    /** @var */
39
    private $shippings;
40
41
    /** @var */
42
    private $credit;
43
44
    /** @var */
45
    private $debit;
46
47
    /** @var */
48
    private $boleto;
49
50
    /**
51
     * @return false|string
52
     */
53 View Code Duplication
    public function toJSON()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $vars = get_object_vars($this);
56
        $vars_clear = array_filter($vars, function ($value) {
57
            return null !== $value;
58
        });
59
60
        return json_encode($vars_clear, JSON_PRETTY_PRINT);
61
    }
62
63
    /**
64
     * @return mixed
65
     */
66
    public function getSellerId()
67
    {
68
        return $this->seller_id;
69
    }
70
71
    /**
72
     * @param $seller_id
73
     * @return $this
74
     */
75
    public function setSellerId($seller_id)
76
    {
77
        $this->seller_id = (string)$seller_id;
78
79
        return $this;
80
    }
81
82
    /**
83
     * @return mixed
84
     */
85
    public function getAmount()
86
    {
87
        return $this->amount;
88
    }
89
90
    /**
91
     * @param $amount
92
     * @return $this
93
     */
94
    public function setAmount($amount)
95
    {
96
        $this->amount = (int)($amount * 100);
97
98
        return $this;
99
    }
100
101
    /**
102
     * @return string
103
     */
104
    public function getCurrency()
105
    {
106
        return $this->currency;
107
    }
108
109
    /**
110
     * @param $currency
111
     * @return $this
112
     */
113
    public function setCurrency($currency)
114
    {
115
        $this->currency = (string)$currency;
116
117
        return $this;
118
    }
119
120
    /**
121
     * @param $order_id
122
     * @return Order
123
     */
124
    public function order($order_id)
125
    {
126
        $order = new Order($order_id);
127
        $this->setOrder($order);
128
129
        return $order;
130
    }
131
132
    /**
133
     * @return Order
134
     */
135
    public function getOrder()
136
    {
137
        return $this->order;
138
    }
139
140
    /**
141
     * @param Order $order
142
     * @return $this
143
     */
144
    public function setOrder(Order $order)
145
    {
146
        $this->order = $order;
147
148
        return $this;
149
    }
150
151
    /**
152
     * @param null $id
153
     * @return Customer
154
     */
155
    public function customer($id = null)
156
    {
157
        $customer = new Customer($id);
158
159
        $this->setCustomer($customer);
160
161
        return $customer;
162
    }
163
164
    /**
165
     * @return mixed
166
     */
167
    public function getCustomer()
168
    {
169
        return $this->customer;
170
    }
171
172
    /**
173
     * @param Customer $customer
174
     * @return $this
175
     */
176
    public function setCustomer(Customer $customer)
177
    {
178
        $this->customer = $customer;
179
180
        return $this;
181
    }
182
183
    /**
184
     * @param $device_id
185
     * @return Device
186
     */
187
    public function device($device_id)
188
    {
189
        $device = new Device($device_id);
190
191
        $this->device = $device;
192
193
        return $device;
194
    }
195
196
    /**
197
     * @return Device
198
     */
199
    public function getDevice()
200
    {
201
        return $this->device;
202
    }
203
204
    /**
205
     * @param Device $device
206
     * @return $this
207
     */
208
    public function setDevice(Device $device)
209
    {
210
        $this->device = $device;
211
212
        return $this;
213
    }
214
215
    /**
216
     * @return mixed
217
     */
218
    public function getShippings()
219
    {
220
        return $this->shippings;
221
    }
222
223
    /**
224
     * @param $shippings
225
     * @return $this
226
     */
227
    public function setShippings($shippings)
228
    {
229
        $this->shippings = $shippings;
230
231
        return $this;
232
    }
233
234
    /**
235
     * @return Shipping
236
     */
237
    public function shipping()
238
    {
239
        $shipping = new Shipping();
240
241
        $this->addShipping($shipping);
242
243
        return $shipping;
244
    }
245
246
    /**
247
     * @param Shipping $shipping
248
     */
249
    public function addShipping(Shipping $shipping)
250
    {
251
        if (!is_array($this->shippings)) {
252
            $this->shippings = [];
253
        }
254
255
        $this->shippings[] = $shipping;
256
    }
257
258
    /**
259
     * @param Customer $customer
260
     * @return Shipping
261
     */
262
    public function addShippingByCustomer(Customer $customer)
263
    {
264
        $shipping = new Shipping();
265
266
        $this->addShipping($shipping->populateByCustomer($customer));
267
268
        return $shipping;
269
    }
270
271
    /**
272
     * @param null $brand
273
     * @return Credit
274
     */
275
    public function credit($brand = null)
276
    {
277
        $credit = new Credit($brand);
278
        $this->setCredit($credit);
279
280
        return $credit;
281
    }
282
283
    /**
284
     * @return Credit
285
     */
286
    public function getCredit()
287
    {
288
        return $this->credit;
289
    }
290
291
    /**
292
     * @param Credit $credit
293
     * @return $this
294
     */
295
    public function setCredit(Credit $credit)
296
    {
297
        $this->credit = $credit;
298
299
        return $this;
300
    }
301
302
    /**
303
     * @param null $brand
304
     * @return Credit
305
     */
306
    public function debit($brand = null)
307
    {
308
        $debit = new Credit($brand);
309
310
        $this->setDebit($debit);
311
312
        return $debit;
313
    }
314
315
    /**
316
     * @return mixed
317
     */
318
    public function getDebit()
319
    {
320
        return $this->debit;
321
    }
322
323
    /**
324
     * @param Credit $debit
325
     * @return $this
326
     */
327
    public function setDebit(Credit $debit)
328
    {
329
        $this->debit = $debit;
330
331
        return $this;
332
    }
333
334
    /**
335
     * @param $our_number
336
     * @return Boleto
337
     */
338
    public function boleto($our_number)
339
    {
340
        $boleto = new Boleto($our_number);
341
        $this->boleto = $boleto;
342
343
        return $boleto;
344
    }
345
346
    /**
347
     * @return mixed
348
     */
349
    public function getBoleto()
350
    {
351
        return $this->boleto;
352
    }
353
354
    /**
355
     * @param Boleto $boleto
356
     * @return $this
357
     */
358
    public function setBoleto(Boleto $boleto)
359
    {
360
        $this->boleto = $boleto;
361
362
        return $this;
363
    }
364
}
365