|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Part of the AmazonGiftCode package. |
|
5
|
|
|
* Author: Kashyap Merai <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
namespace kamerk22\AmazonGiftCode\Response; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
use Illuminate\Support\Facades\Log; |
|
14
|
|
|
|
|
15
|
|
|
class CreateBalanceResponse |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Amazon Gift Card Balance Amount |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $_amount; |
|
23
|
|
|
/** |
|
24
|
|
|
* Amazon Gift Card Balance Currency |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $_currency; |
|
29
|
|
|
/** |
|
30
|
|
|
* Amazon Gift Card Balance Status |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $_status; |
|
35
|
|
|
/** |
|
36
|
|
|
* Amazon Gift Card Balance Timestamp |
|
37
|
|
|
* |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $_timestamp; |
|
41
|
|
|
/** |
|
42
|
|
|
* Amazon Gift Card Raw JSON |
|
43
|
|
|
* |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $_raw_json; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Response constructor. |
|
50
|
|
|
* @param $jsonResponse |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct($jsonResponse) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->_raw_json = $jsonResponse; |
|
55
|
|
|
$this->_status = TRUE; |
|
|
|
|
|
|
56
|
|
|
$this->parseJsonResponse($jsonResponse); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getAmount(): string |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->_amount; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getCurrency(): string |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->_currency; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return string |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getStatus(): string |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->_status; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getTimestamp(): string |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->_timestamp; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return string |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getRawJson(): string |
|
95
|
|
|
{ |
|
96
|
|
|
return json_encode($this->_raw_json); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param $jsonResponse |
|
101
|
|
|
* @return CreateBalanceResponse |
|
102
|
|
|
*/ |
|
103
|
|
|
public function parseJsonResponse($jsonResponse): self |
|
104
|
|
|
{ |
|
105
|
|
|
if (!is_array($jsonResponse)) { |
|
106
|
|
|
throw new \RuntimeException('Response must be a scalar value'); |
|
107
|
|
|
} |
|
108
|
|
|
if (array_key_exists('amount', $jsonResponse['availableFunds'])) { |
|
109
|
|
|
$this->_amount = $jsonResponse['availableFunds']['amount']; |
|
110
|
|
|
} |
|
111
|
|
|
if (array_key_exists('currencyCode', $jsonResponse['availableFunds'])) { |
|
112
|
|
|
$this->_currency = $jsonResponse['availableFunds']['currencyCode']; |
|
113
|
|
|
} |
|
114
|
|
|
if (array_key_exists('status', $jsonResponse)) { |
|
115
|
|
|
$this->_status = $jsonResponse['status']; |
|
116
|
|
|
} |
|
117
|
|
|
if (array_key_exists('timestamp', $jsonResponse)) { |
|
118
|
|
|
$this->_timestamp = $jsonResponse['timestamp']; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
return $this; |
|
122
|
|
|
|
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.