Skip to content

Commit ca93909

Browse files
committed
Typings and optional steamid field
1 parent ba29cd8 commit ca93909

24 files changed

Lines changed: 312 additions & 174 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "simpaypl/simpay",
33
"description": "Official SimPay API",
44
"type": "library",
5-
"version": "2.0.6",
5+
"version": "2.0.7",
66
"license": "MIT",
77
"minimum-stability": "stable",
88
"require": {

lib/Adapter/Guzzle.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010

1111
class Guzzle
1212
{
13-
1413
private Client $client;
1514

1615
private string $error;
17-
private string $errorCode;
16+
private int $errorCode;
1817

1918
private string $errorApi;
2019

@@ -24,28 +23,30 @@ public function __construct(Authorization $authorization)
2423
{
2524
$this->client = new Client([
2625
'base_uri' => 'https://api.simpay.pl',
27-
'headers' => $authorization->getHeaders()
26+
'headers' => $authorization->getHeaders(),
2827
]);
2928
}
3029

30+
/**
31+
* @param array<string, mixed> $data
32+
* @param array<string, string> $headers
33+
*
34+
* @return false|object|Collection
35+
*/
3136
public function request(string $method, string $uri, array $data = [], array $headers = [], bool $collect = false)
3237
{
33-
3438
try {
35-
3639
$response = $this->client->request($method, $uri, [
37-
($method === 'GET' ? 'query' : 'json') => $data,
40+
('GET' === $method ? 'query' : 'json') => $data,
3841
'headers' => $headers,
39-
'allow_redirects' => false
42+
'allow_redirects' => false,
4043
]);
4144

4245
$response = $response->getBody()->getContents();
4346
$response = json_decode($response);
4447

4548
$this->data = $response;
46-
4749
} catch (ClientException $exception) {
48-
4950
$response = $exception->getResponse()->getBody()->getContents();
5051
$json = json_decode($response);
5152

@@ -57,26 +58,22 @@ public function request(string $method, string $uri, array $data = [], array $he
5758
$this->errorCode = $exception->getCode();
5859

5960
return false;
60-
6161
} catch (GuzzleException $exception) {
62-
6362
$this->error = $exception->getMessage();
6463
$this->errorCode = $exception->getCode();
6564

6665
return false;
67-
6866
}
6967

7068
return !$collect ? $response->data : new Collection($response->data);
71-
7269
}
7370

7471
public function getErrorMessage(): string
7572
{
7673
return $this->error;
7774
}
7875

79-
public function getErrorCode(): string
76+
public function getErrorCode(): int
8077
{
8178
return $this->errorCode;
8279
}
@@ -86,9 +83,12 @@ public function getErrorApiMessage(): string
8683
return $this->errorApi;
8784
}
8885

89-
public function getPagination()
86+
public function getPagination(): ?object
9087
{
88+
if (!isset($this->data->pagination)) {
89+
return null;
90+
}
91+
9192
return $this->data->pagination;
9293
}
93-
94-
}
94+
}

lib/Authorization.php

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

55
class Authorization
66
{
7-
87
private string $apiKey;
98
private string $apiPassword;
109
private string $lang;
@@ -16,13 +15,15 @@ public function __construct(string $apiKey, string $apiPassword, string $lang =
1615
$this->lang = $lang;
1716
}
1817

18+
/**
19+
* @return array<string, string>
20+
*/
1921
public function getHeaders(): array
2022
{
2123
return [
2224
'X-SIM-KEY' => $this->apiKey,
2325
'X-SIM-PASSWORD' => $this->apiPassword,
24-
'X-SIM-LANG' => $this->lang
26+
'X-SIM-LANG' => $this->lang,
2527
];
2628
}
27-
28-
}
29+
}

lib/Components/DirectBilling/GenerateResponse.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,39 @@
44

55
class GenerateResponse
66
{
7-
87
private object $data;
98

10-
public string $transactionId;
11-
public string $redirectUrl;
9+
public ?string $transactionId = null;
10+
public ?string $redirectUrl = null;
1211

1312
public function __construct(object $data)
1413
{
15-
1614
$this->data = $data;
1715

18-
$this->transactionId = $data->transactionId;
19-
$this->redirectUrl = $data->redirectUrl;
16+
if (isset($data->transactionId)) {
17+
$this->transactionId = $data->transactionId;
18+
}
2019

20+
if (isset($data->redirectUrl)) {
21+
$this->redirectUrl = $data->redirectUrl;
22+
}
2123
}
2224

23-
public function getTransactionId()
25+
public function getTransactionId(): ?string
2426
{
27+
if (!isset($this->data->transactionId)) {
28+
return null;
29+
}
30+
2531
return $this->data->transactionId;
2632
}
2733

28-
public function getRedirectUrl()
34+
public function getRedirectUrl(): ?string
2935
{
36+
if (!isset($this->data->redirectUrl)) {
37+
return null;
38+
}
39+
3040
return $this->data->redirectUrl;
3141
}
32-
33-
}
42+
}

lib/Components/Pagination.php

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,86 @@
44

55
class Pagination
66
{
7-
87
private object $pagination;
98

109
public function __construct(object $pagination)
1110
{
1211
$this->pagination = $pagination;
13-
return $this;
1412
}
1513

16-
public function getTotal(): int
14+
public function getTotal(): ?int
1715
{
16+
if (!isset($this->pagination->total)) {
17+
return null;
18+
}
19+
1820
return $this->pagination->total;
1921
}
2022

21-
public function getCount(): int
23+
public function getCount(): ?int
2224
{
25+
if (!isset($this->pagination->count)) {
26+
return null;
27+
}
28+
2329
return $this->pagination->count;
2430
}
2531

26-
public function getPerPage(): int
32+
public function getPerPage(): ?int
2733
{
34+
if (!isset($this->pagination->per_page)) {
35+
return null;
36+
}
37+
2838
return $this->pagination->per_page;
2939
}
3040

31-
public function getCurrentPage(): int
41+
public function getCurrentPage(): ?int
3242
{
43+
if (!isset($this->pagination->current_page)) {
44+
return null;
45+
}
46+
3347
return $this->pagination->current_page;
3448
}
3549

36-
public function getTotalPages(): int
50+
public function getTotalPages(): ?int
3751
{
52+
if (!isset($this->pagination->total_pages)) {
53+
return null;
54+
}
55+
3856
return $this->pagination->total_pages;
3957
}
4058

41-
public function hasNextPage(): bool
59+
public function hasNextPage(): ?bool
4260
{
43-
return $this->pagination->links->next_page !== null;
61+
if (!isset($this->pagination->links)) {
62+
return null;
63+
}
64+
65+
if (!isset($this->pagination->links->next_page)) {
66+
return null;
67+
}
68+
69+
return null !== $this->pagination->links->next_page;
4470
}
4571

46-
public function hasPrevPage(): bool
72+
public function hasPrevPage(): ?bool
4773
{
48-
return $this->pagination->links->prev_page !== null;
74+
if (!isset($this->pagination->links)) {
75+
return null;
76+
}
77+
78+
if (!isset($this->pagination->links->prev_page)) {
79+
return null;
80+
}
81+
82+
return null !== $this->pagination->links->prev_page;
4983
}
5084

5185
public function getObject(): object
5286
{
5387
return $this->pagination;
5488
}
55-
56-
}
89+
}

0 commit comments

Comments
 (0)