|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace LaravelSixConnex; |
|
5
|
|
|
|
|
6
|
|
|
use Illuminate\Support\Collection; |
|
7
|
|
|
|
|
8
|
|
|
class SixConnexOutput |
|
9
|
|
|
{ |
|
10
|
|
|
public static string $typeParameter = '_apicall'; |
|
11
|
|
|
public static string $codeParameter = '_apicallresultcode'; |
|
12
|
|
|
public static string $messageParameter = '_apicallresultmessage'; |
|
13
|
|
|
|
|
14
|
|
|
protected array $body = []; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* SixConnexOutput constructor. |
|
18
|
|
|
* |
|
19
|
|
|
* @param array $body |
|
20
|
|
|
*/ |
|
21
|
2 |
|
public function __construct(array $body) |
|
22
|
|
|
{ |
|
23
|
2 |
|
$this->body = $body; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Get call type |
|
28
|
|
|
* @return string |
|
29
|
|
|
*/ |
|
30
|
1 |
|
public function getApiCall(): string |
|
31
|
|
|
{ |
|
32
|
1 |
|
return (string) $this->body[ static::$typeParameter ] ?? ''; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Get 6connex response code |
|
37
|
|
|
* @return int |
|
38
|
|
|
*/ |
|
39
|
2 |
|
public function getCode(): int |
|
40
|
|
|
{ |
|
41
|
2 |
|
return (int) ($this->body[ static::$codeParameter ] ?? 0); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get result message |
|
46
|
|
|
* @return string |
|
47
|
|
|
*/ |
|
48
|
1 |
|
public function getResultMessage(): string |
|
49
|
|
|
{ |
|
50
|
1 |
|
return (string) ($this->body[ static::$messageParameter ] ?? ''); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get the JSON decoded body of the response as an array or scalar value. |
|
55
|
|
|
* |
|
56
|
|
|
* @param string|null $key |
|
57
|
|
|
* @param mixed $default |
|
58
|
|
|
* |
|
59
|
|
|
* @return mixed |
|
60
|
|
|
*/ |
|
61
|
2 |
|
public function json($key = null, $default = null) |
|
62
|
|
|
{ |
|
63
|
2 |
|
if (is_null($key)) { |
|
64
|
1 |
|
return $this->body; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
2 |
|
return data_get($this->body, $key, $default); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get the JSON decoded body of the response as a collection. |
|
72
|
|
|
* |
|
73
|
|
|
* @param string|null $key |
|
74
|
|
|
* @return \Illuminate\Support\Collection |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function collect($key = null) |
|
77
|
|
|
{ |
|
78
|
1 |
|
return Collection::make($this->json($key)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
2 |
|
public function successful(): bool |
|
82
|
|
|
{ |
|
83
|
2 |
|
return $this->getCode() == 1; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
public function failed(): bool |
|
87
|
|
|
{ |
|
88
|
1 |
|
return !$this->successful(); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|