Passed
Push — main ( 4932ce...ee2dfa )
by Iain
04:38
created

Subscription::setPaymentExternalReference()   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
20
class Subscription
21
{
22
    private $id;
23
24
    private CustomerInterface $customer;
25
26
    private string $planName;
27
28
    private string $paymentSchedule;
29
30
    private ?int $seats = 1;
31
32
    private bool $active;
33
34
    private string $status;
35
36
    private ?int $amount = null;
37
38
    private ?string $currency = null;
39
40
    private string $mainExternalReference;
41
42
    private ?string $mainExternalReferenceDetailsUrl = null;
43
44
    private string $childExternalReference;
45
46
    private ?PaymentDetails $paymentDetails = null;
47
48
    private ?SubscriptionPlan $subscriptionPlan = null;
49
50
    private ?Price $price = null;
51
52
    private \DateTimeInterface $createdAt;
53
54
    private ?\DateTimeInterface $startOfCurrentPeriod = null;
55
56
    private ?\DateTimeInterface $validUntil = null;
57
58
    private \DateTimeInterface $updatedAt;
59
60
    private ?\DateTimeInterface $endedAt = null;
61
62
    private bool $hasTrial = false;
63
64
    private ?int $trialLengthDays = 0;
65
66
    /**
67
     * @return mixed
68
     */
69
    public function getId()
70
    {
71
        return $this->id;
72
    }
73
74
    /**
75
     * @param mixed $id
76
     */
77
    public function setId($id): void
78
    {
79
        $this->id = $id;
80
    }
81
82
    public function getPlanName(): string
83
    {
84
        return $this->planName;
85
    }
86
87
    public function setPlanName(string $planName): void
88
    {
89
        $this->planName = $planName;
90
    }
91
92
    public function getPaymentSchedule(): string
93
    {
94
        return $this->paymentSchedule;
95
    }
96
97
    public function setPaymentSchedule(string $paymentSchedule): void
98
    {
99
        $this->paymentSchedule = $paymentSchedule;
100
    }
101
102
    public function getSeats(): ?int
103
    {
104
        return $this->seats;
105
    }
106
107
    public function setSeats(?int $seats): void
108
    {
109
        $this->seats = $seats;
110
    }
111
112
    public function getStatus(): string
113
    {
114
        return $this->status;
115
    }
116
117
    public function setStatus(string $status): void
118
    {
119
        $this->status = $status;
120
    }
121
122
    public function getSubscriptionPlan(): ?SubscriptionPlan
123
    {
124
        return $this->subscriptionPlan;
125
    }
126
127
    public function setSubscriptionPlan(?SubscriptionPlan $subscriptionPlan): void
128
    {
129
        $this->subscriptionPlan = $subscriptionPlan;
130
    }
131
132
    public function getMainExternalReference(): string
133
    {
134
        return $this->mainExternalReference;
135
    }
136
137
    public function setMainExternalReference(string $mainExternalReference): void
138
    {
139
        $this->mainExternalReference = $mainExternalReference;
140
    }
141
142
    public function getChildExternalReference(): string
143
    {
144
        return $this->childExternalReference;
145
    }
146
147
    public function setChildExternalReference(string $childExternalReference): void
148
    {
149
        $this->childExternalReference = $childExternalReference;
150
    }
151
152
    public function getAmount(): ?int
153
    {
154
        return $this->amount;
155
    }
156
157
    public function setAmount(?int $amount): void
158
    {
159
        $this->amount = $amount;
160
    }
161
162
    public function getCurrency(): ?string
163
    {
164
        return $this->currency;
165
    }
166
167
    public function setCurrency(?string $currency): void
168
    {
169
        $this->currency = $currency;
170
    }
171
172
    public function getPrice(): ?Price
173
    {
174
        return $this->price;
175
    }
176
177
    public function setPrice(?Price $price): void
178
    {
179
        $this->price = $price;
180
    }
181
182
    public function getCreatedAt(): \DateTimeInterface
183
    {
184
        return $this->createdAt;
185
    }
186
187
    public function setCreatedAt(\DateTimeInterface $createdAt): void
188
    {
189
        $this->createdAt = $createdAt;
190
    }
191
192
    public function getUpdatedAt(): \DateTimeInterface
193
    {
194
        return $this->updatedAt;
195
    }
196
197
    public function setUpdatedAt(\DateTimeInterface $updatedAt): void
198
    {
199
        $this->updatedAt = $updatedAt;
200
    }
201
202
    public function getEndedAt(): ?\DateTimeInterface
203
    {
204
        return $this->endedAt;
205
    }
206
207
    public function setEndedAt(?\DateTimeInterface $endedAt): void
208
    {
209
        $this->endedAt = $endedAt;
210
    }
211
212
    public function endAtEndOfPeriod(): void
213
    {
214
        $this->endedAt = clone $this->validUntil;
215
    }
216
217
    public function endNow(): void
218
    {
219
        $this->endedAt = new \DateTime('now');
220
        $this->validUntil = new \DateTime('now');
221
    }
222
223
    public function isActive(): bool
224
    {
225
        return $this->active;
226
    }
227
228
    public function setActive(bool $active): void
229
    {
230
        $this->active = $active;
231
    }
232
233
    public function getValidUntil(): \DateTimeInterface
234
    {
235
        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...
236
    }
237
238
    public function setValidUntil(\DateTimeInterface $validUntil): void
239
    {
240
        $this->validUntil = $validUntil;
241
    }
242
243
    public function getMoneyAmount(): Money
244
    {
245
        return Money::ofMinor($this->amount, Currency::of($this->currency));
246
    }
247
248
    public function setMoneyAmount(?Money $money)
249
    {
250
        if (!$money) {
251
            return;
252
        }
253
254
        $this->amount = $money->getMinorAmount()->toInt();
255
        $this->currency = $money->getCurrency()->getCurrencyCode();
256
    }
257
258
    public function getCustomer(): CustomerInterface
259
    {
260
        return $this->customer;
261
    }
262
263
    public function setCustomer(CustomerInterface $customer): void
264
    {
265
        $this->customer = $customer;
266
    }
267
268
    public function getMainExternalReferenceDetailsUrl(): ?string
269
    {
270
        return $this->mainExternalReferenceDetailsUrl;
271
    }
272
273
    public function setMainExternalReferenceDetailsUrl(?string $mainExternalReferenceDetailsUrl): void
274
    {
275
        $this->mainExternalReferenceDetailsUrl = $mainExternalReferenceDetailsUrl;
276
    }
277
278
    public function getStartOfCurrentPeriod(): ?\DateTimeInterface
279
    {
280
        return $this->startOfCurrentPeriod;
281
    }
282
283
    public function setStartOfCurrentPeriod(?\DateTimeInterface $startOfCurrentPeriod): void
284
    {
285
        $this->startOfCurrentPeriod = $startOfCurrentPeriod;
286
    }
287
288
    public function isHasTrial(): bool
289
    {
290
        return $this->hasTrial;
291
    }
292
293
    public function setHasTrial(bool $hasTrial): void
294
    {
295
        $this->hasTrial = $hasTrial;
296
    }
297
298
    public function getTrialLengthDays(): ?int
299
    {
300
        return $this->trialLengthDays;
301
    }
302
303
    public function setTrialLengthDays(?int $trialLengthDays): void
304
    {
305
        $this->trialLengthDays = $trialLengthDays;
306
    }
307
308
    public function getPaymentDetails(): ?PaymentDetails
309
    {
310
        return $this->paymentDetails;
311
    }
312
313
    public function setPaymentDetails(?PaymentDetails $paymentDetails): void
314
    {
315
        $this->paymentDetails = $paymentDetails;
316
    }
317
}
318