Passed
Push — main ( 70ec62...0d1c63 )
by Iain
05:04
created

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