Passed
Push — main ( c108e4...048889 )
by Iain
04:36
created

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