Completed
Push — master ( 461ffe...a27db3 )
by João Felipe Magro
12:47
created

Order::isValidExpiryFormatDate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace Ipag\Classes;
4
5
use Ipag\Classes\Contracts\Emptiable;
6
use Ipag\Classes\Traits\EmptiableTrait;
7
8
final class Order extends BaseResource implements Emptiable
9
{
10
    use EmptiableTrait;
11
12
    /**
13
     * @var string
14
     */
15
    private $orderId;
16
17
    /**
18
     * @var string
19
     */
20
    private $operation;
21
22
    /**
23
     * @var string
24
     */
25
    private $callbackUrl;
26
27
    /**
28
     * @var float
29
     */
30
    private $amount;
31
32
    /**
33
     * @var int
34
     */
35
    private $installments;
36
37
    /**
38
     * @var string
39
     */
40
    private $expiry;
41
42
    /**
43
     * @var string
44
     */
45
    private $fingerprint;
46
47
    /**
48
     * @var Payment
49
     */
50
    private $payment;
51
52
    /**
53
     * @var Cart
54
     */
55
    private $cart;
56
57
    /**
58
     * @var Customer
59
     */
60
    private $customer;
61
62
    /**
63
     * @var Subscription
64
     */
65
    private $subscription;
66
67
    /**
68
     * @return string
69
     */
70
    public function getOrderId()
71
    {
72
        return $this->orderId;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getOperation()
79
    {
80
        return $this->operation;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getCallbackUrl()
87
    {
88
        return $this->callbackUrl;
89
    }
90
91
    /**
92
     * @return float
93
     */
94
    public function getAmount()
95
    {
96
        return $this->amount;
97
    }
98
99
    /**
100
     * @return int
101
     */
102
    public function getInstallments()
103
    {
104
        return $this->installments;
105
    }
106
107
    /**
108
     * @param string $orderId
109
     */
110
    public function setOrderId($orderId)
111
    {
112
        $this->orderId = substr((string) $orderId, 0, 20);
113
114
        return $this;
115
    }
116
117
    /**
118
     * @param string $operation
119
     */
120
    public function setOperation($operation)
121
    {
122
        $this->operation = $operation;
123
124
        return $this;
125
    }
126
127
    /**
128
     * @param string $callbackUrl
129
     */
130
    public function setCallbackUrl($callbackUrl)
131
    {
132
        $this->callbackUrl = substr((string) $callbackUrl, 0, 255);
133
134
        return $this;
135
    }
136
137
    /**
138
     * @param float $amount
139
     */
140
    public function setAmount($amount)
141
    {
142
        $this->amount = $this->getNumberUtil()->convertToDouble($amount);
143
144
        return $this;
145
    }
146
147
    /**
148
     * @param int $installments
149
     */
150
    public function setInstallments($installments)
151
    {
152
        $this->installments = $this->checkIfInstallmentsIsValidAndReturn($installments);
153
154
        return $this;
155
    }
156
157
    /**
158
     * @return string
159
     */
160
    public function getExpiry()
161
    {
162
        return $this->expiry;
163
    }
164
165
    /**
166
     * @param string $expiry
167
     */
168
    public function setExpiry($expiry)
169
    {
170
        if (!$this->getDateUtil()->isValid($expiry)) {
171
            throw new \UnexpectedValueException(
172
                'A data de vencimento não é valida ou está em formato incorreto, deve ser informada utilizando o formato dd/mm/aaaa'
173
            );
174
        }
175
        $this->expiry = $expiry;
176
177
        return $this;
178
    }
179
180
    /**
181
     * @return string
182
     */
183
    public function getFingerprint()
184
    {
185
        return $this->fingerprint;
186
    }
187
188
    /**
189
     * @param string $fingerprint
190
     */
191
    public function setFingerprint($fingerprint)
192
    {
193
        $this->fingerprint = substr((string) $fingerprint, 0, 120);
194
195
        return $this;
196
    }
197
198
    private function checkIfInstallmentsIsValidAndReturn($installments)
199
    {
200
        if (empty($installments) || $installments < 1) {
201
            $installments = 1;
202
        } elseif ($installments > 12) {
203
            throw new \UnexpectedValueException(
204
                'O parcelamento não pode ser maior que 12 (doze)'
205
            );
206
        }
207
208
        return (int) $installments;
209
    }
210
211
    /**
212
     * @return Payment
213
     */
214
    public function getPayment()
215
    {
216
        if (is_null($this->payment)) {
217
            $this->payment = new Payment();
218
        }
219
220
        return $this->payment;
221
    }
222
223
    /**
224
     * @param Payment $payment
225
     */
226
    public function setPayment(Payment $payment)
227
    {
228
        $this->payment = $payment;
229
230
        return $this;
231
    }
232
233
    /**
234
     * @return Cart
235
     */
236
    public function getCart()
237
    {
238
        if (is_null($this->cart)) {
239
            $this->cart = new Cart();
240
        }
241
242
        return $this->cart;
243
    }
244
245
    /**
246
     * @param Cart $cart
247
     */
248
    public function setCart(Cart $cart)
249
    {
250
        $this->cart = $cart;
251
252
        return $this;
253
    }
254
255
    /**
256
     * @return Customer
257
     */
258
    public function getCustomer()
259
    {
260
        if (is_null($this->customer)) {
261
            $this->customer = new Customer();
262
        }
263
264
        return $this->customer;
265
    }
266
267
    /**
268
     * @param Customer $customer
269
     */
270
    public function setCustomer(Customer $customer)
271
    {
272
        $this->customer = $customer;
273
274
        return $this;
275
    }
276
277
    /**
278
     * @return Subscription
279
     */
280
    public function getSubscription()
281
    {
282
        if (is_null($this->subscription)) {
283
            $this->subscription = new Subscription();
284
        }
285
286
        return $this->subscription;
287
    }
288
289
    /**
290
     * @param Subscription $subscription
291
     */
292
    public function setSubscription(Subscription $subscription)
293
    {
294
        $this->subscription = $subscription;
295
296
        return $this;
297
    }
298
}
299