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\PaymentMethodRepository; |
19
|
|
|
use Linode\Account\Repository\PaymentRepository; |
20
|
|
|
use Linode\Account\Repository\ServiceTransferRepository; |
21
|
|
|
use Linode\Account\Repository\UserRepository; |
22
|
|
|
use Linode\Entity; |
23
|
|
|
use Linode\Exception\LinodeException; |
24
|
|
|
use Linode\LinodeClient; |
25
|
|
|
use Linode\Longview\LongviewSubscription; |
26
|
|
|
use Linode\Managed\StatsDataAvailable; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Account object. |
30
|
|
|
* |
31
|
|
|
* @property string $first_name The first name of the person associated with this Account. |
32
|
|
|
* @property string $last_name The last name of the person associated with this Account. |
33
|
|
|
* @property string $email The email address of the person associated with this Account. |
34
|
|
|
* @property float $balance This Account's balance, in US dollars. |
35
|
|
|
* @property float $balance_uninvoiced This Account's current estimated invoice in US dollars. This is not your final |
36
|
|
|
* invoice balance. Transfer charges are not included in the estimate. |
37
|
|
|
* @property string $company The company name associated with this Account. |
38
|
|
|
* @property string $address_1 First line of this Account's billing address. |
39
|
|
|
* @property string $address_2 Second line of this Account's billing address. |
40
|
|
|
* @property string $city The city for this Account's billing address. |
41
|
|
|
* @property string $state If billing address is in the United States, this is the State portion of the |
42
|
|
|
* Account's billing address. If the address is outside the US, this is the Province |
43
|
|
|
* associated with the Account's billing address. |
44
|
|
|
* @property string $zip The zip code of this Account's billing address. The following restrictions apply: |
45
|
|
|
* - May only consist of letters, numbers, spaces, and hyphens. |
46
|
|
|
* - Must not contain more than 9 letter or number characters. |
47
|
|
|
* @property string $country The two-letter country code of this Account's billing address. |
48
|
|
|
* @property string $phone The phone number associated with this Account. |
49
|
|
|
* @property string $tax_id The tax identification number associated with this Account, for tax calculations |
50
|
|
|
* in some countries. If you do not live in a country that collects tax, this should |
51
|
|
|
* be `null`. |
52
|
|
|
* @property CreditCard $credit_card Credit Card information associated with this Account. |
53
|
|
|
* @property string $active_since The datetime of when the account was activated. |
54
|
|
|
* @property string[] $capabilities A list of capabilities your account supports. |
55
|
|
|
* @property Promotion[] $active_promotions A list of active promotions on your account. |
56
|
|
|
* @property string $euuid An external unique identifier for this account. |
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 PaymentMethodRepositoryInterface $paymentMethods List of Payment Methods for this Account. |
68
|
|
|
* @property ServiceTransferRepositoryInterface $serviceTransfers List of Service Transfer objects containing the details of all transfers that have |
69
|
|
|
* been created and accepted by this account. |
70
|
|
|
* @property UserRepositoryInterface $users List of Users on your Account. Users may access all or part of your Account based |
71
|
|
|
* on their restricted status and grants. An unrestricted User may access everything |
72
|
|
|
* on the account, whereas restricted User may only access entities or perform |
73
|
|
|
* actions they've been given specific grants to. |
74
|
|
|
* |
75
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
76
|
|
|
*/ |
77
|
|
|
class Account extends Entity |
78
|
|
|
{ |
79
|
|
|
// Available fields. |
80
|
|
|
public const FIELD_FIRST_NAME = 'first_name'; |
81
|
|
|
public const FIELD_LAST_NAME = 'last_name'; |
82
|
|
|
public const FIELD_EMAIL = 'email'; |
83
|
|
|
public const FIELD_BALANCE = 'balance'; |
84
|
|
|
public const FIELD_BALANCE_UNINVOICED = 'balance_uninvoiced'; |
85
|
|
|
public const FIELD_COMPANY = 'company'; |
86
|
|
|
public const FIELD_ADDRESS_1 = 'address_1'; |
87
|
|
|
public const FIELD_ADDRESS_2 = 'address_2'; |
88
|
|
|
public const FIELD_CITY = 'city'; |
89
|
|
|
public const FIELD_STATE = 'state'; |
90
|
|
|
public const FIELD_ZIP = 'zip'; |
91
|
|
|
public const FIELD_COUNTRY = 'country'; |
92
|
|
|
public const FIELD_PHONE = 'phone'; |
93
|
|
|
public const FIELD_TAX_ID = 'tax_id'; |
94
|
|
|
public const FIELD_CREDIT_CARD = 'credit_card'; |
95
|
|
|
public const FIELD_ACTIVE_SINCE = 'active_since'; |
96
|
|
|
public const FIELD_CAPABILITIES = 'capabilities'; |
97
|
|
|
public const FIELD_ACTIVE_PROMOTIONS = 'active_promotions'; |
98
|
|
|
public const FIELD_EUUID = 'euuid'; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns the contact and billing information related to your Account. |
102
|
|
|
* |
103
|
|
|
* @throws LinodeException |
104
|
|
|
*/ |
105
|
|
|
public function __construct(LinodeClient $client) |
106
|
|
|
{ |
107
|
|
|
parent::__construct($client); |
108
|
|
|
|
109
|
|
|
$response = $this->client->get('/account'); |
110
|
|
|
$contents = $response->getBody()->getContents(); |
111
|
|
|
$json = json_decode($contents, true); |
112
|
|
|
|
113
|
|
|
$this->data = $json; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @codeCoverageIgnore This method was autogenerated. |
118
|
|
|
*/ |
119
|
|
|
public function __get(string $name): mixed |
120
|
|
|
{ |
121
|
|
|
return match ($name) { |
122
|
|
|
self::FIELD_CREDIT_CARD => new CreditCard($this->client, $this->data[$name]), |
123
|
|
|
self::FIELD_ACTIVE_PROMOTIONS => array_map(fn ($data) => new Promotion($this->client, $data), $this->data[$name]), |
124
|
|
|
'events' => new EventRepository($this->client), |
125
|
|
|
'invoices' => new InvoiceRepository($this->client), |
126
|
|
|
'notifications' => new NotificationRepository($this->client), |
127
|
|
|
'oauth_clients' => new OAuthClientRepository($this->client), |
128
|
|
|
'payments' => new PaymentRepository($this->client), |
129
|
|
|
'paymentMethods' => new PaymentMethodRepository($this->client), |
130
|
|
|
'serviceTransfers' => new ServiceTransferRepository($this->client), |
131
|
|
|
'users' => new UserRepository($this->client), |
132
|
|
|
default => parent::__get($name), |
133
|
|
|
}; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Updates contact and billing information related to your Account. |
138
|
|
|
* |
139
|
|
|
* @param array $parameters Update contact and billing information. |
140
|
|
|
* |
141
|
|
|
* @throws LinodeException |
142
|
|
|
*/ |
143
|
|
|
public function updateAccount(array $parameters = []): self |
144
|
|
|
{ |
145
|
|
|
$response = $this->client->put('/account', $parameters); |
146
|
|
|
$contents = $response->getBody()->getContents(); |
147
|
|
|
$this->data = json_decode($contents, true); |
148
|
|
|
|
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Cancels an active Linode account. This action will cause Linode to attempt to |
154
|
|
|
* charge the credit card on file for the remaining balance. An error will occur if |
155
|
|
|
* Linode fails to charge the credit card on file. Restricted users will not be able |
156
|
|
|
* to cancel an account. |
157
|
|
|
* |
158
|
|
|
* @param string $comments Any reason for cancelling the account, and any other comments you might have about |
159
|
|
|
* your Linode service. |
160
|
|
|
* |
161
|
|
|
* @return string A link to Linode's exit survey. |
162
|
|
|
* |
163
|
|
|
* @throws LinodeException |
164
|
|
|
*/ |
165
|
|
|
public function cancelAccount(string $comments): string |
166
|
|
|
{ |
167
|
|
|
$parameters = [ |
168
|
|
|
'comments' => $comments, |
169
|
|
|
]; |
170
|
|
|
|
171
|
|
|
$response = $this->client->post('/account/cancel', $parameters); |
172
|
|
|
$contents = $response->getBody()->getContents(); |
173
|
|
|
$json = json_decode($contents, true); |
174
|
|
|
|
175
|
|
|
return $json['survey_link']; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* **DEPRECATED**. Please use Payment Method Add (POST /account/payment-methods). |
180
|
|
|
* |
181
|
|
|
* Adds a credit card Payment Method to your account and sets it as the default |
182
|
|
|
* method. |
183
|
|
|
* |
184
|
|
|
* @param string $card_number Your credit card number. No spaces or dashes allowed. |
185
|
|
|
* @param string $expiry_month A value from 1-12 representing the expiration month of your credit card. |
186
|
|
|
* @param string $expiry_year A four-digit integer representing the expiration year of your credit card. |
187
|
|
|
* @param string $cvv The Card Verification Value on the back of the card. |
188
|
|
|
* |
189
|
|
|
* @throws LinodeException |
190
|
|
|
*/ |
191
|
|
|
public function createCreditCard(string $card_number, string $expiry_month, string $expiry_year, string $cvv): void |
192
|
|
|
{ |
193
|
|
|
$parameters = [ |
194
|
|
|
'card_number' => $card_number, |
195
|
|
|
'expiry_month' => $expiry_month, |
196
|
|
|
'expiry_year' => $expiry_year, |
197
|
|
|
'cvv' => $cvv, |
198
|
|
|
]; |
199
|
|
|
|
200
|
|
|
$this->client->post('/account/credit-card', $parameters); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Returns a collection of successful logins for all users on the account during the |
205
|
|
|
* last 90 days. This command can only be accessed by the unrestricted users of an |
206
|
|
|
* account. |
207
|
|
|
* |
208
|
|
|
* @return Login[] A collection of successful logins for all users on the account during the last 90 |
209
|
|
|
* days. |
210
|
|
|
* |
211
|
|
|
* @throws LinodeException |
212
|
|
|
*/ |
213
|
|
|
public function getAccountLogins(): array |
214
|
|
|
{ |
215
|
|
|
$response = $this->client->get('/account/logins'); |
216
|
|
|
$contents = $response->getBody()->getContents(); |
217
|
|
|
$json = json_decode($contents, true); |
218
|
|
|
|
219
|
|
|
return array_map(fn ($data) => new Login($this->client, $data), $json['data']); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Returns a Login object that displays information about a successful login. The |
224
|
|
|
* logins that can be viewed can be for any user on the account, and are not limited |
225
|
|
|
* to only the logins of the user that is accessing this API endpoint. This command |
226
|
|
|
* can only be accessed by the unrestricted users of the account. |
227
|
|
|
* |
228
|
|
|
* @param int $loginId The ID of the login object to access. |
229
|
|
|
* |
230
|
|
|
* @throws LinodeException |
231
|
|
|
*/ |
232
|
|
|
public function getAccountLogin(int $loginId): Login |
233
|
|
|
{ |
234
|
|
|
$response = $this->client->get("/account/logins/{$loginId}"); |
235
|
|
|
$contents = $response->getBody()->getContents(); |
236
|
|
|
$json = json_decode($contents, true); |
237
|
|
|
|
238
|
|
|
return new Login($this->client, $json); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Returns a collection of Maintenance objects for any entity a user has permissions |
243
|
|
|
* to view. |
244
|
|
|
* |
245
|
|
|
* Currently, Linodes are the only entities available for viewing. |
246
|
|
|
* |
247
|
|
|
* **Beta**: This endpoint is in beta. Please make sure to prepend all requests with |
248
|
|
|
* `/v4beta` instead of `/v4`, and be aware that this endpoint may receive breaking |
249
|
|
|
* updates in the future. This notice will be removed when this endpoint is out of |
250
|
|
|
* beta. |
251
|
|
|
* |
252
|
|
|
* @throws LinodeException |
253
|
|
|
*/ |
254
|
|
|
public function getMaintenance(): array |
255
|
|
|
{ |
256
|
|
|
$response = $this->client->get('/account/maintenance'); |
257
|
|
|
$contents = $response->getBody()->getContents(); |
258
|
|
|
|
259
|
|
|
return json_decode($contents, true); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Returns a Transfer object showing your network utilization, in GB, for the current |
264
|
|
|
* month. |
265
|
|
|
* |
266
|
|
|
* @throws LinodeException |
267
|
|
|
*/ |
268
|
|
|
public function getTransfer(): Transfer |
269
|
|
|
{ |
270
|
|
|
$response = $this->client->get('/account/transfer'); |
271
|
|
|
$contents = $response->getBody()->getContents(); |
272
|
|
|
$json = json_decode($contents, true); |
273
|
|
|
|
274
|
|
|
return new Transfer($this->client, $json); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Returns information related to your Account settings: Managed service |
279
|
|
|
* subscription, Longview subscription, and network helper. |
280
|
|
|
* |
281
|
|
|
* @throws LinodeException |
282
|
|
|
*/ |
283
|
|
|
public function getAccountSettings(): AccountSettings |
284
|
|
|
{ |
285
|
|
|
$response = $this->client->get('/account/settings'); |
286
|
|
|
$contents = $response->getBody()->getContents(); |
287
|
|
|
$json = json_decode($contents, true); |
288
|
|
|
|
289
|
|
|
return new AccountSettings($this->client, $json); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* Updates your Account settings. |
294
|
|
|
* |
295
|
|
|
* To update your Longview subscription plan, send a request to Update Longview Plan. |
296
|
|
|
* |
297
|
|
|
* @param array $parameters Update Account settings information. |
298
|
|
|
* |
299
|
|
|
* @throws LinodeException |
300
|
|
|
*/ |
301
|
|
|
public function updateAccountSettings(array $parameters = []): AccountSettings |
302
|
|
|
{ |
303
|
|
|
$response = $this->client->put('/account/settings', $parameters); |
304
|
|
|
$contents = $response->getBody()->getContents(); |
305
|
|
|
$json = json_decode($contents, true); |
306
|
|
|
|
307
|
|
|
return new AccountSettings($this->client, $json); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Enables Linode Managed for the entire account and sends a welcome email to the |
312
|
|
|
* account's associated email address. Linode Managed can monitor any service or |
313
|
|
|
* software stack reachable over TCP or HTTP. See our Linode Managed guide to learn |
314
|
|
|
* more. |
315
|
|
|
* |
316
|
|
|
* @throws LinodeException |
317
|
|
|
*/ |
318
|
|
|
public function enableAccountManged(): void |
319
|
|
|
{ |
320
|
|
|
$this->client->post('/account/settings/managed-enable'); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Get the details of your current Longview plan. This returns a |
325
|
|
|
* `LongviewSubscription` object for your current Longview Pro plan, or an empty set |
326
|
|
|
* `{}` if your current plan is Longview Free. |
327
|
|
|
* |
328
|
|
|
* You must have at least one of the following `global` User Grants in order to |
329
|
|
|
* access this endpoint: |
330
|
|
|
* |
331
|
|
|
* - `"account_access": read_write` |
332
|
|
|
* - `"account_access": read_only` |
333
|
|
|
* - `"longview_subscription": true` |
334
|
|
|
* - `"add_longview": true` |
335
|
|
|
* |
336
|
|
|
* To update your subscription plan, send a request to Update Longview Plan. |
337
|
|
|
* |
338
|
|
|
* @throws LinodeException |
339
|
|
|
*/ |
340
|
|
|
public function getLongviewPlan(): LongviewSubscription |
341
|
|
|
{ |
342
|
|
|
$response = $this->client->get('/longview/plan'); |
343
|
|
|
$contents = $response->getBody()->getContents(); |
344
|
|
|
$json = json_decode($contents, true); |
345
|
|
|
|
346
|
|
|
return new LongviewSubscription($this->client, $json); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* Update your Longview plan to that of the given subcription ID. This returns a |
351
|
|
|
* `LongviewSubscription` object for the updated Longview Pro plan, or an empty set |
352
|
|
|
* `{}` if the updated plan is Longview Free. |
353
|
|
|
* |
354
|
|
|
* You must have `"longview_subscription": true` configured as a `global` User Grant |
355
|
|
|
* in order to access this endpoint. |
356
|
|
|
* |
357
|
|
|
* You can send a request to the List Longview Subscriptions endpoint to receive the |
358
|
|
|
* details, including `id`'s, of each plan. |
359
|
|
|
* |
360
|
|
|
* @param array $parameters Update your Longview subscription plan. |
361
|
|
|
* |
362
|
|
|
* @throws LinodeException |
363
|
|
|
*/ |
364
|
|
|
public function updateLongviewPlan(array $parameters = []): LongviewSubscription |
365
|
|
|
{ |
366
|
|
|
$response = $this->client->put('/longview/plan', $parameters); |
367
|
|
|
$contents = $response->getBody()->getContents(); |
368
|
|
|
$json = json_decode($contents, true); |
369
|
|
|
|
370
|
|
|
return new LongviewSubscription($this->client, $json); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* Adds an expiring Promo Credit to your account. |
375
|
|
|
* |
376
|
|
|
* The following restrictions apply: |
377
|
|
|
* |
378
|
|
|
* * Your account must be less than 90 days old. |
379
|
|
|
* * There must not be an existing Promo Credit already on your account. |
380
|
|
|
* * The requesting User must be unrestricted. Use the User Update |
381
|
|
|
* (PUT /account/users/{username}) to change a User's restricted status. |
382
|
|
|
* * The `promo_code` must be valid and unexpired. |
383
|
|
|
* |
384
|
|
|
* @param array $parameters Enter a Promo Code to add its associated credit to your Account. |
385
|
|
|
* |
386
|
|
|
* @throws LinodeException |
387
|
|
|
*/ |
388
|
|
|
public function createPromoCredit(array $parameters = []): Promotion |
389
|
|
|
{ |
390
|
|
|
$response = $this->client->post('/account/promo-codes', $parameters); |
391
|
|
|
$contents = $response->getBody()->getContents(); |
392
|
|
|
$json = json_decode($contents, true); |
393
|
|
|
|
394
|
|
|
return new Promotion($this->client, $json); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* Returns a list of Managed Stats on your Account in the form of x and y data |
399
|
|
|
* points. |
400
|
|
|
* You can use these data points to plot your own graph visualizations. These stats |
401
|
|
|
* reflect the last 24 hours of combined usage across all managed Linodes on your |
402
|
|
|
* account |
403
|
|
|
* giving you a high-level snapshot of data for the following: |
404
|
|
|
* |
405
|
|
|
* * cpu |
406
|
|
|
* * disk |
407
|
|
|
* * swap |
408
|
|
|
* * network in |
409
|
|
|
* * network out |
410
|
|
|
* |
411
|
|
|
* @return StatsDataAvailable A list of Managed Stats from the last 24 hours. |
412
|
|
|
* |
413
|
|
|
* @throws LinodeException |
414
|
|
|
*/ |
415
|
|
|
public function getManagedStats(): StatsDataAvailable |
416
|
|
|
{ |
417
|
|
|
$response = $this->client->get('/managed/stats'); |
418
|
|
|
$contents = $response->getBody()->getContents(); |
419
|
|
|
$json = json_decode($contents, true); |
420
|
|
|
|
421
|
|
|
return new StatsDataAvailable($this->client, $json); |
422
|
|
|
} |
423
|
|
|
} |
424
|
|
|
|