Passed
Push — main ( ce54f9...f825c1 )
by Iain
05:05
created

Subscription::setPayments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Iain Cambridge 2020-2023.
7
 *
8
 * Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
9
 *
10
 * Change Date: TBD ( 3 years after 2.2.0 release )
11
 *
12
 * On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
13
 */
14
15
namespace Parthenon\Billing\Entity;
16
17
use Brick\Money\Currency;
18
use Brick\Money\Money;
19
use Doctrine\Common\Collections\Collection;
20
use Parthenon\Billing\Enum\SubscriptionStatus;
21
22
class Subscription
23
{
24
    private $id;
25
26
    private CustomerInterface $customer;
27
28
    private string $planName;
29
30
    private string $paymentSchedule;
31
32
    private ?int $seats = 1;
33
34
    private bool $active;
35
36
    private SubscriptionStatus $status;
37
38
    private ?int $amount = null;
39
40
    private ?string $currency = null;
41
42
    private string $mainExternalReference;
43
44
    private ?string $mainExternalReferenceDetailsUrl = null;
45
46
    private string $childExternalReference;
47
48
    private ?PaymentDetails $paymentDetails = null;
49
50
    private ?SubscriptionPlan $subscriptionPlan = null;
51
52
    private ?Price $price = null;
53
54
    private \DateTimeInterface $createdAt;
55
56
    private ?\DateTimeInterface $startOfCurrentPeriod = null;
57
58
    private ?\DateTimeInterface $validUntil = null;
59
60
    private \DateTimeInterface $updatedAt;
61
62
    private ?\DateTimeInterface $endedAt = null;
63
64
    private bool $hasTrial = false;
65
66
    private ?int $trialLengthDays = 0;
67
68
    private Collection $payments;
69
70
    /**
71
     * @return mixed
72
     */
73
    public function getId()
74
    {
75
        return $this->id;
76
    }
77
78
    /**
79
     * @param mixed $id
80
     */
81
    public function setId($id): void
82
    {
83
        $this->id = $id;
84
    }
85
86
    public function getPlanName(): string
87
    {
88
        return $this->planName;
89
    }
90
91
    public function setPlanName(string $planName): void
92
    {
93
        $this->planName = $planName;
94
    }
95
96
    public function getPaymentSchedule(): string
97
    {
98
        return $this->paymentSchedule;
99
    }
100
101
    public function setPaymentSchedule(string $paymentSchedule): void
102
    {
103
        $this->paymentSchedule = $paymentSchedule;
104
    }
105
106
    public function getSeats(): ?int
107
    {
108
        return $this->seats;
109
    }
110
111
    public function setSeats(?int $seats): void
112
    {
113
        $this->seats = $seats;
114
    }
115
116
    public function getStatus(): SubscriptionStatus
117
    {
118
        return $this->status;
119
    }
120
121
    public function setStatus(SubscriptionStatus $status): void
122
    {
123
        if (SubscriptionStatus::CANCELLED === $status ||
124
            SubscriptionStatus::PAUSED === $status ||
125
            SubscriptionStatus::BLOCKED === $status ||
126
            SubscriptionStatus::OVERDUE_PAYMENT_DISABLED === $status) {
127
            $this->active = false;
128
        } else {
129
            $this->active = true;
130
        }
131
132
        $this->status = $status;
133
    }
134
135
    public function getSubscriptionPlan(): ?SubscriptionPlan
136
    {
137
        return $this->subscriptionPlan;
138
    }
139
140
    public function setSubscriptionPlan(?SubscriptionPlan $subscriptionPlan): void
141
    {
142
        $this->subscriptionPlan = $subscriptionPlan;
143
    }
144
145
    public function getMainExternalReference(): string
146
    {
147
        return $this->mainExternalReference;
148
    }
149
150
    public function setMainExternalReference(string $mainExternalReference): void
151
    {
152
        $this->mainExternalReference = $mainExternalReference;
153
    }
154
155
    public function getChildExternalReference(): string
156
    {
157
        return $this->childExternalReference;
158
    }
159
160
    public function setChildExternalReference(string $childExternalReference): void
161
    {
162
        $this->childExternalReference = $childExternalReference;
163
    }
164
165
    public function getAmount(): ?int
166
    {
167
        return $this->amount;
168
    }
169
170
    public function setAmount(?int $amount): void
171
    {
172
        $this->amount = $amount;
173
    }
174
175
    public function getCurrency(): ?string
176
    {
177
        return $this->currency;
178
    }
179
180
    public function setCurrency(?string $currency): void
181
    {
182
        $this->currency = $currency;
183
    }
184
185
    public function getPrice(): ?Price
186
    {
187
        return $this->price;
188
    }
189
190
    public function setPrice(?Price $price): void
191
    {
192
        $this->price = $price;
193
    }
194
195
    public function getCreatedAt(): \DateTimeInterface
196
    {
197
        return $this->createdAt;
198
    }
199
200
    public function setCreatedAt(\DateTimeInterface $createdAt): void
201
    {
202
        $this->createdAt = $createdAt;
203
    }
204
205
    public function getUpdatedAt(): \DateTimeInterface
206
    {
207
        return $this->updatedAt;
208
    }
209
210
    public function setUpdatedAt(\DateTimeInterface $updatedAt): void
211
    {
212
        $this->updatedAt = $updatedAt;
213
    }
214
215
    public function getEndedAt(): ?\DateTimeInterface
216
    {
217
        return $this->endedAt;
218
    }
219
220
    public function setEndedAt(?\DateTimeInterface $endedAt): void
221
    {
222
        $this->endedAt = $endedAt;
223
    }
224
225
    public function endAtEndOfPeriod(): void
226
    {
227
        $this->endedAt = clone $this->validUntil;
228
    }
229
230
    public function endNow(): void
231
    {
232
        $this->endedAt = new \DateTime('now');
233
        $this->validUntil = new \DateTime('now');
234
    }
235
236
    public function isActive(): bool
237
    {
238
        return $this->active;
239
    }
240
241
    public function setActive(bool $active): void
242
    {
243
        $this->active = $active;
244
    }
245
246
    public function getValidUntil(): \DateTimeInterface
247
    {
248
        return $this->validUntil;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->validUntil could return the type null which is incompatible with the type-hinted return DateTimeInterface. Consider adding an additional type-check to rule them out.
Loading history...
249
    }
250
251
    public function setValidUntil(\DateTimeInterface $validUntil): void
252
    {
253
        $this->validUntil = $validUntil;
254
    }
255
256
    public function getMoneyAmount(): Money
257
    {
258
        return Money::ofMinor($this->amount, Currency::of($this->currency));
259
    }
260
261
    public function setMoneyAmount(?Money $money)
262
    {
263
        if (!$money) {
264
            return;
265
        }
266
267
        $this->amount = $money->getMinorAmount()->toInt();
268
        $this->currency = $money->getCurrency()->getCurrencyCode();
269
    }
270
271
    public function getCustomer(): CustomerInterface
272
    {
273
        return $this->customer;
274
    }
275
276
    public function setCustomer(CustomerInterface $customer): void
277
    {
278
        $this->customer = $customer;
279
    }
280
281
    public function getMainExternalReferenceDetailsUrl(): ?string
282
    {
283
        return $this->mainExternalReferenceDetailsUrl;
284
    }
285
286
    public function setMainExternalReferenceDetailsUrl(?string $mainExternalReferenceDetailsUrl): void
287
    {
288
        $this->mainExternalReferenceDetailsUrl = $mainExternalReferenceDetailsUrl;
289
    }
290
291
    public function getStartOfCurrentPeriod(): ?\DateTimeInterface
292
    {
293
        return $this->startOfCurrentPeriod;
294
    }
295
296
    public function setStartOfCurrentPeriod(?\DateTimeInterface $startOfCurrentPeriod): void
297
    {
298
        $this->startOfCurrentPeriod = $startOfCurrentPeriod;
299
    }
300
301
    public function isHasTrial(): bool
302
    {
303
        return $this->hasTrial;
304
    }
305
306
    public function setHasTrial(bool $hasTrial): void
307
    {
308
        $this->hasTrial = $hasTrial;
309
    }
310
311
    public function getTrialLengthDays(): ?int
312
    {
313
        return $this->trialLengthDays;
314
    }
315
316
    public function setTrialLengthDays(?int $trialLengthDays): void
317
    {
318
        $this->trialLengthDays = $trialLengthDays;
319
    }
320
321
    public function getPaymentDetails(): ?PaymentDetails
322
    {
323
        return $this->paymentDetails;
324
    }
325
326
    public function setPaymentDetails(?PaymentDetails $paymentDetails): void
327
    {
328
        $this->paymentDetails = $paymentDetails;
329
    }
330
331
    public function getPayments(): Collection
332
    {
333
        return $this->payments;
334
    }
335
336
    public function setPayments(Collection $payments): void
337
    {
338
        $this->payments = $payments;
339
    }
340
}
341