|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Fenerum\API; |
|
6
|
|
|
|
|
7
|
|
|
class Subscription extends Base |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @return array|null |
|
11
|
|
|
* @throws \Fenerum\API\Exceptions\FenerumApiException |
|
12
|
|
|
*/ |
|
13
|
|
|
public function listSubscriptions(): ?array |
|
14
|
|
|
{ |
|
15
|
|
|
return $this->client->get('subscriptions/'); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @param string $uuid |
|
20
|
|
|
* @return array|null |
|
21
|
|
|
* @throws \Fenerum\API\Exceptions\FenerumApiException |
|
22
|
|
|
*/ |
|
23
|
|
|
public function getSubscription(string $uuid): ?array |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->client->get('subscriptions/'.$uuid.'/'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param array $data |
|
30
|
|
|
* @return array|null |
|
31
|
|
|
* @throws \Fenerum\API\Exceptions\FenerumApiException |
|
32
|
|
|
* @throws \Fenerum\API\Exceptions\FenerumValidationException |
|
33
|
|
|
*/ |
|
34
|
|
|
public function createSubscription(array $data): ?array |
|
35
|
|
|
{ |
|
36
|
|
|
$this->validate($data, [ |
|
37
|
|
|
'account' => 'required|string', |
|
38
|
|
|
'terms' => 'required|string', |
|
39
|
|
|
'collection_method' => 'required|string', |
|
40
|
|
|
'start_date' => 'date', |
|
41
|
|
|
'quantity' => 'integer', |
|
42
|
|
|
'group_on_invoice' => 'boolean', |
|
43
|
|
|
'payment_terms' => 'integer', |
|
44
|
|
|
'pre_renewal_invoicing' => 'boolean', |
|
45
|
|
|
'po_number' => 'string', |
|
46
|
|
|
'invoice_supplement' => 'string', |
|
47
|
|
|
]); |
|
48
|
|
|
|
|
49
|
|
|
return $this->client->post('subscriptions/', $data); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param array $data |
|
54
|
|
|
* @param string $uuid |
|
55
|
|
|
* @return array|null |
|
56
|
|
|
* @throws \Fenerum\API\Exceptions\FenerumApiException |
|
57
|
|
|
*/ |
|
58
|
|
|
public function updateSubscription(array $data, string $uuid): ?array |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->client->put('subscriptions/'.$uuid.'/', $data); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param array $data |
|
65
|
|
|
* @param string $uuid |
|
66
|
|
|
* @return array|null |
|
67
|
|
|
* @throws \Fenerum\API\Exceptions\FenerumApiException |
|
68
|
|
|
* @throws \Fenerum\API\Exceptions\FenerumValidationException |
|
69
|
|
|
*/ |
|
70
|
|
|
public function cancelSubscription(array $data, string $uuid): ?array |
|
71
|
|
|
{ |
|
72
|
|
|
$this->validate($data, [ |
|
73
|
|
|
'cancellation_type' => 'required|string', |
|
74
|
|
|
]); |
|
75
|
|
|
|
|
76
|
|
|
return $this->client->post('subscriptions/'.$uuid.'/cancel/', $data); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|