|
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
|
|
|
class CancelResponse |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Amazon Gift Card gcId. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $_id; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Amazon Gift Card creationRequestId |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $_creation_request_id; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Amazon Gift Card status |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $_status; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Amazon Gift Card status |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $_card_status; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Amazon Gift Card Raw JSON |
|
46
|
|
|
* |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $_raw_json; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Response constructor. |
|
53
|
|
|
* @param $jsonResponse |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct($jsonResponse) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->_raw_json = $jsonResponse; |
|
58
|
|
|
$this->_status = TRUE; |
|
|
|
|
|
|
59
|
|
|
$this->parseJsonResponse($jsonResponse); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getId(): string |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->_id; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getCreationRequestId(): string |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->_creation_request_id; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getStatus(): string |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->_status; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return string |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getCardStatus(): string |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->_card_status; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return string |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getRawJson(): string |
|
101
|
|
|
{ |
|
102
|
|
|
return json_encode($this->_raw_json); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param $jsonResponse |
|
108
|
|
|
* @return CancelResponse |
|
109
|
|
|
*/ |
|
110
|
|
|
public function parseJsonResponse($jsonResponse): self |
|
111
|
|
|
{ |
|
112
|
|
|
if (!is_array($jsonResponse)) { |
|
113
|
|
|
throw new \RuntimeException('Response must be a scalar value'); |
|
114
|
|
|
} |
|
115
|
|
|
if (array_key_exists('gcId', $jsonResponse)) { |
|
116
|
|
|
$this->_id = $jsonResponse['gcId']; |
|
117
|
|
|
} |
|
118
|
|
|
if (array_key_exists('creationRequestId', $jsonResponse)) { |
|
119
|
|
|
$this->_creation_request_id = $jsonResponse['creationRequestId']; |
|
120
|
|
|
} |
|
121
|
|
|
if (array_key_exists('cardStatus', $jsonResponse['cardInfo'])) { |
|
122
|
|
|
$this->_value = $jsonResponse['cardInfo']['cardStatus']; |
|
|
|
|
|
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
return $this; |
|
126
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
} |
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.