|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// --------------------------------------------------------------------- |
|
4
|
|
|
// |
|
5
|
|
|
// Copyright (C) 2018-2024 Artem Rodygin |
|
6
|
|
|
// |
|
7
|
|
|
// You should have received a copy of the MIT License along with |
|
8
|
|
|
// this file. If not, see <https://opensource.org/licenses/MIT>. |
|
9
|
|
|
// |
|
10
|
|
|
// --------------------------------------------------------------------- |
|
11
|
|
|
|
|
12
|
|
|
namespace Linode\Account; |
|
13
|
|
|
|
|
14
|
|
|
use Linode\Account\Repository\EventRepository; |
|
15
|
|
|
use Linode\Account\Repository\InvoiceRepository; |
|
16
|
|
|
use Linode\Account\Repository\NotificationRepository; |
|
17
|
|
|
use Linode\Account\Repository\OAuthClientRepository; |
|
18
|
|
|
use Linode\Account\Repository\PaymentRepository; |
|
19
|
|
|
use Linode\Account\Repository\UserRepository; |
|
20
|
|
|
use Linode\Entity; |
|
21
|
|
|
use Linode\Exception\LinodeException; |
|
22
|
|
|
use Linode\LinodeClient; |
|
23
|
|
|
use Linode\Managed\StatsDataAvailable; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Account object. |
|
27
|
|
|
* |
|
28
|
|
|
* @property string $first_name The first name of the person associated with this Account. |
|
29
|
|
|
* @property string $last_name The last name of the person associated with this Account. |
|
30
|
|
|
* @property string $email The email address of the person associated with this Account. |
|
31
|
|
|
* @property float $balance This Account's balance, in US dollars. |
|
32
|
|
|
* @property float $balance_uninvoiced This Account's current estimated invoice in US dollars. This is not your final |
|
33
|
|
|
* invoice balance. Bandwidth charges are not included in the estimate. |
|
34
|
|
|
* @property string $company The company name associated with this Account. |
|
35
|
|
|
* @property string $address_1 First line of this Account's billing address. |
|
36
|
|
|
* @property string $address_2 Second line of this Account's billing address. |
|
37
|
|
|
* @property string $city The city for this Account's billing address. |
|
38
|
|
|
* @property string $state If billing address is in the United States, this is the State portion of the |
|
39
|
|
|
* Account's billing address. If the address is outside the US, this is the Province |
|
40
|
|
|
* associated with the Account's billing address. |
|
41
|
|
|
* @property string $zip The zip code of this Account's billing address. |
|
42
|
|
|
* @property string $country The two-letter country code of this Account's billing address. |
|
43
|
|
|
* @property string $phone The phone number associated with this Account. |
|
44
|
|
|
* @property string $tax_id The tax identification number associated with this Account, for tax calculations |
|
45
|
|
|
* in some countries. If you do not live in a country that collects tax, this should |
|
46
|
|
|
* be `null`. |
|
47
|
|
|
* @property CreditCard $credit_card Credit Card information associated with this Account. |
|
48
|
|
|
* @property string $active_since The datetime of when the account was activated. |
|
49
|
|
|
* @property string[] $capabilities A list of capabilities your account supports. |
|
50
|
|
|
* @property Promotion[] $active_promotions A list of active promotions on your account. Promotions generally |
|
51
|
|
|
* offer a set amount of credit that can be used toward your Linode |
|
52
|
|
|
* services, and the promotion expires after a specified date. As well, |
|
53
|
|
|
* a monthly cap on the promotional offer is set. |
|
54
|
|
|
* Simply put, a promotion offers a certain amount of credit every |
|
55
|
|
|
* month, until either the expiration date is passed, or until the total |
|
56
|
|
|
* promotional credit is used, whichever comes first. |
|
57
|
|
|
* @property EventRepositoryInterface $events List of Event objects representing actions taken on your Account. The Events |
|
58
|
|
|
* returned depends on your grants. |
|
59
|
|
|
* @property InvoiceRepositoryInterface $invoices List of Invoices against your Account. |
|
60
|
|
|
* @property NotificationRepositoryInterface $notifications List of Notification objects representing important, often time-sensitive items |
|
61
|
|
|
* related to your Account. |
|
62
|
|
|
* @property OAuthClientRepositoryInterface $oauth_clients List of OAuth Clients registered to your Account. OAuth Clients allow users to log |
|
63
|
|
|
* into applications you write or host using their Linode Account, and may allow them |
|
64
|
|
|
* to grant some level of access to their Linodes or other entities to your |
|
65
|
|
|
* application. |
|
66
|
|
|
* @property PaymentRepositoryInterface $payments List of Payments made on this Account. |
|
67
|
|
|
* @property UserRepositoryInterface $users List of Users on your Account. Users may access all or part of your Account based |
|
68
|
|
|
* on their restricted status and grants. An unrestricted User may access everything |
|
69
|
|
|
* on the account, whereas restricted User may only access entities or perform |
|
70
|
|
|
* actions they've been given specific grants to. |
|
71
|
|
|
* |
|
72
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
|
73
|
|
|
*/ |
|
74
|
|
|
class Account extends Entity |
|
75
|
|
|
{ |
|
76
|
|
|
// Available fields. |
|
77
|
|
|
public const FIELD_FIRST_NAME = 'first_name'; |
|
78
|
|
|
public const FIELD_LAST_NAME = 'last_name'; |
|
79
|
|
|
public const FIELD_EMAIL = 'email'; |
|
80
|
|
|
public const FIELD_BALANCE = 'balance'; |
|
81
|
|
|
public const FIELD_BALANCE_UNINVOICED = 'balance_uninvoiced'; |
|
82
|
|
|
public const FIELD_COMPANY = 'company'; |
|
83
|
|
|
public const FIELD_ADDRESS_1 = 'address_1'; |
|
84
|
|
|
public const FIELD_ADDRESS_2 = 'address_2'; |
|
85
|
|
|
public const FIELD_CITY = 'city'; |
|
86
|
|
|
public const FIELD_STATE = 'state'; |
|
87
|
|
|
public const FIELD_ZIP = 'zip'; |
|
88
|
|
|
public const FIELD_COUNTRY = 'country'; |
|
89
|
|
|
public const FIELD_PHONE = 'phone'; |
|
90
|
|
|
public const FIELD_TAX_ID = 'tax_id'; |
|
91
|
|
|
public const FIELD_CREDIT_CARD = 'credit_card'; |
|
92
|
|
|
public const FIELD_ACTIVE_SINCE = 'active_since'; |
|
93
|
|
|
public const FIELD_CAPABILITIES = 'capabilities'; |
|
94
|
|
|
public const FIELD_ACTIVE_PROMOTIONS = 'active_promotions'; |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Returns the contact and billing information related to your Account. |
|
98
|
|
|
* |
|
99
|
|
|
* @throws LinodeException |
|
100
|
|
|
*/ |
|
101
|
|
|
public function __construct(LinodeClient $client) |
|
102
|
|
|
{ |
|
103
|
|
|
parent::__construct($client); |
|
104
|
|
|
|
|
105
|
|
|
$response = $this->client->get('/account'); |
|
106
|
|
|
$contents = $response->getBody()->getContents(); |
|
107
|
|
|
$json = json_decode($contents, true); |
|
108
|
|
|
|
|
109
|
|
|
$this->data = $json; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @codeCoverageIgnore This method was autogenerated. |
|
114
|
|
|
*/ |
|
115
|
|
|
public function __get(string $name): mixed |
|
116
|
|
|
{ |
|
117
|
|
|
return match ($name) { |
|
118
|
|
|
self::FIELD_CREDIT_CARD => new CreditCard($this->client, $this->data[$name]), |
|
119
|
|
|
self::FIELD_ACTIVE_PROMOTIONS => array_map(fn ($data) => new Promotion($this->client, $data), $this->data[$name]), |
|
120
|
|
|
'events' => new EventRepository($this->client), |
|
121
|
|
|
'invoices' => new InvoiceRepository($this->client), |
|
122
|
|
|
'notifications' => new NotificationRepository($this->client), |
|
123
|
|
|
'oauth_clients' => new OAuthClientRepository($this->client), |
|
124
|
|
|
'payments' => new PaymentRepository($this->client), |
|
125
|
|
|
'users' => new UserRepository($this->client), |
|
126
|
|
|
default => parent::__get($name), |
|
127
|
|
|
}; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Updates contact and billing information related to your Account. |
|
132
|
|
|
* |
|
133
|
|
|
* @param array $parameters Update contact and billing information. |
|
134
|
|
|
* |
|
135
|
|
|
* @throws LinodeException |
|
136
|
|
|
*/ |
|
137
|
|
|
public function updateAccount(array $parameters = []): self |
|
138
|
|
|
{ |
|
139
|
|
|
$response = $this->client->put('/account', $parameters); |
|
140
|
|
|
$contents = $response->getBody()->getContents(); |
|
141
|
|
|
$this->data = json_decode($contents, true); |
|
142
|
|
|
|
|
143
|
|
|
return $this; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Cancels an active Linode account. This action will cause Linode to attempt to |
|
148
|
|
|
* charge the credit card on file for the remaining balance. An error will occur if |
|
149
|
|
|
* Linode fails to charge the credit card on file. Restricted users will not be able |
|
150
|
|
|
* to cancel an account. |
|
151
|
|
|
* |
|
152
|
|
|
* @param string $comments Any reason for cancelling the account, and any other comments you might have about |
|
153
|
|
|
* your Linode service. |
|
154
|
|
|
* |
|
155
|
|
|
* @return string A link to Linode's exit survey. |
|
156
|
|
|
* |
|
157
|
|
|
* @throws LinodeException |
|
158
|
|
|
*/ |
|
159
|
|
|
public function cancelAccount(string $comments): string |
|
160
|
|
|
{ |
|
161
|
|
|
$parameters = [ |
|
162
|
|
|
'comments' => $comments, |
|
163
|
|
|
]; |
|
164
|
|
|
|
|
165
|
|
|
$response = $this->client->post('/account/cancel', $parameters); |
|
166
|
|
|
$contents = $response->getBody()->getContents(); |
|
167
|
|
|
$json = json_decode($contents, true); |
|
168
|
|
|
|
|
169
|
|
|
return $json['survey_link']; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Adds/edit credit card information to your Account. |
|
174
|
|
|
* Only one credit card can be associated with your Account, so using this endpoint |
|
175
|
|
|
* will overwrite your currently active card information with the new credit card. |
|
176
|
|
|
* |
|
177
|
|
|
* @param string $card_number Your credit card number. No spaces or dashes allowed. |
|
178
|
|
|
* @param string $expiry_month A value from 1-12 representing the expiration month of your credit card. |
|
179
|
|
|
* @param string $expiry_year A four-digit integer representing the expiration year of your credit card. |
|
180
|
|
|
* @param string $cvv The Card Verification Value on the back of the card. |
|
181
|
|
|
* |
|
182
|
|
|
* @throws LinodeException |
|
183
|
|
|
*/ |
|
184
|
|
|
public function createCreditCard(string $card_number, string $expiry_month, string $expiry_year, string $cvv): void |
|
185
|
|
|
{ |
|
186
|
|
|
$parameters = [ |
|
187
|
|
|
'card_number' => $card_number, |
|
188
|
|
|
'expiry_month' => $expiry_month, |
|
189
|
|
|
'expiry_year' => $expiry_year, |
|
190
|
|
|
'cvv' => $cvv, |
|
191
|
|
|
]; |
|
192
|
|
|
|
|
193
|
|
|
$this->client->post('/account/credit-card', $parameters); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Returns a Transfer object showing your network utilization, in GB, for the current |
|
198
|
|
|
* month. |
|
199
|
|
|
* |
|
200
|
|
|
* @throws LinodeException |
|
201
|
|
|
*/ |
|
202
|
|
|
public function getTransfer(): Transfer |
|
203
|
|
|
{ |
|
204
|
|
|
$response = $this->client->get('/account/transfer'); |
|
205
|
|
|
$contents = $response->getBody()->getContents(); |
|
206
|
|
|
$json = json_decode($contents, true); |
|
207
|
|
|
|
|
208
|
|
|
return new Transfer($this->client, $json); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Returns information related to your Account settings: Managed service |
|
213
|
|
|
* subscription, Longview subscription, and network helper. |
|
214
|
|
|
* |
|
215
|
|
|
* @throws LinodeException |
|
216
|
|
|
*/ |
|
217
|
|
|
public function getAccountSettings(): AccountSettings |
|
218
|
|
|
{ |
|
219
|
|
|
$response = $this->client->get('/account/settings'); |
|
220
|
|
|
$contents = $response->getBody()->getContents(); |
|
221
|
|
|
$json = json_decode($contents, true); |
|
222
|
|
|
|
|
223
|
|
|
return new AccountSettings($this->client, $json); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Updates your Account settings. |
|
228
|
|
|
* |
|
229
|
|
|
* @param array $parameters Update Account settings information. |
|
230
|
|
|
* |
|
231
|
|
|
* @throws LinodeException |
|
232
|
|
|
*/ |
|
233
|
|
|
public function updateAccountSettings(array $parameters = []): AccountSettings |
|
234
|
|
|
{ |
|
235
|
|
|
$response = $this->client->put('/account/settings', $parameters); |
|
236
|
|
|
$contents = $response->getBody()->getContents(); |
|
237
|
|
|
$json = json_decode($contents, true); |
|
238
|
|
|
|
|
239
|
|
|
return new AccountSettings($this->client, $json); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* Enables Linode Managed for the entire account and sends a welcome email to the |
|
244
|
|
|
* account's associated email address. Linode Managed can monitor any service or |
|
245
|
|
|
* software stack reachable over TCP or HTTP. See our Linode Managed guide to learn |
|
246
|
|
|
* more. |
|
247
|
|
|
* |
|
248
|
|
|
* @throws LinodeException |
|
249
|
|
|
*/ |
|
250
|
|
|
public function enableAccountManged(): void |
|
251
|
|
|
{ |
|
252
|
|
|
$this->client->post('/account/settings/managed-enable'); |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* Returns a list of Managed Stats on your Account in the form of x and y data |
|
257
|
|
|
* points. |
|
258
|
|
|
* You can use these data points to plot your own graph visualizations. These stats |
|
259
|
|
|
* reflect the last 24 hours of combined usage across all managed Linodes on your |
|
260
|
|
|
* account |
|
261
|
|
|
* giving you a high-level snapshot of data for the following: |
|
262
|
|
|
* |
|
263
|
|
|
* * cpu |
|
264
|
|
|
* * disk |
|
265
|
|
|
* * swap |
|
266
|
|
|
* * network in |
|
267
|
|
|
* * network out |
|
268
|
|
|
* |
|
269
|
|
|
* @return StatsDataAvailable A list of Managed Stats from the last 24 hours. |
|
270
|
|
|
* |
|
271
|
|
|
* @throws LinodeException |
|
272
|
|
|
*/ |
|
273
|
|
|
public function getManagedStats(): StatsDataAvailable |
|
274
|
|
|
{ |
|
275
|
|
|
$response = $this->client->get('/managed/stats'); |
|
276
|
|
|
$contents = $response->getBody()->getContents(); |
|
277
|
|
|
$json = json_decode($contents, true); |
|
278
|
|
|
|
|
279
|
|
|
return new StatsDataAvailable($this->client, $json); |
|
280
|
|
|
} |
|
281
|
|
|
} |
|
282
|
|
|
|