|
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\Billing\Entity; |
|
23
|
|
|
|
|
24
|
|
|
use Brick\Money\Currency; |
|
25
|
|
|
use Brick\Money\Money; |
|
26
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
27
|
|
|
use Doctrine\Common\Collections\Collection; |
|
28
|
|
|
use Parthenon\Billing\Enum\PaymentStatus; |
|
29
|
|
|
|
|
30
|
|
|
class Payment implements PaymentInterface |
|
31
|
|
|
{ |
|
32
|
|
|
private $id; |
|
33
|
|
|
|
|
34
|
|
|
private string $paymentReference; |
|
35
|
|
|
|
|
36
|
|
|
private string $provider; |
|
37
|
|
|
|
|
38
|
|
|
private PaymentStatus $status; |
|
39
|
|
|
|
|
40
|
|
|
private int $amount; |
|
41
|
|
|
|
|
42
|
|
|
private string $currency; |
|
43
|
|
|
|
|
44
|
|
|
private ?string $description = null; |
|
45
|
|
|
|
|
46
|
|
|
private ?CustomerInterface $customer = null; |
|
47
|
|
|
|
|
48
|
|
|
private \DateTimeInterface $createdAt; |
|
49
|
|
|
|
|
50
|
|
|
private \DateTimeInterface $updatedAt; |
|
51
|
|
|
|
|
52
|
|
|
private bool $refunded = false; |
|
53
|
|
|
|
|
54
|
|
|
private bool $completed = false; |
|
55
|
|
|
|
|
56
|
|
|
private bool $chargedBack = false; |
|
57
|
|
|
|
|
58
|
|
|
private Collection $subscriptions; |
|
59
|
|
|
|
|
60
|
|
|
private ?string $paymentProviderDetailsUrl; |
|
61
|
|
|
|
|
62
|
|
|
public function __construct() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->subscriptions = new ArrayCollection(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getId() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->id; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function setId($id): void |
|
73
|
|
|
{ |
|
74
|
|
|
$this->id = $id; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getPaymentReference(): string |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->paymentReference; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function setPaymentReference(string $paymentReference): void |
|
83
|
|
|
{ |
|
84
|
|
|
$this->paymentReference = $paymentReference; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function getProvider(): string |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->provider; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function setProvider(string $provider): void |
|
93
|
|
|
{ |
|
94
|
|
|
$this->provider = $provider; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function getAmount(): int |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->amount; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function setAmount(int $amount): void |
|
103
|
|
|
{ |
|
104
|
|
|
$this->amount = $amount; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function getCurrency(): string |
|
108
|
|
|
{ |
|
109
|
|
|
return strtoupper($this->currency); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function setCurrency(string $currency): void |
|
113
|
|
|
{ |
|
114
|
|
|
$this->currency = strtoupper($currency); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function getCreatedAt(): \DateTimeInterface |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->createdAt; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function setCreatedAt(\DateTimeInterface $createdAt): void |
|
123
|
|
|
{ |
|
124
|
|
|
$this->createdAt = $createdAt; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function isRefunded(): bool |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->refunded; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function setRefunded(bool $refunded): void |
|
133
|
|
|
{ |
|
134
|
|
|
$this->refunded = $refunded; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function isCompleted(): bool |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->completed; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function setCompleted(bool $completed): void |
|
143
|
|
|
{ |
|
144
|
|
|
$this->completed = $completed; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function isChargedBack(): bool |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->chargedBack; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function setChargedBack(bool $chargedBack): void |
|
153
|
|
|
{ |
|
154
|
|
|
$this->chargedBack = $chargedBack; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
public function getUpdatedAt(): \DateTimeInterface |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->updatedAt; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public function setUpdatedAt(\DateTimeInterface $updatedAt): void |
|
163
|
|
|
{ |
|
164
|
|
|
$this->updatedAt = $updatedAt; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
public function getCustomer(): ?CustomerInterface |
|
168
|
|
|
{ |
|
169
|
|
|
return $this->customer; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
public function setCustomer(CustomerInterface $customer): void |
|
173
|
|
|
{ |
|
174
|
|
|
$this->customer = $customer; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function hasCustomer(): bool |
|
178
|
|
|
{ |
|
179
|
|
|
return isset($this->customer); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
public function getMoneyAmount(): Money |
|
183
|
|
|
{ |
|
184
|
|
|
return Money::ofMinor($this->amount, Currency::of($this->getCurrency())); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function setMoneyAmount(Money $money) |
|
188
|
|
|
{ |
|
189
|
|
|
$this->amount = $money->getMinorAmount()->toInt(); |
|
190
|
|
|
$this->currency = $money->getCurrency()->getCurrencyCode(); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
public function getSubscription(): ?Subscription |
|
194
|
|
|
{ |
|
195
|
|
|
return $this->subscription; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
public function setSubscription(?Subscription $subscription): void |
|
199
|
|
|
{ |
|
200
|
|
|
$this->subscription = $subscription; |
|
|
|
|
|
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public function getPaymentProviderDetailsUrl(): ?string |
|
204
|
|
|
{ |
|
205
|
|
|
return $this->paymentProviderDetailsUrl; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
public function setPaymentProviderDetailsUrl(?string $paymentProviderDetailsUrl): void |
|
209
|
|
|
{ |
|
210
|
|
|
$this->paymentProviderDetailsUrl = $paymentProviderDetailsUrl; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
public function getSubscriptions(): Collection |
|
214
|
|
|
{ |
|
215
|
|
|
return $this->subscriptions; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
public function setSubscriptions(Collection|array $subscriptions): void |
|
219
|
|
|
{ |
|
220
|
|
|
$this->subscriptions = $subscriptions; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
public function addSubscription(Subscription $subscription): void |
|
224
|
|
|
{ |
|
225
|
|
|
if ($this->subscriptions instanceof Collection && !$this->subscriptions->contains($subscription)) { |
|
226
|
|
|
$this->subscriptions->add($subscription); |
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
public function getStatus(): PaymentStatus |
|
231
|
|
|
{ |
|
232
|
|
|
return $this->status; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
public function setStatus(PaymentStatus $status): void |
|
236
|
|
|
{ |
|
237
|
|
|
if (PaymentStatus::PARTIALLY_REFUNDED === $status || PaymentStatus::FULLY_REFUNDED === $status) { |
|
238
|
|
|
$this->refunded = true; |
|
239
|
|
|
} elseif (PaymentStatus::DISPUTED === $status) { |
|
240
|
|
|
$this->chargedBack = true; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
$this->status = $status; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
public function getDescription(): ?string |
|
247
|
|
|
{ |
|
248
|
|
|
return $this->description; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
public function setDescription(string $description): void |
|
252
|
|
|
{ |
|
253
|
|
|
$this->description = $description; |
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
|