Skip to content

Commit 3f1e06d

Browse files
committed
Add Microsoft Subscriptions
1 parent 6697e19 commit 3f1e06d

3 files changed

Lines changed: 354 additions & 4 deletions

File tree

src/CloudFactoryAPIClient.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Inserve\CloudFactoryAPI\DTO\AccessToken;
66
use Inserve\CloudFactoryAPI\DTO\CustomerResults;
7+
use Inserve\CloudFactoryAPI\DTO\MicrosoftSubscriptionResults;
78
use Inserve\CloudFactoryAPI\DTO\ProductResults;
89
use Inserve\CloudFactoryAPI\Exception\CloudFactoryAPIException;
910
use GuzzleHttp\ClientInterface;
@@ -121,6 +122,23 @@ public function getProducts(array $parameters = []): ?ProductResults
121122
return $this->getDto('/v2/catalogue/Products', ProductResults::class, $parameters);
122123
}
123124

125+
/**
126+
* @param string $customerId
127+
* @param array $parameters
128+
*
129+
* @return MicrosoftSubscriptionResults|null
130+
* @throws CloudFactoryAPIException
131+
*/
132+
public function getMicrosoftSubscriptions(string $customerId, array $parameters = []): ?MicrosoftSubscriptionResults
133+
{
134+
/** @var MicrosoftSubscriptionResults|null */
135+
return $this->getDto(
136+
sprintf('/v2/microsoft/customer/%s/subscriptions', $customerId),
137+
MicrosoftSubscriptionResults::class,
138+
$parameters
139+
);
140+
}
141+
124142
/**
125143
* @template T
126144
* @param string $uri
@@ -133,19 +151,23 @@ public function getProducts(array $parameters = []): ?ProductResults
133151
*/
134152
protected function getDto(string $uri, string $dtoClass, array $query = [], array $headers = []): ?object
135153
{
136-
$json = $this->requestRaw('GET', $uri, [
154+
$response = $this->requestRaw('GET', $uri, [
137155
'query' => $query,
138156
'headers' => $headers,
139157
]);
140158

141159
try {
142-
$json = json_decode(
143-
json: $json,
160+
$jsonData = json_decode(
161+
json: $response,
144162
associative: true,
145163
flags: JSON_THROW_ON_ERROR
146164
);
147165

148-
return $this->normalizer->denormalize($json, $dtoClass);
166+
if (array_is_list($jsonData) && method_exists($dtoClass, 'setResults')) {
167+
$jsonData = ['results' => $jsonData];
168+
}
169+
170+
return $this->normalizer->denormalize($jsonData, $dtoClass);
149171
} catch (Throwable $exception) {
150172
$this->logError('Error denormalizing response', [
151173
'uri' => $uri,

src/DTO/MicrosoftSubscription.php

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
<?php
2+
3+
namespace Inserve\CloudFactoryAPI\DTO;
4+
5+
final class MicrosoftSubscription
6+
{
7+
protected ?string $id = null;
8+
protected ?string $name = null;
9+
protected ?string $nickname = null;
10+
protected ?int $quantity = null;
11+
protected ?string $sku = null;
12+
protected ?bool $isTrial = null;
13+
protected ?bool $autoRenewEnabled = null;
14+
protected ?string $status = null;
15+
protected ?string $billingCycle = null;
16+
protected ?string $termDuration = null;
17+
protected ?string $commitmentEndDate = null;
18+
protected ?string $creationDate = null;
19+
protected ?string $effectiveStartDate = null;
20+
protected null $parentSubscriptionId = null;
21+
22+
/**
23+
* @return string|null
24+
*/
25+
public function getId(): ?string
26+
{
27+
return $this->id;
28+
}
29+
30+
/**
31+
* @return string|null
32+
*/
33+
public function getName(): ?string
34+
{
35+
return $this->name;
36+
}
37+
38+
/**
39+
* @return string|null
40+
*/
41+
public function getNickname(): ?string
42+
{
43+
return $this->nickname;
44+
}
45+
46+
/**
47+
* @return int|null
48+
*/
49+
public function getQuantity(): ?int
50+
{
51+
return $this->quantity;
52+
}
53+
54+
/**
55+
* @return string|null
56+
*/
57+
public function getSku(): ?string
58+
{
59+
return $this->sku;
60+
}
61+
62+
/**
63+
* @return bool|null
64+
*/
65+
public function getIsTrial(): ?bool
66+
{
67+
return $this->isTrial;
68+
}
69+
70+
/**
71+
* @return bool|null
72+
*/
73+
public function getAutoRenewEnabled(): ?bool
74+
{
75+
return $this->autoRenewEnabled;
76+
}
77+
78+
/**
79+
* @return string|null
80+
*/
81+
public function getStatus(): ?string
82+
{
83+
return $this->status;
84+
}
85+
86+
/**
87+
* @return string|null
88+
*/
89+
public function getBillingCycle(): ?string
90+
{
91+
return $this->billingCycle;
92+
}
93+
94+
/**
95+
* @return string|null
96+
*/
97+
public function getTermDuration(): ?string
98+
{
99+
return $this->termDuration;
100+
}
101+
102+
/**
103+
* @return string|null
104+
*/
105+
public function getCommitmentEndDate(): ?string
106+
{
107+
return $this->commitmentEndDate;
108+
}
109+
110+
/**
111+
* @return string|null
112+
*/
113+
public function getCreationDate(): ?string
114+
{
115+
return $this->creationDate;
116+
}
117+
118+
/**
119+
* @return string|null
120+
*/
121+
public function getEffectiveStartDate(): ?string
122+
{
123+
return $this->effectiveStartDate;
124+
}
125+
126+
/**
127+
* @return null
128+
*/
129+
public function getParentSubscriptionId(): null
130+
{
131+
return $this->parentSubscriptionId;
132+
}
133+
134+
/**
135+
* @param string|null $id
136+
*
137+
* @return $this
138+
*/
139+
public function setId(?string $id): self
140+
{
141+
$this->id = $id;
142+
143+
return $this;
144+
}
145+
146+
/**
147+
* @param string|null $name
148+
*
149+
* @return $this
150+
*/
151+
public function setName(?string $name): self
152+
{
153+
$this->name = $name;
154+
155+
return $this;
156+
}
157+
158+
/**
159+
* @param string|null $nickname
160+
*
161+
* @return $this
162+
*/
163+
public function setNickname(?string $nickname): self
164+
{
165+
$this->nickname = $nickname;
166+
167+
return $this;
168+
}
169+
170+
/**
171+
* @param int|null $quantity
172+
*
173+
* @return $this
174+
*/
175+
public function setQuantity(?int $quantity): self
176+
{
177+
$this->quantity = $quantity;
178+
179+
return $this;
180+
}
181+
182+
/**
183+
* @param string|null $sku
184+
*
185+
* @return $this
186+
*/
187+
public function setSku(?string $sku): self
188+
{
189+
$this->sku = $sku;
190+
191+
return $this;
192+
}
193+
194+
/**
195+
* @param bool|null $isTrial
196+
*
197+
* @return $this
198+
*/
199+
public function setIsTrial(?bool $isTrial): self
200+
{
201+
$this->isTrial = $isTrial;
202+
203+
return $this;
204+
}
205+
206+
/**
207+
* @param bool|null $autoRenewEnabled
208+
*
209+
* @return $this
210+
*/
211+
public function setAutoRenewEnabled(?bool $autoRenewEnabled): self
212+
{
213+
$this->autoRenewEnabled = $autoRenewEnabled;
214+
215+
return $this;
216+
}
217+
218+
/**
219+
* @param string|null $status
220+
*
221+
* @return $this
222+
*/
223+
public function setStatus(?string $status): self
224+
{
225+
$this->status = $status;
226+
227+
return $this;
228+
}
229+
230+
/**
231+
* @param string|null $billingCycle
232+
*
233+
* @return $this
234+
*/
235+
public function setBillingCycle(?string $billingCycle): self
236+
{
237+
$this->billingCycle = $billingCycle;
238+
239+
return $this;
240+
}
241+
242+
/**
243+
* @param string|null $termDuration
244+
*
245+
* @return $this
246+
*/
247+
public function setTermDuration(?string $termDuration): self
248+
{
249+
$this->termDuration = $termDuration;
250+
251+
return $this;
252+
}
253+
254+
/**
255+
* @param string|null $commitmentEndDate
256+
*
257+
* @return $this
258+
*/
259+
public function setCommitmentEndDate(?string $commitmentEndDate): self
260+
{
261+
$this->commitmentEndDate = $commitmentEndDate;
262+
263+
return $this;
264+
}
265+
266+
/**
267+
* @param string|null $creationDate
268+
*
269+
* @return $this
270+
*/
271+
public function setCreationDate(?string $creationDate): self
272+
{
273+
$this->creationDate = $creationDate;
274+
275+
return $this;
276+
}
277+
278+
/**
279+
* @param string|null $effectiveStartDate
280+
*
281+
* @return $this
282+
*/
283+
public function setEffectiveStartDate(?string $effectiveStartDate): self
284+
{
285+
$this->effectiveStartDate = $effectiveStartDate;
286+
287+
return $this;
288+
}
289+
290+
/**
291+
* @param null $parentSubscriptionId
292+
*
293+
* @return $this
294+
*/
295+
public function setParentSubscriptionId(null $parentSubscriptionId): self
296+
{
297+
$this->parentSubscriptionId = $parentSubscriptionId;
298+
299+
return $this;
300+
}
301+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Inserve\CloudFactoryAPI\DTO;
4+
5+
final class MicrosoftSubscriptionResults
6+
{
7+
/** @var MicrosoftSubscription[] */
8+
protected array $results = [];
9+
10+
/**
11+
* @return MicrosoftSubscription[]
12+
*/
13+
public function getResults(): array
14+
{
15+
return $this->results;
16+
}
17+
18+
/**
19+
* @param MicrosoftSubscription[] $results
20+
*/
21+
public function setResults(array $results): self
22+
{
23+
$this->results = $results;
24+
25+
return $this;
26+
}
27+
}

0 commit comments

Comments
 (0)