|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* Copyright (C) 2020-2025 Iain Cambridge |
|
7
|
|
|
* |
|
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by |
|
10
|
|
|
* the Free Software Foundation, either version 2.1 of the License, or |
|
11
|
|
|
* (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU Lesser General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU General Public License |
|
19
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace Parthenon\Payments\Entity; |
|
23
|
|
|
|
|
24
|
|
|
use Parthenon\Payments\SubscriptionInterface; |
|
25
|
|
|
|
|
26
|
|
|
class Subscription implements SubscriptionInterface |
|
27
|
|
|
{ |
|
28
|
|
|
public const STATUS_UNKNOWN = 'unknown'; |
|
29
|
|
|
public const STATUS_PENDING = 'pending'; |
|
30
|
|
|
public const STATUS_TRIAL = 'trial'; |
|
31
|
|
|
public const STATUS_ACTIVE = 'active'; |
|
32
|
|
|
public const STATUS_CANCELLED = 'cancelled'; |
|
33
|
|
|
public const STATUS_OVERDUE = 'overdue'; |
|
34
|
|
|
public const STATUS_ARRAY = [ |
|
35
|
|
|
self::STATUS_UNKNOWN, |
|
36
|
|
|
self::STATUS_PENDING, |
|
37
|
|
|
self::STATUS_TRIAL, |
|
38
|
|
|
self::STATUS_ACTIVE, |
|
39
|
|
|
self::STATUS_CANCELLED, |
|
40
|
|
|
self::STATUS_OVERDUE, |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
public const PAYMENT_SCHEDULE_MONTHLY = 'monthly'; |
|
44
|
|
|
public const PAYMENT_SCHEDULE_YEARLY = 'yearly'; |
|
45
|
|
|
public const PAYMENT_SCHEDULE_LIFETIME = 'lifetime'; |
|
46
|
|
|
|
|
47
|
|
|
private ?string $priceId; |
|
48
|
|
|
|
|
49
|
|
|
private ?string $planName = ''; |
|
50
|
|
|
|
|
51
|
|
|
private ?string $paymentSchedule; |
|
52
|
|
|
|
|
53
|
|
|
private ?bool $active; |
|
54
|
|
|
|
|
55
|
|
|
private ?string $customerId = null; |
|
56
|
|
|
|
|
57
|
|
|
private ?string $status = self::STATUS_UNKNOWN; |
|
58
|
|
|
|
|
59
|
|
|
private ?\DateTimeInterface $startedAt; |
|
60
|
|
|
|
|
61
|
|
|
private ?\DateTimeInterface $validUntil; |
|
62
|
|
|
|
|
63
|
|
|
private ?\DateTimeInterface $endedAt; |
|
64
|
|
|
|
|
65
|
|
|
private ?\DateTimeInterface $updatedAt; |
|
66
|
|
|
|
|
67
|
|
|
private ?string $paymentId; |
|
68
|
|
|
|
|
69
|
|
|
private ?string $checkoutId; |
|
70
|
|
|
|
|
71
|
|
|
private ?int $seats; |
|
72
|
|
|
|
|
73
|
|
|
public function getPriceId(): ?string |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->priceId; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function setPriceId(string $priceId): void |
|
79
|
|
|
{ |
|
80
|
|
|
$this->priceId = $priceId; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function getPlanName(): ?string |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->planName; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function setPlanName(string $planName): void |
|
89
|
|
|
{ |
|
90
|
|
|
$this->planName = $planName; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function getPaymentSchedule(): ?string |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->paymentSchedule; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function setPaymentSchedule(string $paymentSchedule): void |
|
99
|
|
|
{ |
|
100
|
|
|
$this->paymentSchedule = $paymentSchedule; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function isActive(): bool |
|
104
|
|
|
{ |
|
105
|
|
|
if (self::PAYMENT_SCHEDULE_LIFETIME === $this->paymentSchedule) { |
|
106
|
|
|
return true === $this->active; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
$now = new \DateTime(); |
|
110
|
|
|
|
|
111
|
|
|
return true === $this->active && $this->validUntil > $now; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function setActive(bool $active): void |
|
115
|
|
|
{ |
|
116
|
|
|
$this->active = $active; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function getStatus(): ?string |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->status; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function setStatus(string $status): void |
|
125
|
|
|
{ |
|
126
|
|
|
$this->status = $status; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function getStartedAt(): ?\DateTimeInterface |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->startedAt; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function setStartedAt(\DateTimeInterface $startedAt): void |
|
135
|
|
|
{ |
|
136
|
|
|
$this->startedAt = $startedAt; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function getValidUntil(): ?\DateTimeInterface |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->validUntil; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function setValidUntil(?\DateTimeInterface $validUntil): void |
|
145
|
|
|
{ |
|
146
|
|
|
$this->validUntil = $validUntil; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function getEndedAt(): ?\DateTimeInterface |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->endedAt; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function setEndedAt(?\DateTimeInterface $endedAt): void |
|
155
|
|
|
{ |
|
156
|
|
|
$this->endedAt = $endedAt; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function getPaymentId(): ?string |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->paymentId; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
public function setPaymentId(string $paymentId): void |
|
165
|
|
|
{ |
|
166
|
|
|
$this->paymentId = $paymentId; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
public function getCheckoutId(): ?string |
|
170
|
|
|
{ |
|
171
|
|
|
return $this->checkoutId; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
public function setCheckoutId(string $checkoutId): void |
|
175
|
|
|
{ |
|
176
|
|
|
$this->checkoutId = $checkoutId; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
public function getUpdatedAt(): ?\DateTimeInterface |
|
180
|
|
|
{ |
|
181
|
|
|
return $this->updatedAt; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
public function setUpdatedAt(?\DateTimeInterface $updatedAt): void |
|
185
|
|
|
{ |
|
186
|
|
|
$this->updatedAt = $updatedAt; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
public function increaseValidUntil() |
|
190
|
|
|
{ |
|
191
|
|
|
if (self::PAYMENT_SCHEDULE_YEARLY === $this->paymentSchedule) { |
|
192
|
|
|
$this->validUntil = new \DateTime('+1 Year'); |
|
193
|
|
|
} elseif (self::PAYMENT_SCHEDULE_MONTHLY === $this->paymentSchedule) { |
|
194
|
|
|
$this->validUntil = new \DateTime('+1 month'); |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
public function getSeats(): ?int |
|
199
|
|
|
{ |
|
200
|
|
|
return $this->seats; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public function setSeats(int $seats): void |
|
204
|
|
|
{ |
|
205
|
|
|
$this->seats = $seats; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
public function getCustomerId(): ?string |
|
209
|
|
|
{ |
|
210
|
|
|
return $this->customerId; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
public function setCustomerId(?string $customerId): void |
|
214
|
|
|
{ |
|
215
|
|
|
$this->customerId = $customerId; |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|