Passed
Push — main ( c81eb8...7d97d9 )
by Iain
04:22
created

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